Debian Codegraph @

testsuite/itest4-stdin.pl

raw
1 #! /usr/bin/perl
2
3 # Test that programs accept and reject argument of '-' (for reading
4 # data from stdin, rather than from files) as they're supposed to.
5 #
6 # Usage: ./itest4-stdin.pl <builddir> <srcdir> <tmpfile prefix>
7 # Example: ./itest4-stdin.pl .. .. tmpfoo
8 #
9 # SRE, Wed Oct 27 13:05:10 2010 [Janelia]
10
11
12 BEGIN {
13 $builddir = shift;
14 $srcdir = shift;
15 $tmppfx = shift;
16 }
17
18 $verbose = 0;
19
20 # The test makes use of the following files:
21 #
22 # $model1.c.cm <cmfile> Single tRNA model, calibrated
23 # $model2.c.cm <cmfile> Single snR75 model (0 basepairs), calibrated
24 # $model3.c.cm <cmfile> Single Vault model, calibrated
25 # $model1.sto <msafile> Single tRNA alignment
26 # $model2.sto <msafile> Single snR75 alignment
27 # $model3.sto <msafile> Single Vault alignment
28
29 # It creates the following files:
30 # $tmppfx.cm <cmdb> 3 models, tRNA + snR75 + Vault
31 # $tmppfx.sto <msadb> 3 MSAs, tRNA + Vault
32 # $tmppfx.cm.i1{mifp} cmpress auxfiles for .cm file
33 # $tmppfx.fa1 <seqfile> 1 consensus seq from tRNA model
34 # $tmppfx.fa2 <seqfile> 3 consensus seqs, one from tRNA, one from snR75 and one from Vault
35 # $tmppfx.fa10 <seqfile> 10 seqs from tRNA model
36 # $tmppfx.db <seqdb> 10 tRNA + 10 snR75 + 100 random seqs
37 # $tmppfx.key <keyfile> "snR75" in a file, to test cmfetch -f
38 #
39
40 # All models assumed to be in testsuite subdirectory.
41 $model1 = "tRNA";
42 $model2 = "snR75";
43 $model3 = "Vault";
44
45 @i1progs = ("cmalign", "cmbuild", "cmconvert", "cmemit", "cmfetch", "cmpress", "cmscan", "cmsearch", "cmstat");
46 @eslprogs = ("esl-shuffle");
47
48 # Verify that we have all the executables and datafiles we need for the test.
49 foreach $i1prog (@i1progs) { if (! -x "$builddir/src/$i1prog") { die "FAIL: didn't find $i1prog executable in $builddir/src\n"; } }
50 foreach $eslprog (@eslrogs) { if (! -x "$builddir/easel/miniapps/$eslprog") { die "FAIL: didn't find $eslprog executable in $builddir/easel/miniapps\n"; } }
51
52 if (! -r "$srcdir/testsuite/$model1.c.cm") { die "FAIL: can't read profile $model1.c.cm in $srcdir/testsuite\n"; }
53 if (! -r "$srcdir/testsuite/$model2.c.cm") { die "FAIL: can't read profile $model2.c.cm in $srcdir/testsuite\n"; }
54 if (! -r "$srcdir/testsuite/$model3.c.cm") { die "FAIL: can't read profile $model3.c.cm in $srcdir/testsuite\n"; }
55
56 if (! -r "$srcdir/testsuite/$model1.sto") { die "FAIL: can't read msa $model1.sto in $srcdir/testsuite\n"; }
57 if (! -r "$srcdir/testsuite/$model2.sto") { die "FAIL: can't read msa $model2.sto in $srcdir/testsuite\n"; }
58 if (! -r "$srcdir/testsuite/$model3.sto") { die "FAIL: can't read msa $model3.sto in $srcdir/testsuite\n"; }
59
60 `cat $srcdir/testsuite/$model1.c.cm $srcdir/testsuite/$model2.c.cm $srcdir/testsuite/$model3.c.cm > $tmppfx.cm`; if ($?) { die "FAIL: cat\n"; }
61 if(-e "$tmppfx.cm.i1m") { unlink "$tmppfx.cm.i1m"; }
62 if(-e "$tmppfx.cm.i1p") { unlink "$tmppfx.cm.i1p"; }
63 if(-e "$tmppfx.cm.i1f") { unlink "$tmppfx.cm.i1f"; }
64 if(-e "$tmppfx.cm.i1i") { unlink "$tmppfx.cm.i1i"; }
65 if(-e "$tmppfx.cm.ssi") { unlink "$tmppfx.cm.ssi"; }
66 `$builddir/src/cmpress $tmppfx.cm`; if ($?) { die "FAIL: cmpress\n"; }
67
68 `cat $srcdir/testsuite/$model1.sto $srcdir/testsuite/$model2.sto $srcdir/testsuite/$model3.sto > $tmppfx.sto`; if ($?) { die "FAIL: cat\n"; }
69
70 `$builddir/src/cmemit -c $srcdir/testsuite/$model1.c.cm > $tmppfx.fa1`; if ($?) { die "FAIL: cmemit -c\n"; }
71 `cat $tmppfx.fa1 > $tmppfx.fa2`; if ($?) { die "FAIL: cat\n"; }
72 `$builddir/src/cmemit -c $srcdir/testsuite/$model2.c.cm >> $tmppfx.fa2`; if ($?) { die "FAIL: cmemit -c\n"; }
73 `$builddir/src/cmemit -c $srcdir/testsuite/$model3.c.cm >> $tmppfx.fa2`; if ($?) { die "FAIL: cmemit -c\n"; }
74
75 `$builddir/src/cmemit -N10 $srcdir/testsuite/$model1.c.cm > $tmppfx.fa10`; if ($?) { die "FAIL: cmemit\n"; }
76
77 `$builddir/src/cmemit -N10 $srcdir/testsuite/$model1.c.cm > $tmppfx.db`; if ($?) { die "FAIL: cmemit\n"; }
78 `$builddir/src/cmemit -N10 $srcdir/testsuite/$model2.c.cm >> $tmppfx.db`; if ($?) { die "FAIL: cmemit\n"; }
79 `$builddir/src/cmemit -N10 $srcdir/testsuite/$model3.c.cm >> $tmppfx.db`; if ($?) { die "FAIL: cmemit\n"; }
80 `$builddir/easel/miniapps/esl-shuffle -G -N100 -L 80 --rna >> $tmppfx.db`; if ($?) { die "FAIL: esl-shuffle\n"; }
81
82 `echo $model1 > $tmppfx.key`; if ($?) { die "FAIL: cat\n"; }
83 `echo $model2 >> $tmppfx.key`; if ($?) { die "FAIL: cat\n"; }
84
85 ################################################################
86 # cmalign
87 # reject - - case
88 ################################################################
89
90 $tag = "cmalign"; $prog = "$builddir/src/$tag";
91 $tag1 = "<cmfile>"; $arg1 = "$srcdir/testsuite/$model1.c.cm";
92 $tag2 = "<seqfile>"; $arg2 = "$tmppfx.fa10";
93 if ($verbose) { print "$tag...\n"; }
94
95 `$prog --cpu 1 $arg1 $arg2 | grep -v "^#DEBUG" > $tmppfx.out1`; if ($?) { die "FAIL: $tag $tag1 $tag2\n"; }
96 `cat $arg1 | $prog --cpu 1 - $arg2 | grep -v "^#DEBUG" > $tmppfx.out2`; if ($?) { die "FAIL: $tag - $tag2\n"; }
97 `cat $arg2 | $prog --cpu 1 $arg1 - | grep -v "^#DEBUG" > $tmppfx.out3`; if ($?) { die "FAIL: $tag $tag1 -\n"; }
98
99 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`; if ($?) { die "FAIL: $tag results differ if $tag1 comes through stdin\n"; }
100 `diff -b $tmppfx.out1 $tmppfx.out3 2>&1 > /dev/null`; if ($?) { die "FAIL: $tag results differ if $tag2 comes through stdin\n"; }
101
102 $output = `cat $arg1 $arg2 | $prog - - 2>&1`;
103 if (!$?) { die "FAIL: $tag should fail on double - -\n"; }
104 if ($output !~ /^\nERROR: Either <cmfile> or <seqfile>/) { die "FAIL: $tag didn't give expected error message for the - - case.\n"; }
105
106 ################################################################
107 # cmbuild
108 # don't diff CM files, they may fail because of DATE field
109 # reject - for <cmfile>: can't send it to stdout.
110 ################################################################
111
112 $tag = "cmbuild"; $prog = "$builddir/src/$tag";
113 $tag1 = "<msafile>"; $arg1 = "$tmppfx.sto";
114 if ($verbose) { print "$tag...\n"; }
115
116 `$prog -F $tmppfx.cm.out1 $arg1 | grep -v "^#" > $tmppfx.out1`; if ($?) { die "FAIL: $tag <cmfile> $tag1 \n"; }
117 `cat $arg1 | $prog -F --informat stockholm $tmppfx.cm.out2 - | grep -v "^#" > $tmppfx.out2`; if ($?) { die "FAIL: $tag <cmfile> -\n"; }
118 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`; if ($?) { die "FAIL: $tag results differ if $tag1 comes through stdin\n"; }
119
120 $output = `$prog - $arg1`;
121 if (!$?) { die "FAIL: $tag should reject - for <cmfile_out>\n"; }
122
123 ################################################################
124 # cmconvert
125 ################################################################
126
127 $tag = "cmconvert"; $prog = "$builddir/src/$tag";
128 $tag1 = "<cmfile>"; $arg1 = "$tmppfx.cm";
129 if ($verbose) { print "$tag...\n"; }
130
131 # need to remove COM lines, they will differ due to different cmdline usage, differs from hmmer version
132 `$prog $arg1 | grep -v "^COM" > $tmppfx.out1`; if ($?) { die "FAIL: $tag $tag1\n"; }
133 `cat $arg1 | $prog - | grep -v "^COM" > $tmppfx.out2`; if ($?) { die "FAIL: $tag -\n"; }
134
135 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`;
136 if ($?) { die "FAIL: $tag results differ if $tag1 comes through stdin\n"; }
137
138 ################################################################
139 # cmemit
140 # need to pass fixed RNG seed to be able to diff outputs
141 ################################################################
142
143 $tag = "cmemit"; $prog = "$builddir/src/$tag";
144 $tag1 = "<cmfile>"; $arg1 = "$tmppfx.cm";
145 if ($verbose) { print "$tag...\n"; }
146
147 `$prog --seed 42 $arg1 > $tmppfx.out1`; if ($?) { die "FAIL: $tag $tag1\n"; }
148 `cat $arg1 | $prog --seed 42 - > $tmppfx.out2`; if ($?) { die "FAIL: $tag -\n"; }
149
150 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`;
151 if ($?) { die "FAIL: $tag results differ if $tag1 comes through stdin\n"; }
152
153
154 ################################################################
155 # cmfetch
156 # need to check all three use modes, including -f and --index
157 # --index rejects -
158 # w/ -f, only one of <cmfile>, <keyfile> can be -
159 # -f fetches in different orders depending on whether file is
160 # indexed or not, so <keyfile> must be constructed to give
161 # same fetch order either way.
162 ################################################################
163
164 $tag = "cmfetch"; $prog = "$builddir/src/$tag";
165 $tag1 = "<cmfile>"; $arg1 = "$tmppfx.cm";
166 $tag2 = "<keyfile>"; $arg2 = "$tmppfx.key";
167 if ($verbose) { print "$tag...\n"; }
168
169 `$prog $arg1 snR75 > $tmppfx.out1`; if ($?) { die "FAIL: $tag $tag1\n"; }
170 `cat $arg1 | $prog - snR75 > $tmppfx.out2`; if ($?) { die "FAIL: $tag -\n"; }
171 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`; if ($?) { die "FAIL: $tag results differ if $tag1 comes through stdin\n"; }
172
173 `$prog -f $arg1 $arg2 > $tmppfx.out1`; if ($?) { die "FAIL: $tag -f $tag1 $tag2\n"; }
174 `cat $arg1 | $prog -f - $arg2 > $tmppfx.out2`; if ($?) { die "FAIL: $tag -f - $tag2\n"; }
175 `cat $arg2 | $prog -f $arg1 - > $tmppfx.out3`; if ($?) { die "FAIL: $tag -f $tag1 -\n"; }
176 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`; if ($?) { die "FAIL: $tag -f results differ if $tag1 comes through stdin\n"; }
177 `diff -b $tmppfx.out1 $tmppfx.out3 2>&1 > /dev/null`; if ($?) { die "FAIL: $tag -f results differ if $tag2 comes through stdin\n"; }
178
179 $output = `cat $arg1 $arg2 | $prog -f - - 2>&1`;
180 if (! $?) { die "FAIL: $tag should have failed on double - -\n"; }
181 if ($output !~ /^Either <cmfile> or <keyfile>/) { die "FAIL: $tag didn't give expected error message for the - - case.\n"; }
182
183 if(-e "$arg1.i1m") { unlink "$arg1.i1m"; }
184 if(-e "$arg1.i1p") { unlink "$arg1.i1p"; }
185 if(-e "$arg1.i1f") { unlink "$arg1.i1f"; }
186 if(-e "$arg1.i1i") { unlink "$arg1.i1i"; }
187 if(-e "$arg1.ssi") { unlink "$arg1.ssi"; }
188 `$prog --index $arg1 > $tmppfx.out1`; if ($?) { die "FAIL: $tag --index $tag1\n"; }
189 $output = `cat $arg1 | $prog --index - 2>&1`; if (! $?) { die "FAIL: $tag should reject - for <cmfile> when using --index\n"; }
190 if ($output !~ /^Can't use - with --index/) { die "FAIL: $tag didn't give expected error message for the - - case.\n"; }
191
192 ################################################################
193 # cmpress
194 # rejects - argument.
195 ################################################################
196
197 $tag = "cmpress"; $prog = "$builddir/src/$tag";
198 $tag1 = "<cmfile>"; $arg1 = "$tmppfx.cm";
199 if ($verbose) { print "$tag...\n"; }
200
201 $output = `cat $arg1 | $prog - 2>&1`; if (! $?) { die "FAIL: $tag should reject - for <cmfile>\n"; }
202 if ($output !~ /^\nError: Can't use - for <cmfile>/) { die "FAIL: $tag didn't give expected error message.\n"; }
203
204 #################################################################
205 # cmscan
206 # rejects - for <cmfile>, because it must be cmpress'ed.
207 #################################################################
208
209 $tag = "cmscan"; $prog = "$builddir/src/$tag";
210 $tag1 = "<cmdb>"; $arg1 = "$tmppfx.cm";
211 $tag2 = "<seqfile>"; $arg2 = "$tmppfx.fa2";
212 if ($verbose) { print "$tag...\n"; }
213
214 # need to repress $tmppfx.cm, we deleted pressed files above
215 `$builddir/src/cmpress $arg1`; if ($?) { die "FAIL: cmpress\n"; }
216 `$prog --cpu 1 $arg1 $arg2 | grep -v "^#" > $tmppfx.out1`; if ($?) { die "FAIL: $tag $tag1 $tag2\n"; }
217 `cat $arg2 | $prog --cpu 1 $arg1 - | grep -v "^#" > $tmppfx.out2`; if ($?) { die "FAIL: $tag $tag1 -\n"; }
218
219 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`;
220 if ($?) { die "FAIL: $tag results differ if $arg2 comes from stdin\n"; }
221
222 $output = `cat $arg1 | $prog - $arg2 2>&1`;
223 if (! $?) { die "FAIL: $tag should reject - for $tag1\n"; }
224 if ($output !~ /^cmscan cannot read/) { die "FAIL: cmscan didn't give expected error message\n"; }
225
226
227 #################################################################
228 # cmsearch
229 # reject - - case
230 # reject <seqdb> as -, for all CM files (unlike H3, which works as long as not multiquery)
231 #################################################################
232 # note that the grep -v "^#" removes lines that would make diffs fail,
233 # like query name and cpu time.
234
235 $tag = "cmsearch"; $prog = "$builddir/src/$tag";
236 $tag1 = "<cmfile>"; $arg1 = "$srcdir/testsuite/$model1.c.cm";
237 $tag2 = "<seqdb>"; $arg2 = "$tmppfx.db";
238 if ($verbose) { print "$tag...\n"; }
239
240 `$prog --cpu 1 $arg1 $arg2 | grep -v "^#" > $tmppfx.out1`; if ($?) { die "FAIL: $tag $tag1 $tag2\n"; }
241 `cat $arg1 | $prog --cpu 1 - $arg2 | grep -v "^#" > $tmppfx.out2`; if ($?) { die "FAIL: $tag - $tag2\n"; }
242
243 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`; if ($?) { die "FAIL: $prog results differ if $tag1 comes through stdin\n"; }
244
245 $output = `cat $arg2 | $prog $arg1 - 2>&1`; if (! $?) { die "FAIL: $prog should fail on stdin $tag2.\n"; }
246 $output = `cat $arg1 $arg2 | $prog - - 2>&1`; if (! $?) { die "FAIL: $prog should have failed on double - -\n"; }
247
248 ################################################################
249 # cmstat
250 ################################################################
251
252 $tag = "cmstat"; $prog = "$builddir/src/$tag";
253 $tag1 = "<cmfile>"; $arg1 = "$tmppfx.cm";
254 if ($verbose) { print "$tag...\n"; }
255
256 `$prog $arg1 > $tmppfx.out1`; if ($?) { die "FAIL: $tag $tag1\n"; }
257 `cat $arg1 | $prog - > $tmppfx.out2`; if ($?) { die "FAIL: $tag -\n"; }
258
259 `diff -b $tmppfx.out1 $tmppfx.out2 2>&1 > /dev/null`; if ($?) { die "FAIL: $tag results differ if $tag1 comes through stdin\n"; }
260
261
262
263 unlink <$tmppfx.out*>;
264 unlink <$tmppfx.cm*>;
265 unlink "$tmppfx.sto";
266 unlink "$tmppfx.fa1";
267 unlink "$tmppfx.fa2";
268 unlink "$tmppfx.fa10";
269 unlink "$tmppfx.db";
270 unlink "$tmppfx.key";
271
272 print "ok\n";
273 exit 0;