25 |
use Carp; |
use Carp; |
26 |
use gjoseqlib; |
use gjoseqlib; |
27 |
|
|
28 |
my $blat_cmd = "blat"; |
use SeedAware; |
29 |
my $blastall_cmd = "blastall"; |
|
30 |
my $formatdb_cmd = "formatdb"; |
my $blat_cmd = SeedAware::executable_for("blat"); |
31 |
|
my $blastall_cmd = SeedAware::executable_for("blastall"); |
32 |
BEGIN { |
my $formatdb_cmd = SeedAware::executable_for("formatdb"); |
|
eval { |
|
|
require FIG_Config; |
|
|
if (defined $FIG_Config::ext_bin) { |
|
|
$blat_cmd = "$FIG_Config::ext_bin/blat"; |
|
|
$blastall_cmd = "$FIG_Config::ext_bin/blastall"; |
|
|
$formatdb_cmd = "$FIG_Config::ext_bin/formatdb"; |
|
|
} |
|
|
}; |
|
|
} |
|
33 |
|
|
34 |
sub blastP { |
sub blastP { |
35 |
my($q,$db,$min_hits,$use_blast) = @_; |
my($q,$db,$min_hits,$use_blast) = @_; |
36 |
|
|
37 |
my(@q,@db); |
my(@q,@db); |
38 |
|
|
39 |
|
my $tmp_dir = SeedAware::location_of_tmp(); |
40 |
|
|
41 |
my $qF; |
my $qF; |
42 |
if (ref $q) |
if (ref $q) |
43 |
{ |
{ |
44 |
$qF = "/tmp/query.$$"; |
$qF = "$tmp_dir/query.$$"; |
45 |
&gjoseqlib::print_alignment_as_fasta($qF,$q); |
&gjoseqlib::print_alignment_as_fasta($qF,$q); |
46 |
} |
} |
47 |
else |
else |
61 |
my $dbF; |
my $dbF; |
62 |
if (ref $db) |
if (ref $db) |
63 |
{ |
{ |
64 |
$dbF = "/tmp/db.$$"; |
$dbF = "$tmp_dir/db.$$"; |
65 |
&gjoseqlib::print_alignment_as_fasta($dbF,$db); |
&gjoseqlib::print_alignment_as_fasta($dbF,$db); |
66 |
system "$formatdb_cmd -i $dbF"; |
system($formatdb_cmd, '-i', $dbF); |
67 |
} |
} |
68 |
else |
else |
69 |
{ |
{ |
72 |
{ |
{ |
73 |
if (! ((-e "$dbF.psq") && ((-M "$dbF.psq") < (-M $dbF)))) |
if (! ((-e "$dbF.psq") && ((-M "$dbF.psq") < (-M $dbF)))) |
74 |
{ |
{ |
75 |
system "formatdb_cmd -i $dbF"; |
system($formatdb_cmd, '-i', $dbF);; |
76 |
} |
} |
77 |
@db = &gjoseqlib::read_fasta($dbF); |
@db = &gjoseqlib::read_fasta($dbF); |
78 |
$db = \@db; |
$db = \@db; |
83 |
} |
} |
84 |
} |
} |
85 |
|
|
86 |
my $tmpF = "/tmp/sim.out.$$"; |
my $tmpF = "$tmp_dir/sim.out.$$"; |
87 |
my $cmd = $use_blast ? "touch $tmpF" : "$blat_cmd $dbF $qF -prot -out=blast8 $tmpF > /dev/null"; |
|
88 |
#print STDERR "$cmd\n"; |
if ($use_blast) |
89 |
my $rc = system $cmd; |
{ |
90 |
|
open(my $fh, ">", $tmpF); |
91 |
|
close($fh); |
92 |
|
} |
93 |
|
else |
94 |
|
{ |
95 |
|
my @cmd = ($blat_cmd, $dbF, $qF, "-prot", "-out=blast8", $tmpF); |
96 |
|
|
97 |
|
my $rc = system_with_redirect(\@cmd, { stdout => '/dev/null' } ); |
98 |
|
print STDERR "Blat returns $rc: @cmd\n"; |
99 |
if ($rc != 0) |
if ($rc != 0) |
100 |
{ |
{ |
101 |
die "ProtSims::blastP: blat run failed with rc=$rc: $cmd\n"; |
warn "Blat run failed with rc=$rc\n"; |
102 |
|
open(my $fh, ">", $tmpF); |
103 |
|
close($fh); |
104 |
|
} |
105 |
} |
} |
106 |
|
|
107 |
|
# my $cmd = $use_blast ? "touch $tmpF" : "$blat_cmd $dbF $qF -prot -out=blast8 $tmpF > /dev/null"; |
108 |
|
# #print STDERR "$cmd\n"; |
109 |
|
# my $rc = system $cmd; |
110 |
|
# if ($rc != 0) |
111 |
|
# { |
112 |
|
# die "ProtSims::blastP: blat run failed with rc=$rc: $cmd\n"; |
113 |
|
# } |
114 |
|
|
115 |
my @sims1 = (); |
my @sims1 = (); |
116 |
open(BLAT,"<$tmpF") || die "could not open $tmpF"; |
open(BLAT,"<$tmpF") || die "could not open $tmpF"; |
117 |
my $sim = <BLAT>; |
my $sim = <BLAT>; |
164 |
|
|
165 |
if (@rerun > 0) |
if (@rerun > 0) |
166 |
{ |
{ |
167 |
my $tmpQ = "/tmp/tmpQ.$$"; |
my $tmpQ = "$tmp_dir/tmpQ.$$"; |
168 |
&gjoseqlib::print_alignment_as_fasta($tmpQ,\@rerun); |
&gjoseqlib::print_alignment_as_fasta($tmpQ,\@rerun); |
169 |
my $cmd = "$blastall_cmd -m 8 -i $tmpQ -d $dbF -FF -p blastp -e 1e-5"; |
# my $cmd = "$blastall_cmd -m 8 -i $tmpQ -d $dbF -FF -p blastp -e 1e-5"; |
170 |
|
my @cmd = ($blastall_cmd, '-m', 8, '-i', $tmpQ, '-d', $dbF, '-FF', '-p', 'blastp', '-e', '1e-5'); |
171 |
|
print STDERR "@cmd\n"; |
172 |
#print STDERR "$cmd\n"; |
#print STDERR "$cmd\n"; |
173 |
open(BL, "$cmd|") or die "ProtSims::blastP: pipe to blast failed with $!: $cmd\n"; |
#open(BL, "$cmd|") or die "ProtSims::blastP: pipe to blast failed with $!: $cmd\n"; |
174 |
|
|
175 |
|
open(BL, "-|", @cmd) or die "ProtSims::blastP: pipe to blast failed with $!: @cmd\n"; |
176 |
|
|
177 |
my @blastout = map { chomp; [split(/\s+/,$_)] } <BL>; |
my @blastout = map { chomp; [split(/\s+/,$_)] } <BL>; |
178 |
close(BL); |
close(BL); |
179 |
push(@sims,@blastout); |
push(@sims,@blastout); |
184 |
my %lnDB = map { $_->[0] => length($_->[2]) } @$db; |
my %lnDB = map { $_->[0] => length($_->[2]) } @$db; |
185 |
@sims = map { push(@$_,$lnQ{$_->[0]},$lnDB{$_->[1]}); bless($_,'Sim') } @sims; |
@sims = map { push(@$_,$lnQ{$_->[0]},$lnDB{$_->[1]}); bless($_,'Sim') } @sims; |
186 |
|
|
187 |
if ($qF eq "/tmp/query.$$") { unlink $qF } |
if ($qF eq "$tmp_dir/query.$$") { unlink $qF } |
188 |
if ($dbF eq "/tmp/db.$$") { unlink($dbF,"$dbF.psq","$dbF.pin","$dbF.phr") } |
if ($dbF eq "$tmp_dir/db.$$") { unlink($dbF,"$dbF.psq","$dbF.pin","$dbF.phr") } |
189 |
return sort { ($a->id1 cmp $b->id1) or ($a->psc <=> $b->psc) or ($a->id2 cmp $b->id2) } @sims; |
return sort { ($a->id1 cmp $b->id1) or ($a->psc <=> $b->psc) or ($a->id2 cmp $b->id2) } @sims; |
190 |
} |
} |
191 |
|
|