2 ## Bioperl Test Harness Script for Modules
9 $NUMTESTS = 3; # base number of tests (those not in blocks)
11 # I have set up eutils tests to run in sections for easier test maintenance
12 # and keeping track of problematic tests. The below hash is the list of
13 # tests, with test number and coderef.
15 # these now run very simple tests for connectivity and data sampling
16 # main tests now with the parser
19 'params' => {'tests' => 13,
20 'sub' => \&simple_param_tests},
21 'cmalign' => {'tests' => 6,
22 'sub' => \&cmalign_norm},
23 # need to add merge tests
24 'cmsearch' => {'tests' => 7,
26 'cmbuild' => {'tests' => 4,
28 'cmstat' => {'tests' => 2,
30 # leave this one commented (may run for quite a while dep. on CPU)
31 #'cmcalibrate' => {'tests' => 2,
32 # 'sub' => \&cmcalibrate},
33 'cmscore' => {'tests' => 2,
35 'cmemit' => {'tests' => 6,
38 $NUMTESTS += $INFERNAL_TESTS{$_}->{'tests'} for (keys %INFERNAL_TESTS);
42 test_begin(-tests => $NUMTESTS );
43 use_ok('Bio::Tools::Run::Infernal');
45 use_ok('Bio::AlignIO');
48 my $factory = Bio::Tools::Run::Infernal->new(-program => 'cmsearch');
51 test_skip(-requires_executable => $factory,
52 -tests => $NUMTESTS - 3);
53 for my $test (keys %INFERNAL_TESTS) {
54 $INFERNAL_TESTS{$test}->{'sub'}->();
58 # test out parameters and command string building
59 sub simple_param_tests {
63 outfile => 'foo.txt', # this won't get set (not a valid param for cmsearch)
64 o => 'bar.infernal', # test multiple outfile designations
66 tabfile => 'tab.txt', # param
70 test1 => 'cmsearch --dna -g --gcfile gc.txt --tabfile tab.txt -o bar.infernal baz.cm seq1.txt',
71 test2 => 'cmsearch --dna -g --gcfile gc.txt --tabfile tab.txt -o bar.infernal arg.cm seq1.txt',
72 seq_files => ['seq1.txt'],
81 -tfile => 'trees.txt',
82 -outfile_name => 'seqs.stk'
84 test1 => 'cmemit -a -l --rna -n 10 --tfile trees.txt baz.cm seqs.stk',
85 test2 => 'cmemit -a -l --rna -n 10 --tfile trees.txt arg.cm seqs.stk',
96 outfile => 'seqs.fna', # note this is different from outfile_name
97 -outfile_name => 'seqs.stk'
99 test1 => 'cmscore -a -l --mxsize 4096 -n 10 --outfile seqs.fna baz.cm > seqs.stk',
100 test2 => 'cmscore -a -l --mxsize 4096 -n 10 --outfile seqs.fna arg.cm > seqs.stk',
111 test1 => 'cmalign --cyk -l --tau 1e-07 -o aligns.stk baz.cm seq1.fas',
112 test2 => 'cmalign --cyk -l --tau 1e-07 -o aligns.stk arg.cm seq1.fas',
113 test3 => 'cmalign --cyk -l --merge --tau 1e-07 -o aligns.stk arg.cm alns1.stk alns2.stk',
114 seq_files => ['seq1.fas'],
115 align_files => ['alns1.stk', 'alns2.stk'],
122 test1 => 'cmbuild --binary --ehmmre 12 baz.cm alns1.stk',
123 test2 => 'cmbuild --binary --ehmmre 12 arg.cm alns1.stk',
124 seq_files => ['seq1.fas'],
125 align_files => ['alns1.stk'],
130 '-exp-no-qdb' => 1, # note use of quotes
132 test1 => 'cmcalibrate --exp-no-qdb -s 12 baz.cm',
133 test2 => 'cmcalibrate --exp-no-qdb -s 12 arg.cm',
136 for my $exe (sort keys %executable) {
137 my %p = %{$executable{$exe}{params}};
138 $factory = Bio::Tools::Run::Infernal->new(-program => $exe,
139 -model_file => 'baz.cm',
141 like($factory->to_exe_string(-seq_files => $executable{$exe}{seq_files},
142 -align_files => $executable{$exe}{align_files}),
143 qr/$executable{$exe}{test1}/,"$exe parameter setting");
144 $factory->model_file('arg.cm');
145 like($factory->to_exe_string(-seq_files => $executable{$exe}{seq_files},
146 -align_files => $executable{$exe}{align_files}),
147 qr/$executable{$exe}{test2}/,"$exe parameter setting");
148 if ($exe eq 'cmalign') {
149 $factory->set_parameters(merge => 1);
150 like($factory->to_exe_string(-seq_files => $executable{$exe}{seq_files},
151 -align_files => $executable{$exe}{align_files}),
152 qr/$executable{$exe}{test3}/,"$exe parameter setting");
158 my ($model, $input) = (test_input_file('purine.c.cm'), test_input_file('xprt.gb'));
159 my $factory = Bio::Tools::Run::Infernal->new(-model_file => $model,
160 -program => 'cmsearch',
161 -verbose => test_debug());
164 test_skip(-requires_executable => $factory,
168 my $searchio = $factory->cmsearch($input);
169 isa_ok($searchio, 'Bio::SearchIO', 'cmsearch works for v1.0 with file name;');
170 my $result = $searchio->next_result();
171 isa_ok($result, 'Bio::Search::Result::ResultI');
172 is($result->hits, 1);
173 my $hit = $result->next_hit;
176 # from a Bio::PrimarySeqI
177 my $seq = Bio::SeqIO->new(-format => 'genbank',
178 -file => $input)->next_seq;
179 $searchio = $factory->cmsearch($seq);
180 isa_ok($searchio, 'Bio::SearchIO', 'cmsearch works for v1.0 with PrimarySeq;');
181 $result = $searchio->next_result();
182 is($result->hits, 1);
183 $hit = $result->next_hit;
189 my ($aln, $outfile) = (test_input_file('purine.1.sto'), test_output_file());
193 my $factory = Bio::Tools::Run::Infernal->new(-model_file => $outfile,
195 -program => 'cmbuild',
196 -verbose => test_debug());
198 test_skip(-requires_executable => $factory,
202 my $success = $factory->cmbuild($aln);
203 ok($success, 'cmbuild works using alignment file');
204 ok(-e $outfile, 'CM file created');
206 my $outfile2 = test_output_file();
210 $factory->model_file($outfile2);
212 # from a Bio::Align::AlignI
213 my $alnobj = Bio::AlignIO->new(-format => 'stockholm',
214 -file => $aln)->next_aln;
215 $success = $factory->cmbuild($alnobj);
216 ok($success, 'cmbuild works using Bio::Align::AlignI');
217 ok(-e $outfile2, 'CM file created');
222 my ($cm, $outfile) = (test_input_file('purine.c.cm'), test_output_file());
223 my $factory = Bio::Tools::Run::Infernal->new(-model_file => $cm,
224 -outfile_name => $outfile,
225 -program => 'cmstat',
226 -verbose => test_debug());
228 test_skip(-requires_executable => $factory,
231 my $success = $factory->cmstat();
232 ok($success, 'cmstat works');
233 ok (-e $outfile, 'cmstat outfile created');
238 my ($cm, $outfile) = (test_input_file('purine.c.cm'), test_output_file());
239 my $factory = Bio::Tools::Run::Infernal->new(-model_file => $cm,
240 -outfile_name => $outfile,
241 -program => 'cmscore',
242 -verbose => test_debug());
244 test_skip(-requires_executable => $factory,
247 my $success = $factory->cmscore();
248 ok($success, 'cmscore works');
249 ok (-e $outfile, 'cmscore outfile created');
254 my ($cm, $seqfile) = (test_input_file('purine.c.cm'),
255 test_input_file('purine.added.fa'));
256 my $factory = Bio::Tools::Run::Infernal->new(-model_file => $cm,
257 -program => 'cmalign');
259 test_skip(-requires_executable => $factory,
264 my $stream = $factory->cmalign($seqfile);
265 isa_ok($stream, 'Bio::AlignIO', 'cmalign works');
266 my $aln = $stream->next_aln;
267 isa_ok($aln, 'Bio::Align::AlignI');
268 is($aln->num_sequences, 2);
270 my $seqio = Bio::SeqIO->new(-format => 'fasta', -file => $seqfile);
272 while (my $seq = $seqio->next_seq) {
276 $stream = $factory->cmalign(@seqs);
277 isa_ok($stream, 'Bio::AlignIO', 'cmalign works');
278 $aln = $stream->next_aln;
279 isa_ok($aln, 'Bio::Align::AlignI');
280 is($aln->num_sequences, 2);
285 my ($cm, $outfile) = (test_input_file('purine.c.cm'), test_output_file());
286 my $factory = Bio::Tools::Run::Infernal->new(-model_file => $cm,
287 -program => 'cmemit',
288 -outfile_name => $outfile,
292 test_skip(-requires_executable => $factory,
296 my $stream = $factory->cmemit();
297 isa_ok($stream, 'Bio::SeqIO', 'cmemit works');
298 my $seq = $stream->next_seq;
299 isa_ok($seq, 'Bio::PrimarySeqI');
300 is($seq->display_id, 'Purine-1');
302 # alignment (-a flag)
303 $factory->set_parameters(-a => 1);
304 $stream = $factory->cmemit();
305 isa_ok($stream, 'Bio::AlignIO', 'cmemit works');
306 my $aln = $stream->next_aln;
307 isa_ok($aln, 'Bio::Align::AlignI');
308 is($aln->num_sequences, 10);
313 my $cm = test_input_file('purine.cm');
314 my $factory = Bio::Tools::Run::Infernal->new(-model_file => $cm,
315 -program => 'cmcalibrate');
317 test_skip(-requires_executable => $factory,
321 my $success = $factory->cmcalibrate();
322 ok($success, 'cmcalibrate successful');
323 cmp_ok(-M $cm, '<=' ,1);