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/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 $blastall = "$top_builddir/bin/blastall";
23 $blastopts = "-p blastp -a $nthreads -v 9999 -b0 -F F";
24
25 if (! -d $top_builddir) { die "didn't find BLAST directory $top_builddir"; }
26 if (! -x $blastall) { die "didn't find blastall executable $blastall"; }
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) { `$blastall $blastopts -d $targetdb -i $resultdir/$msaname.query.fa 2>&1`; }
57
58 # BLAST it and capture timing
59 $t0 = Benchmark->new;
60 $output = `$blastall $blastopts -d $targetdb -i $resultdir/$msaname.query.fa 2>&1`;
61 if ($? != 0) { print "FAILED: ncbi blast on $msaname\n"; next MSA; }
62 $t1 = Benchmark->new;
63
64 if ($output =~ /\nLength of query:\s*(\S+)/) {$M = $1; $M =~ s/,//g; }
65 elsif ($output =~ /\nQuery=.+\n\s*\((\d+) letters\)/) {$M = $1; $M =~ s/,//g; }
66 if ($output =~ /\nLength of database:\s*(\S+)/) {$L = $1; $L =~ s/,//g; }
67 elsif ($output =~ /\n\s*Number of letters in database:\s*(\S+)/) {$L = $1; $L =~ s/,//g; }
68
69 # Get the wall clock time.
70 $td = timediff($t1, $t0);
71 $walltime = $td->real;
72
73 $mcs = $L / 1000000 / $walltime * $M;
74 printf OUTFILE "%-15s %5d %10.1f %12.2f\n", $msaname, $M, $mcs, $walltime;
75
76 unlink "$resultdir/$msaname.sto";
77 # unlink "$resultdir/$msaname.query.fa";
78 }
79 }
80 close TABLE;
81 close OUTFILE;