1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 128);
12 use_ok('Bio::Seq::Meta');
13 use_ok('Bio::Seq::Meta::Array');
15 use_ok('Bio::AlignIO');
16 use_ok('Bio::Seq::Quality');
19 my $DEBUG = test_debug();
21 ok my $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA");
23 ok $seq->force_flush(1);
25 $seq->seq("AT-CGATCGATT");
27 ok not $seq->force_flush(0);
29 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA");
30 is $seq->meta_text, "";
31 ok $seq->force_flush(1);
32 $seq->seq("AT-CGATCGATT");
33 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0 0 0";
34 ok not $seq->force_flush(0);
36 ok $seq = Bio::Seq::Quality->new( -seq => "AT-CGATCGA");
37 is $seq->meta_text, "";
38 ok $seq->force_flush(1);
39 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0";
40 $seq->seq("AT-CGATCGATT");
41 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0 0 0";
42 ok not $seq->force_flush(0);
44 ok $seq = Bio::Seq::Meta->new
51 # create a sequence object
52 ok $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA",
59 is $seq->meta_length, 10;
61 # Create some random meta values, but gap in the wrong place
62 my $metastring = "a-abb bb ";
63 $seq->meta($metastring);
66 # create some random meta values, but not for the last residue
67 $metastring = "aa-bb bb";
68 ok $seq->meta($metastring), $metastring. " ";
70 # truncate the sequence by assignment
73 $seq->alphabet('dna');
74 is $seq->meta, 'aa-bb ';
79 # truncate the sequence with trunc()
80 is $seq->strand(-1), -1;
81 ok $seq = $seq->trunc(1,5);
84 is $seq->seq, 'AT-CG';
85 is $seq->meta, 'aa-bb';
89 ok $seq = $seq->revcom;
90 is $seq->seq, 'CG-AT';
91 is $seq->meta, 'bb-aa';
95 is $seq->subseq(2,4), 'G-A';
96 is $seq->submeta(2,4), 'b-a';
97 is $seq->submeta(2,undef, 'c-c'), 'c-ca';
98 is $seq->submeta(2,4), 'c-c';
99 is $seq->meta, 'bc-ca';
100 is $seq->meta(''), ' ';
101 is $seq->submeta(2,undef, 'c-c'), 'c-c ';
102 is $seq->meta, ' c-c ';
104 # add named meta annotations
107 is $seq->named_meta('first', $first), $first;
108 is $seq->named_meta('first'), $first;
110 my $second = '[[-]]';
111 ok $seq->named_meta('second', $second);
113 # undefined range arguments
114 is $seq->named_submeta('second', 3, 4), '-]';
115 is $seq->named_submeta('second', 3), '-]]';
116 is $seq->named_submeta('second'), '[[-]]';
118 my @names = $seq->meta_names;
120 is $names[0], 'DEFAULT';
129 my ($infile, $outfile) = @_;
132 $in .= $_ while (<FH>);
136 $out .= $_ while (<FH>);
138 print "|$in||$out|\n" if $DEBUG;
145 my $str = Bio::SeqIO->new
146 ( '-file'=> test_input_file('test.metafasta'),
147 '-format' => 'metafasta');
148 ok $seq = $str->next_seq;
150 my $outfile = test_output_file();
151 my $strout = Bio::SeqIO->new
152 ('-file'=> ">". $outfile,
153 '-format' => 'metafasta');
154 ok $strout->write_seq($seq);
156 diff (test_input_file('test.metafasta'),
162 $str = Bio::AlignIO->new
163 ( '-file'=> test_input_file('testaln.metafasta'),
164 '-format' => 'metafasta');
165 ok my $aln = $str->next_aln;
167 $outfile = test_output_file();
168 $strout = Bio::AlignIO->new
169 ('-file'=> ">". $outfile,
170 '-format' => 'metafasta');
171 ok $strout->write_aln($aln);
173 diff (test_input_file('testaln.metafasta'),
179 ### tests for Meta::Array
183 ok $seq = Bio::Seq::Meta::Array->new
190 # create a sequence object
191 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA",
197 is $seq->is_flush, 1;
198 #is $seq->meta_text, " ";
199 is $seq->meta_text, '0 0 0 0 0 0 0 0 0 0';
201 # create some random meta values, but not for the last residue
202 $metastring = "a a - b b 0 b b 0";
203 is join (' ', @{$seq->meta($metastring)}), $metastring. ' 0';
204 is $seq->meta_text, $metastring. ' 0';
206 # truncate the sequence by assignment
208 $seq->alphabet('dna');
209 is $seq->meta_text, 'a a - b b 0';
211 # truncate the sequence with trunc()
212 is $seq->strand(-1), -1;
213 ok $seq = $seq->trunc(1,5);
214 is $seq->seq, 'AT-CG';
215 is $seq->meta_text, 'a a - b b';
219 #is $seq->meta_length, 6;
220 #ok $seq->force_flush(1);
221 #is $seq->meta_length, 5;
224 ok $seq = $seq->revcom;
225 is $seq->seq, 'CG-AT';
226 is $seq->meta_text, 'b b - a a';
231 is $seq->subseq(2,4), 'G-A';
233 is $seq->submeta_text(2,4), 'b - a';
234 is $seq->submeta_text(2,undef, 'c - c'), 'c - c';
235 is $seq->submeta_text(2,4), 'c - c';
236 is $seq->meta_text, 'b c - c a';
238 is $seq->meta_text(''), '0 0 0 0 0';
239 is $seq->submeta_text(2,undef, 'c - c'), 'c - c';
240 is $seq->meta_text, '0 c - c 0';
242 # add named meta annotations
243 $first = '1 10 - 222 23';
244 is $seq->named_meta_text('first', $first), $first;
245 is $seq->named_meta_text('first'), $first;
246 $second = '[ [ - ] ]';
247 ok $seq->named_meta_text('second', $second);
249 # undefined range arguments
250 is $seq->named_submeta_text('second', 3, 4), '- ]';
251 is $seq->named_submeta_text('second', 3), '- ] ]';
252 is $seq->named_submeta_text('second'), '[ [ - ] ]';
254 @names = $seq->meta_names;
256 is $names[0], 'DEFAULT';
262 # testing the forcing of flushed meta values
268 ok $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA",
272 is $seq->submeta(4, 6, '456'), '456';
273 is $seq->meta_length, 6;
276 is $seq->meta, " 456";
278 ok $seq->force_flush(1);
279 is $seq->meta, " 456 ";
280 ok $seq->seq('aaatttc');
281 is $seq->meta, " 456 ";
283 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA",
287 is join (' ', @{$seq->submeta(4, 6, '4 5 6')}), '4 5 6';
288 is $seq->meta_length, 6;
291 is $seq->meta_text, "0 0 0 4 5 6";
292 ok $seq->force_flush(1);
293 is $seq->meta_text, "0 0 0 4 5 6 0 0 0 0";
295 ok $seq->seq('aaatttc');
296 is $seq->meta_text, "0 0 0 4 5 6 0";
297 is $seq->meta_length, 7;
300 ok $seq = Bio::Seq::Quality->new( -seq => "AT-CGATCGA",
304 is join (' ', @{$seq->submeta(4, 6, '4 5 6')}), '4 5 6';
305 is $seq->meta_length, 6;
308 is $seq->meta_text, "0 0 0 4 5 6";
310 ok $seq->force_flush(1);
312 is $seq->meta_text, "0 0 0 4 5 6 0 0 0 0";
314 ok $seq->seq('aaatttc');
315 is $seq->meta_text, "0 0 0 4 5 6 0";
316 is $seq->meta_length, 7;
317 is $seq->trace_length, 7;
318 #is $seq->quality_length, 7;
320 is $seq->is_flush, 1;
321 is $seq->trace_is_flush, 1;
322 is $seq->quality_is_flush, 1;
324 # quality: trace_lengths, trace_is_flush, quality_is_flush