Debian Codegraph @

hmmer/test-speed/x-ncbiblast+

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-ncbiblast+ /usr/local/ncbi-blast-2.2.24+ . 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 $blastp = "$top_builddir/bin/blastp";
23 $blastopts = "-num_threads $nthreads -num_descriptions 9999 -num_alignments 0";
24
25 if (! -d $top_builddir) { die "didn't find BLAST directory $top_builddir"; }
26 if (! -x $blastp) { die "didn't find blastp executable $blastp"; }
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 (.sto file)
43 $output = `esl-afetch -o $resultdir/$msaname.sto $querydb $msaname`;
44 if ($? != 0) { print "FAILED: esl-afetch on $msaname\n"; next MSA; }
45
46 # Select median length single sequence as the query (.query.fa file)
47 $output = `esl-seqstat -a $resultdir/$msaname.sto | grep "^=" | sort -n -k2 | awk '{print \$2}'`;
48 if ($?) { print "FAILED: esl-seqstat on $msaname\n"; next MSA; }
49 @qnames = split(/^/,$output);
50 chop (@qnames);
51 $qname = $qnames[ int(($#qnames+1) / 2)];
52 $output = `esl-sfetch -o $resultdir/$msaname.query.fa $resultdir/$msaname.sto $qname`;
53 if ($?) { print "FAILED: esl-sfetch on $msaname\n"; next MSA; }
54
55 # Warmup. (An untimed run, to encourage filesystem to cache the target database.)
56 if ($n==1) { `$blastp $blastopts -db $targetdb -query $resultdir/$msaname.query.fa 2>&1`; }
57
58 # BLAST it and capture timing
59 $t0 = Benchmark->new;
60 $output = `$blastp $blastopts -db $targetdb -query $resultdir/$msaname.query.fa 2>&1`;
61 if ($? != 0) { print "FAILED: ncbi blastp+ on $msaname\n"; next MSA; }
62 $t1 = Benchmark->new;
63
64 if ($output =~ /\nLength=(\S+)/) { $M = $1; $M =~ s/,//g; }
65 if ($output =~ /\n\s*Number of letters in database:\s*(\S+)/) { $L = $1; $L =~ s/,//g; }
66
67 # Get the wall clock time.
68 $td = timediff($t1, $t0);
69 $walltime = $td->real;
70
71 $mcs = $L / 1000000 / $walltime * $M;
72 printf OUTFILE "%-15s %5d %10.1f %12.2f\n", $msaname, $M, $mcs, $walltime;
73
74 unlink "$resultdir/$msaname.sto";
75 unlink "$resultdir/$msaname.query.fa";
76 }
77 }
78 close TABLE;
79 close OUTFILE;