Debian Codegraph @

hmmer/test-speed/x-psiblast

raw
1 #! /usr/bin/perl
2
3 # We assume that an NCBI BLAST install tree is in $top_builddir
4 # $top_srcdir is unused: pass "." or $top_builddir
5 #
6 # Example:
7 # mkdir foo-test
8 # ./x-psiblast /usr/local/blast-2.2.22 . foo-test test.list 1 Pfam-A.seed uniprot/trembl-shuf-1M test.out
9 #
10
11 use Benchmark qw(:hireswallclock) ;
12
13 $top_builddir = shift;
14 $top_srcdir = shift;
15 $resultdir = shift;
16 $tblfile = shift;
17 $nthreads = shift;
18 $querydb = shift;
19 $targetdb = shift;
20 $outfile = shift;
21
22 $blastpgp = "$top_builddir/bin/blastpgp";
23 $blastopts = "-a $nthreads -v 9999 -b0";
24
25 if (! -d $top_builddir) { die "didn't find BLAST directory $top_builddir"; }
26 if (! -x $blastpgp) { die "didn't find blastpgp executable $blastpgp"; }
27 if ($top_srcdir ne "." && $top_srcdir ne $top_builddir) { die "$top_srcdir is unused. pass ."; }
28 if (! -e $resultdir) { die "$resultdir doesn't exist"; }
29
30 open(OUTFILE,">$outfile") || die "failed to open output $outfile";
31 open(TABLE, "$tblfile") || die "failed to open work unit list $tblfile";
32
33 $n = 0;
34 MSA:
35 while (<TABLE>)
36 {
37 if (/(\S+)/)
38 {
39 $n++;
40 $msaname = $1;
41
42 # Fetch the query MSA from the benchmark (.sto file)
43 $output = `esl-afetch -o $resultdir/$msaname.sto $querydb $msaname`;
44 if ($?) { print "FAILED: esl-afetch on $msaname\n"; next MSA; }
45
46 # Reformat to psiblast format (.pbl file)
47 $output = `esl-reformat -o $resultdir/$msaname.pbl psiblast $resultdir/$msaname.sto`;
48 if ($?) { print "FAILED: esl-reformat on $msaname\n"; next MSA; }
49
50 # Select median length single sequence as the "query" (.query.fa file)
51 $output = `esl-seqstat -a $resultdir/$msaname.sto | grep "^=" | sort -n -k2 | awk '{print \$2}'`;
52 if ($?) { print "FAILED: esl-seqstat on $msaname\n"; next MSA; }
53 @qnames = split(/^/,$output);
54 chop (@qnames);
55 $qname = $qnames[ int(($#qnames+1) / 2)];
56 $output = `esl-sfetch -o $resultdir/$msaname.query.fa $resultdir/$msaname.sto $qname`;
57 if ($?) { print "FAILED: esl-sfetch on $msaname\n"; next MSA; }
58
59 # Warmup. (An untimed run, to encourage filesystem to cache the target database.)
60 if ($n == 1) {
61 $output = `$blastpgp $blastopts -d $targetdb -i $resultdir/$msaname.query.fa -B $resultdir/$msaname.pbl 2>&1`;
62 }
63
64 # Run psi-blast against the benchmark
65 $t0 = Benchmark->new;
66 $output = `$blastpgp $blastopts -d $targetdb -i $resultdir/$msaname.query.fa -B $resultdir/$msaname.pbl 2>&1`;
67 if ($?) { print "FAILED: $blastpgp on $msaname\n"; next MSA; }
68 $t1 = Benchmark->new;
69
70 if ($output =~ /\nLength of query:\s*(\S+)/) {$M = $1; $M =~ s/,//g; }
71 elsif ($output =~ /\nQuery=.+\n\s*\((\d+) letters\)/) {$M = $1; $M =~ s/,//g; }
72 if ($output =~ /\nLength of database:\s*(\S+)/) {$L = $1; $L =~ s/,//g; }
73 elsif ($output =~ /\n\s*Number of letters in database:\s*(\S+)/) {$L = $1; $L =~ s/,//g; }
74
75 # Get the wall clock time.
76 $td = timediff($t1, $t0);
77 $walltime = $td->real;
78
79 $mcs = $L / 1000000 / $walltime * $M;
80 printf OUTFILE "%-15s %5d %10.1f %12.2f\n", $msaname, $M, $mcs, $walltime;
81
82 # unlink "$resultdir/$msaname.sto";
83 # unlink "$resultdir/$msaname.pbl";
84 # unlink "$resultdir/$msaname.query.fa";
85 }
86 }
87 close TABLE;
88 close OUTFILE;