[Bio] / FigKernelPackages / ProtSims.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/ProtSims.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15, Tue Sep 14 19:09:17 2010 UTC revision 1.18, Mon Oct 4 21:31:34 2010 UTC
# Line 32  Line 32 
32  my $blastall_cmd = SeedAware::executable_for("blastall");  my $blastall_cmd = SeedAware::executable_for("blastall");
33  my $formatdb_cmd = SeedAware::executable_for("formatdb");  my $formatdb_cmd = SeedAware::executable_for("formatdb");
34    
35    #
36    # Need to call temps different names on each invocation -
37    # if a subprocess hung on windows, we get problems with
38    # "file in use" errors.
39    #
40    my $tmp_serial = 0;
41    
42  sub blastP {  sub blastP {
43      my($q,$db,$min_hits,$use_blast) = @_;      my($q,$db,$min_hits,$use_blast) = @_;
44    
# Line 39  Line 46 
46    
47      my $tmp_dir = SeedAware::location_of_tmp();      my $tmp_dir = SeedAware::location_of_tmp();
48    
49        my $tmp_suffix = $$ . "." . $tmp_serial++ . "." . time;
50    
51      my $qF;      my $qF;
52      if (ref $q)      if (ref $q)
53      {      {
54          $qF = "$tmp_dir/query.$$";          $qF = "$tmp_dir/query.$tmp_suffix";
55          &gjoseqlib::print_alignment_as_fasta($qF,$q);          &gjoseqlib::print_alignment_as_fasta($qF,$q);
56      }      }
57      else      else
# Line 64  Line 73 
73      my $dbF;      my $dbF;
74      if (ref $db)      if (ref $db)
75      {      {
76          $dbF = "$tmp_dir/db.$$";          $dbF = "$tmp_dir/db.$tmp_suffix";
77          &gjoseqlib::print_alignment_as_fasta($dbF,$db);          &gjoseqlib::print_alignment_as_fasta($dbF,$db);
78          system($formatdb_cmd, '-i', $dbF);          system($formatdb_cmd, '-i', $dbF);
79          $db_lengths->{$_->[0]} = length($_->[2]) for @$db;          $db_lengths->{$_->[0]} = length($_->[2]) for @$db;
# Line 107  Line 116 
116          }          }
117      }      }
118    
119      my $tmpF = "$tmp_dir/sim.out.$$";      my $tmpF = "$tmp_dir/sim.out.$tmp_suffix";
120    
121      if ($use_blast)      if ($use_blast)
122      {      {
# Line 118  Line 127 
127      {      {
128          my @cmd = ($blat_cmd, $dbF, $qF, "-prot", "-out=blast8", $tmpF);          my @cmd = ($blat_cmd, $dbF, $qF, "-prot", "-out=blast8", $tmpF);
129    
130          my $rc = system_with_redirect(\@cmd, { stdout => '/dev/null' } );          #
131            # When running under FCGI, the system_with_redirect fails due to
132            # the FCGI library redefining open.
133            #
134    
135            my $rc;
136            if (defined($ENV{FCGI_ROLE}))
137            {
138                $rc = system(@cmd);
139            }
140            else
141            {
142                $rc = system_with_redirect(\@cmd, { stdout => '/dev/null' } );
143            }
144    
145          print STDERR "Blat returns $rc: @cmd\n";          print STDERR "Blat returns $rc: @cmd\n";
146          if ($rc != 0)          if ($rc != 0)
147          {          {
# Line 188  Line 211 
211    
212      if (@rerun > 0)      if (@rerun > 0)
213      {      {
214          my $tmpQ = "$tmp_dir/tmpQ.$$";          my $tmpQ = "$tmp_dir/tmpQ.$tmp_suffix";
215          &gjoseqlib::print_alignment_as_fasta($tmpQ,\@rerun);          &gjoseqlib::print_alignment_as_fasta($tmpQ,\@rerun);
216    
217    
218            #
219            # If we're under FCGI (and thus under the servers), and the loadavg is low, do a small parallel run.
220            #
221    
222            my @par = ();
223            if (defined($ENV{FCGI_ROLE}) && open(my $la, "/proc/loadavg"))
224            {
225                my $l = <$la>;
226                chomp $l;
227                my @vals = split(/\s+/, $l);
228                my @procs = split(/\//, $vals[3]);
229                if ($vals[0] < 4 && $procs[0] < 8)
230                {
231                    @par = ("-a", 4);
232                }
233            }
234    
235    
236          # 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";
237          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', @par);
238          #print STDERR "$cmd\n";          #print STDERR "$cmd\n";
239          #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";
240    
# Line 199  Line 242 
242          # It'd be nice to do this but windows doesn't support it.          # It'd be nice to do this but windows doesn't support it.
243          #          #
244          #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";
245          my $out_tmp = "$tmp_dir/blast_out.$$";          my $out_tmp = "$tmp_dir/blast_out.$tmp_suffix";
246          push(@cmd, "-o", $out_tmp);          push(@cmd, "-o", $out_tmp);
247          print STDERR "@cmd\n";          print STDERR "@cmd\n";
248          my $rc = system(@cmd);          my $rc = system(@cmd);
# Line 229  Line 272 
272    
273      @sims = map { push(@$_, $lnQ{$_->[0]}, $db_lengths->{$_->[1]}); bless($_,'Sim') } @sims;      @sims = map { push(@$_, $lnQ{$_->[0]}, $db_lengths->{$_->[1]}); bless($_,'Sim') } @sims;
274    
275      if ($qF      eq "$tmp_dir/query.$$")   { unlink $qF  }      if ($qF      eq "$tmp_dir/query.$tmp_suffix")   { unlink $qF  }
276      if ($dbF     eq "$tmp_dir/db.$$")      { unlink($dbF,"$dbF.psq","$dbF.pin","$dbF.phr") }      if ($dbF     eq "$tmp_dir/db.$tmp_suffix")      { unlink($dbF,"$dbF.psq","$dbF.pin","$dbF.phr") }
277      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;
278  }  }
279    

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.18

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3