| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
# Test that the search tools (hmmsearch, phmmer, nhmmer) |
| 4 |
# produce the correct set of hits when the target sequence |
| 5 |
# database is rewound. This aims to avoid a bug found by |
| 6 |
# TW in 2016, in which a second pass through an NCBI |
| 7 |
# database would miss hits to the first sequence of that |
| 8 |
# database. |
| 9 |
# |
| 10 |
# Usage: ./i21-rewind.pl <builddir> <srcdir> <tmpfile prefix> |
| 11 |
# Example: ./i21-rewind.pl .. .. tmpfoo |
| 12 |
# |
| 13 |
|
| 14 |
BEGIN { |
| 15 |
$builddir = shift; |
| 16 |
$srcdir = shift; |
| 17 |
$tmppfx = shift; |
| 18 |
$verbose = shift; # if arg not given, defaults to false (zero) |
| 19 |
} |
| 20 |
|
| 21 |
# The test creates the following files: |
| 22 |
# $tmppfx.hmm a profile HMM file containing two copies of a single query hmm |
| 23 |
# |
| 24 |
# If a previous Easel test has generated a $tmppfx.hmm file and |
| 25 |
# pressed it to binary, you could get a very confusing failure; when |
| 26 |
# we create our $tmppfx.hmm here, the previous binary database will be |
| 27 |
# silently read instead. To avoid this, quietly remove any previous |
| 28 |
# pressed indices. |
| 29 |
if (-e "$tmppfx.hmm.h3f") { unlink "$tmppfx.hmm.h3f"; } |
| 30 |
if (-e "$tmppfx.hmm.h3i") { unlink "$tmppfx.hmm.h3i"; } |
| 31 |
if (-e "$tmppfx.hmm.h3m") { unlink "$tmppfx.hmm.h3m"; } |
| 32 |
if (-e "$tmppfx.hmm.h3p") { unlink "$tmppfx.hmm.h3p"; } |
| 33 |
|
| 34 |
# Verify that we have all the executables we need for the test. |
| 35 |
@h3progs = ( "hmmsearch", "phmmer", "nhmmer"); |
| 36 |
foreach $h3prog (@h3progs) { if (! -x "$builddir/src/$h3prog") { die "FAIL: didn't find $h3prog executable in $builddir/src\n"; } } |
| 37 |
|
| 38 |
@easel_progs = ( "esl-reformat"); |
| 39 |
foreach $easel_prog (@easel_progs) { if (! -x "$builddir/easel/miniapps/$easel_progs") { die "FAIL: didn't find $easel_prog executable in $builddir/easel/miniapps\n"; } } |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
@formats = ("ncbi" , "fasta", "afa", "stockholm"); |
| 44 |
@exts = ( "", ".fa", ".afa", ".sto"); |
| 45 |
|
| 46 |
# Test hmmsearch. Make a query with two copies of the hmm. |
| 47 |
# Should get the same number of hits with both searches |
| 48 |
$cmd = "cat $srcdir/testsuite/20aa.hmm $srcdir/testsuite/20aa.hmm > $tmppfx.hmm"; |
| 49 |
do_cmd($cmd); |
| 50 |
|
| 51 |
for $i (0..$#formats) { |
| 52 |
$fmt = $formats[$i]; |
| 53 |
$ext = $exts[$i]; |
| 54 |
|
| 55 |
$cmd = "$builddir/src/hmmsearch --tformat $fmt $tmppfx.hmm $srcdir/testsuite/20aa-alitest$ext 2>&1"; |
| 56 |
$output = do_cmd($cmd); |
| 57 |
|
| 58 |
my ($first) = ( $output =~ /Domain search space \(domZ\):\s+(\d+)/g); |
| 59 |
my ($second) = ( $output =~ /Domain search space \(domZ\):\s+(\d+)/g); |
| 60 |
|
| 61 |
if ($first != 4 || $second != 4) { |
| 62 |
die "FAIL: rewound second search gave different results for hmmsearch, $fmt format"; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
# Test phmmer. Make a query with two copies of a sequence. |
| 68 |
# Should get the same number of hits with both searches |
| 69 |
unlink ("$tmppfx.fa"); |
| 70 |
$cmd = "$builddir/src/hmmemit --seed 10 $srcdir/testsuite/20aa.hmm >> $tmppfx.fa"; |
| 71 |
do_cmd($cmd); |
| 72 |
do_cmd($cmd); # yes, twice |
| 73 |
|
| 74 |
for $i (0..$#formats) { |
| 75 |
$fmt = $formats[$i]; |
| 76 |
$ext = $exts[$i]; |
| 77 |
|
| 78 |
$cmd = "$builddir/src/phmmer --tformat $fmt $tmppfx.fa $srcdir/testsuite/20aa-alitest$ext 2>&1"; |
| 79 |
$output = do_cmd($cmd); |
| 80 |
|
| 81 |
my ($first) = ( $output =~ /Domain search space \(domZ\):\s+(\d+)/g); |
| 82 |
my ($second) = ( $output =~ /Domain search space \(domZ\):\s+(\d+)/g); |
| 83 |
|
| 84 |
if ($first != 4 || $second != 4) { |
| 85 |
die "FAIL: rewound second search gave different results for phmmer, $fmt format"; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
# Test nhmmer. Make a query with two copies of an hmm. |
| 91 |
# Should get the same number of hits with both searches |
| 92 |
$cmd = "cat $srcdir/testsuite/3box.hmm $srcdir/testsuite/3box.hmm > $tmppfx.hmm"; |
| 93 |
do_cmd($cmd); |
| 94 |
|
| 95 |
# the 3box-alitest.fa test was created with: |
| 96 |
#$database = "$tmppfx.fa"; |
| 97 |
#do_cmd ( "$builddir/easel/miniapps/esl-shuffle --seed 1 --dna -G -N 1 -L 10000 -o $tmppfx.A" ); |
| 98 |
#do_cmd ( "$builddir/src/hmmemit -N 1 --seed 3 $tmppfx.hmm > $tmppfx.B " ); #makes two sequences |
| 99 |
#do_cmd ( "head -n 70 $tmppfx.A > $database" ); |
| 100 |
#do_cmd ( "head -n 2 $tmppfx.B | tail -n 1 >> $database" ); |
| 101 |
#do_cmd ( "tail -n +97 $tmppfx.A | head -n 50 >> $database"); |
| 102 |
#do_cmd ( "head -n 4 $tmppfx.B | tail -n 1 >> $database" ); |
| 103 |
#do_cmd ( "tail -n 47 $tmppfx.A >> $database" ); |
| 104 |
|
| 105 |
@formats = ("ncbi" , "fasta"); |
| 106 |
@exts = ( "", ".fa" ); |
| 107 |
|
| 108 |
for $i (0..$#formats) { |
| 109 |
$fmt = $formats[$i]; |
| 110 |
$ext = $exts[$i]; |
| 111 |
|
| 112 |
$cmd = "$builddir/src/nhmmer --tformat $fmt $tmppfx.hmm $srcdir/testsuite/3box-alitest$ext 2>&1"; |
| 113 |
$output = do_cmd($cmd); |
| 114 |
|
| 115 |
my ($first) = ( $output =~ /Total number of hits:\s+(\d+)/g); |
| 116 |
my ($second) = ( $output =~ /Total number of hits:\s+(\d+)/g); |
| 117 |
|
| 118 |
if ($first != 2 || $second != 2) { |
| 119 |
die "FAIL: rewound second search gave different results for nhmmer, $fmt format"; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
print "ok\n"; |
| 125 |
unlink "$tmppfx.hmm"; |
| 126 |
unlink "$tmppfx.fa"; |
| 127 |
|
| 128 |
|
| 129 |
exit 0; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
sub do_cmd { |
| 135 |
$cmd = shift; |
| 136 |
print "$cmd\n" if $verbose; |
| 137 |
return `$cmd`; |
| 138 |
} |