forked from sanahmed/PhaME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallel_run.pl
88 lines (79 loc) · 2.78 KB
/
parallel_run.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl -w
use strict;
use FindBin;
use Getopt::Long;
use File::Basename;
use Parallel::ForkManager;
my $dir;
my $program="mafft";
my $muscle_options= "-diags";
my $mafft_options= "";
my @files;
my $thread;
GetOptions(
'd=s' => \$dir,
't=i' => \$thread,
'm=s' => \$program,
'h|help' => sub {usage()},
);
if (!$dir) {die &usage;}
if ($dir=~ /.+\/$/){my $tmp= chop($dir);}
sub usage
{
print STDERR"
Usage: $0 -d (directory) -m (script)
required options
-d File directory
-m program to run
default: mafft
-t Number of threads
additional options
-muscle <string> muscle options
default: \"-diags\"
type \"muscle\" to see additional muscle options
-mafft <string> mafft options
type \"mafft\" to see additional mafft options
list of progams
-mafft: Multiple alignment program
-muscle: Multiple alignment program
-translate: Translate DNA to amino acid
-oneline: Write multi-line fasta sequences to one line
-pal2nal: Convert amino acid alignment to codon alignment, needs DNA fasta file
";
exit;
}
my $bindir=getBinDirectory();
my $pm= new Parallel::ForkManager($thread);
$pm->run_on_finish(sub{my ($pid,$ident)=@_;});
sub getBinDirectory
{
my @t = split '/', "$FindBin::RealBin";
my $path = join '/', @t;
return ($path);
}
opendir(DIR, $dir);
while (my $file= readdir(DIR)){
next if ($file=~ /^..?$/);
$file= $dir.'/'.$file;
if ($program=~ /pal2nal/ ||$program=~ /oneline/){
if ($file=~ /msa$/){push (@files,$file);}
}
if ($program=~ /translate/){
if ($file=~ /fna$/){push (@files,$file);}
}
if ($program=~ /mafft/ ||$program=~ /muscle/){
if ($file=~ /faa$/){push (@files,$file);}
}
}
for (my $i=0; $i<=$#files; $i++){
$pm->start and next;
my ($ref_file_name,$ref_file_path,$ref_file_suffix)=fileparse("$files[$i]", qr/\.[^.]*/);
if ($program=~/oneline/){`$bindir/fasta_oneline.pl $files[$i] > $ref_file_path/$ref_file_name.faa`}
if ($program=~ /mafft/i){`$bindir/mafft $mafft_options $files[$i] > $ref_file_path/$ref_file_name.msa`;}
if ($program=~/pal2nal/){`$bindir/pal2nal.pl $files[$i] $ref_file_path/$ref_file_name.fna -output fasta > $ref_file_path/$ref_file_name.cdn`;}
# if ($program=~/pal2nal/){`$bindir/pal2nal.pl $files[$i] $ref_file_path/$ref_file_name.fna -output fasta > $ref_file_path/$ref_file_name.cdn`;}
if ($program=~ /translate/){`$bindir/translate.pl $files[$i] > $ref_file_path/$ref_file_name.faa`;}
elsif ($program=~ /muscle/i){`$bindir/muscle3.8.31_i86linux64 $muscle_options -in $files[$i] -out $ref_file_path$ref_file_name.msa`;}
$pm->finish;
}
$pm->wait_all_children;