Debian Codegraph @

hmmer/test-speed/x-sam

raw
1 #! /usr/bin/perl
2
3 # We assume that a SAM binary install is in $top_builddir
4 # $top_srcdir is unused: pass "." or $top_builddir
5 # $nthreads must be 1.
6 #
7 # Example:
8 # ./x-sam ~/alien-src/sam-3.5/sam3.5.x86_64-linux . foo-test test.list 1 Pfam-A.seed uniprot/trembl-shuf-10k test.out
9
10 use Benchmark qw(:hireswallclock) ;
11
12 $top_builddir = shift;
13 $top_srcdir = shift;
14 $resultdir = shift;
15 $tblfile = shift;
16 $nthreads = shift;
17 $querydb = shift;
18 $targetdb = shift;
19 $outfile = shift;
20
21 $w05 = "$top_builddir/bin/w0.5";
22 $hmmscore = "$top_builddir/bin/hmmscore";
23
24 if (! -d $top_builddir) { die "didn't find SAM directory $top_builddir"; }
25 if (! -x $w05) { die "didn't find w0.5 executable $w05"; }
26 if (! -x $hmmscore) { die "didn't find hmmscore executable $hmmscore"; }
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 if ($nthreads ne "1") { die "SAM isn't multithreaded; nthreads must be 1"; }
30
31 open(OUTFILE,">$outfile") || die "failed to open output $outfile";
32 open(TABLE, "$tblfile") || die "failed to open work unit list $tblfile";
33
34 $n = 0;
35 MSA:
36 while (<TABLE>)
37 {
38 if (/(\S+)/)
39 {
40 $n++;
41 $msaname = $1;
42
43 # Fetch the query MSA from the benchmark (.sto file)
44 $output = `esl-afetch -o $resultdir/$msaname.sto $querydb $msaname`;
45 if ($?) { print "FAILED: esl-afetch on $msaname\n"; next MSA; }
46
47 # Reformat to A2M format (.a2m file)
48 $output = `esl-reformat -o $resultdir/$msaname.a2m a2m $resultdir/$msaname.sto`;
49 if ($?) { print "FAILED: esl-reformat on $msaname\n"; next MSA; }
50
51 # Build a model using UCSC's w0.5 script (.mod file)
52 `(cd $resultdir; $w05 $msaname.a2m $msaname.mod &> /dev/null)`;
53 if ($? != 0) { print "FAILED: w0.5 on $msaname\n"; next MSA; }
54
55 # Warmup. (An untimed run, to encourage filesystem to cache the target database.)
56 if ($n == 1) {
57 $output = `(cd $resultdir; $hmmscore $msaname -i $msaname.mod -db ../$targetdb -sw 2 2>&1)`;
58 }
59
60 # Run hmmscore. The result (a .dist file) drops into the wd.
61 $t0 = Benchmark->new;
62 $output = `(cd $resultdir; $hmmscore $msaname -i $msaname.mod -db ../$targetdb -sw 2 2>&1)`;
63 if ($? != 0) { print "FAILED: hmmscore on $msaname\n"; next MSA; }
64 $t1 = Benchmark->new;
65
66 # Get the wall clock time.
67 $td = timediff($t1, $t0);
68 $walltime = $td->real;
69
70 # The dist file contains a useful line
71 open (SAMOUTPUT,"$resultdir/$msaname.dist") || die "FAILED: opening sam output on $msaname\n";
72 while ($line = <SAMOUTPUT>)
73 {
74 if ($line =~ /^%\s+(\d+)\s+sequences,\s+(\d+)\s+residues,\s+(\d+)\s+nodes/)
75 {
76 $N = $1;
77 $L = $2;
78 $M = $3;
79 last;
80 }
81 }
82 close SAMOUTPUT;
83
84 $mcs = $L / 1000000 / $walltime * $M;
85
86 printf OUTFILE "%-15s %5d %10.1f %12.2f\n", $msaname, $M, $mcs, $walltime;
87
88 unlink "$resultdir/$msaname.sto";
89 unlink "$resultdir/$msaname.a2m";
90 unlink "$resultdir/$msaname.mod";
91 unlink "$resultdir/$msaname.dist";
92 }
93 }
94 close TABLE;
95 close OUTFILE;