| 1 |
#! /usr/bin/perl |
| 2 |
|
| 3 |
# Test of hmmbuild/nhmmer as used to build a DNA model, then query a |
| 4 |
# a database of long (1MB). |
| 5 |
# |
| 6 |
# Usage: ./i18-nhmmer-generic.pl <builddir> <srcdir> <tmpfile prefix> |
| 7 |
# Example: ./i18-nhmmer-generic.pl .. .. tmpfoo |
| 8 |
# |
| 9 |
# TJW, Fri Nov 12 11:07:31 EST 2010 [Janelia] |
| 10 |
|
| 11 |
BEGIN { |
| 12 |
$builddir = shift; |
| 13 |
$srcdir = shift; |
| 14 |
$tmppfx = shift; |
| 15 |
$verbose = shift; # if arg not given, defaults to false (zero) |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
# The test makes use of the following file: |
| 20 |
# |
| 21 |
# 3box.sto <msafile> Single 3box alignment |
| 22 |
|
| 23 |
# It creates the following files: |
| 24 |
# $tmppfx.hmm <hmm> 1 model, 3box |
| 25 |
# $tmppfx.A <seqfile> 1 random seq, ~4.5MB in length |
| 26 |
# $tmppfx.B <seqfile> 2 random seqs, generated by hmmemit from $tmppfx.hmm |
| 27 |
# $tmppfx.fa <seqdb> Roughly 4.5MB of a single pseudochromosome, consisting of the two sequences from $tmppfx.B inserted into the sequence of $tmppfx.A |
| 28 |
|
| 29 |
# All models assumed to be in testsuite subdirectory. |
| 30 |
$alignment = "3box.sto"; |
| 31 |
|
| 32 |
@h3progs = ( "hmmemit", "hmmbuild", "nhmmer"); |
| 33 |
@eslprogs = ("esl-shuffle"); |
| 34 |
|
| 35 |
# Verify that we have all the executables and datafiles we need for the test. |
| 36 |
foreach $h3prog (@h3progs) { if (! -x "$builddir/src/$h3prog") { die "FAIL: didn't find $h3prog executable in $builddir/src\n"; } } |
| 37 |
foreach $eslprog (@eslprogs) { if (! -x "$builddir/easel/miniapps/$eslprog") { die "FAIL: didn't find $eslprog executable in $builddir/easel/miniapps\n"; } } |
| 38 |
|
| 39 |
if (! -r "$srcdir/testsuite/$alignment") { die "FAIL: can't read msa $alignment in $srcdir/testsuite\n"; } |
| 40 |
|
| 41 |
# Create the test hmm |
| 42 |
$cmd = "$builddir/src/hmmbuild $tmppfx.hmm $srcdir/testsuite/$alignment"; |
| 43 |
$output = do_cmd($cmd); |
| 44 |
if ($? != 0) { die "FAIL: hmmbuild failed unexpectedly\n"; } |
| 45 |
if ($output !~ /1 3box 22 22 20 75 22.00 1.414/) { |
| 46 |
die "FAIL: hmmbuild failed to build correctly\n"; |
| 47 |
} |
| 48 |
$output = do_cmd( "grep MAXL $tmppfx.hmm" ); |
| 49 |
if ($output !~ /MAXL 75/) { |
| 50 |
die "FAIL: hmmbuild failed to build correctly\n"; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
# Create a roughly 4.5MB database against which to search |
| 55 |
$database = "$tmppfx.fa"; |
| 56 |
do_cmd ( "$builddir/easel/miniapps/esl-shuffle --seed 33 --dna -G -N 1 -L 4500000 -o $tmppfx.A" ); |
| 57 |
do_cmd ( "$builddir/src/hmmemit -N 2 --seed 4 $tmppfx.hmm > $tmppfx.B " ); |
| 58 |
do_cmd ( "$builddir/src/hmmemit -N 1 --seed 3 $tmppfx.hmm >> $tmppfx.B" ); |
| 59 |
do_cmd ( "head -n 33000 $tmppfx.A > $database" ); |
| 60 |
do_cmd ( "head -n 2 $tmppfx.B | tail -n 1 >> $database" ); |
| 61 |
do_cmd ( "tail -n +33001 $tmppfx.A | head -n 22000 >> $database"); |
| 62 |
do_cmd ( "head -n 4 $tmppfx.B | tail -n 1 >> $database" ); |
| 63 |
do_cmd ( "tail -n 20000 $tmppfx.A >> $database" ); |
| 64 |
do_cmd ( "tail -n 1 $tmppfx.B >> $database" ); |
| 65 |
|
| 66 |
# perform nhmmer search |
| 67 |
$cmd = "$builddir/src/nhmmer --tformat fasta $tmppfx.hmm $database"; |
| 68 |
$output = do_cmd($cmd); |
| 69 |
|
| 70 |
if ($? != 0) { die "FAIL: nhmmer failed unexpectedly\n"; } |
| 71 |
$expect = |
| 72 |
q[ |
| 73 |
Target sequences: 1 \(9000000 residues searched\) |
| 74 |
Residues passing SSV filter: 172355 \(0.0192\); expected \(0.02\) |
| 75 |
Residues passing bias filter: 144134 \(0.016\); expected \(0.02\) |
| 76 |
Residues passing Vit filter: 17743 \(0.00197\); expected \(0.003\) |
| 77 |
Residues passing Fwd filter: 415 \(4.61e-05\); expected \(3e-05\) |
| 78 |
Total number of hits: 4 \(8.33e-06\)]; |
| 79 |
if ($output !~ /$expect/s) { |
| 80 |
die "FAIL: nhmmer failed search test 1\n"; |
| 81 |
} |
| 82 |
|
| 83 |
$expect = q[ |
| 84 |
0.31 14.1 4.3 random 4499980 4500000\s+ |
| 85 |
0.57 13.3 3.7 random 3299961 3299979\s+ |
| 86 |
1.4 12.1 4.4 random 1979941 1979960\s+ |
| 87 |
7.8 9.7 2.3 random 2354832 2354818]; |
| 88 |
if ($output !~ /$expect/s) { |
| 89 |
die "FAIL: nhmmer failed search test 2\n"; |
| 90 |
} |
| 91 |
|
| 92 |
$cmd = "$builddir/src/nhmmer --tformat fasta --watson $tmppfx.hmm $database"; |
| 93 |
$output = do_cmd($cmd); |
| 94 |
if ($? != 0) { die "FAIL: nhmmer failed unexpectedly\n"; } |
| 95 |
$expect = q[ |
| 96 |
Target sequences: 1 \(4500000 residues searched\) |
| 97 |
Residues passing SSV filter: 84074 \(0.0187\); expected \(0.02\) |
| 98 |
Residues passing bias filter: 69825 \(0.0155\); expected \(0.02\) |
| 99 |
Residues passing Vit filter: 8940 \(0.00199\); expected \(0.003\) |
| 100 |
Residues passing Fwd filter: 228 \(5.07e-05\); expected \(3e-05\) |
| 101 |
Total number of hits: 3 \(1.33e-05\)]; |
| 102 |
|
| 103 |
if ($output !~ /$expect/s) { |
| 104 |
die "FAIL: nhmmer failed search test 3\n"; |
| 105 |
} |
| 106 |
$expect = q[ |
| 107 |
0.15 14.1 4.3 random 4499980 4500000\s+ |
| 108 |
0.28 13.3 3.7 random 3299961 3299979\s+ |
| 109 |
0.68 12.1 4.4 random 1979941 1979960]; |
| 110 |
if ($output !~ /$expect/s) { |
| 111 |
die "FAIL: nhmmer failed search test 4\n"; |
| 112 |
} |
| 113 |
|
| 114 |
print "ok\n"; |
| 115 |
unlink "$tmppfx.hmm"; |
| 116 |
unlink "$tmppfx.A"; |
| 117 |
unlink "$tmppfx.B"; |
| 118 |
unlink "$tmppfx.fa"; |
| 119 |
|
| 120 |
exit 0; |
| 121 |
|
| 122 |
|
| 123 |
sub do_cmd { |
| 124 |
$cmd = shift; |
| 125 |
print "$cmd\n" if $verbose; |
| 126 |
return `$cmd`; |
| 127 |
} |