-
Notifications
You must be signed in to change notification settings - Fork 4
/
make_blasts.pl
73 lines (58 loc) · 1.17 KB
/
make_blasts.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
#!/usr/bin/perl -w
use strict;
use Cwd;
my $dir = getcwd;
my $n = shift || 8;
my $rname = "results";
my @files = ();
opendir(DIR, $dir);
while (my $f = readdir(DIR)){
if ($f =~ /\.fa$/){
push @files, $f;
}
}
closedir DIR;
my $rfold = compose_path($dir, $rname);
if (!-d $rfold){
mkdir($rfold);
}
my $i = iterator((1 .. $n));
my $commands = [];
foreach my $f (@files){
foreach my $g (@files){
next if ($f eq $g);
my $command = "blastall -p blastp -e 1e-10 -m 8 -d $g -i $f | gzip >$rname\/$f\__$g\.blast.gz";
$command .= "\n(>&2 echo \"Finished comparing $f with $g\")";
my $n = $i->();
push @{$commands->[$n]}, $command;
}
}
for (my $c = 1; $c < scalar(@$commands); $c++){
my $fname = "blastme$c.sh";
my $cs = $commands->[$c];
open (OUT, ">$fname");
print OUT join("\n", @$cs);
close OUT;
`chmod 755 $fname`;
}
sub compose_path{
my $p = shift;
my $f = shift;
$p =~ s/[\/\s]*$//;
my $result = "$p\/$f";
return $result;
}
sub iterator{
my $elements = \@_;
my $i = 0;
return sub{
my $result = $elements->[$i];
if ($i >= scalar(@$elements) - 1){
$i = 0;
}
else{
$i++;
}
return $result;
};
}