1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 132);
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 is $seq->revcom->seq, 'TCGATCG-AT';
25 ok $seq->force_flush(1);
27 $seq->seq("AT-CGATCGATT");
29 ok not $seq->force_flush(0);
31 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA");
33 is $seq->revcom->seq, 'TCGATCG-AT';
34 is $seq->meta_text, "";
35 ok $seq->force_flush(1);
36 $seq->seq("AT-CGATCGATT");
37 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0 0 0";
38 ok not $seq->force_flush(0);
40 ok $seq = Bio::Seq::Quality->new( -seq => "AT-CGATCGA");
41 is $seq->meta_text, "";
42 ok $seq->force_flush(1);
43 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0";
44 $seq->seq("AT-CGATCGATT");
45 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0 0 0";
46 ok not $seq->force_flush(0);
48 ok $seq = Bio::Seq::Meta->new
55 # create a sequence object
56 ok $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA",
63 is $seq->meta_length, 10;
65 # Create some random meta values, but gap in the wrong place
66 my $metastring = "a-abb bb ";
67 $seq->meta($metastring);
70 # create some random meta values, but not for the last residue
71 $metastring = "aa-bb bb";
72 ok $seq->meta($metastring), $metastring. " ";
74 # truncate the sequence by assignment
77 $seq->alphabet('dna');
78 is $seq->meta, 'aa-bb ';
83 # truncate the sequence with trunc()
84 is $seq->strand(-1), -1;
85 ok $seq = $seq->trunc(1,5);
88 is $seq->seq, 'AT-CG';
89 is $seq->meta, 'aa-bb';
93 ok $seq = $seq->revcom;
94 is $seq->seq, 'CG-AT';
95 is $seq->meta, 'bb-aa';
99 is $seq->subseq(2,4), 'G-A';
100 is $seq->submeta(2,4), 'b-a';
101 is $seq->submeta(2,undef, 'c-c'), 'c-ca';
102 is $seq->submeta(2,4), 'c-c';
103 is $seq->meta, 'bc-ca';
104 is $seq->meta(''), ' ';
105 is $seq->submeta(2,undef, 'c-c'), 'c-c ';
106 is $seq->meta, ' c-c ';
108 # add named meta annotations
111 is $seq->named_meta('first', $first), $first;
112 is $seq->named_meta('first'), $first;
114 my $second = '[[-]]';
115 ok $seq->named_meta('second', $second);
117 # undefined range arguments
118 is $seq->named_submeta('second', 3, 4), '-]';
119 is $seq->named_submeta('second', 3), '-]]';
120 is $seq->named_submeta('second'), '[[-]]';
122 my @names = $seq->meta_names;
124 is $names[0], 'DEFAULT';
133 my ($infile, $outfile) = @_;
136 $in .= $_ while (<FH>);
140 $out .= $_ while (<FH>);
142 print "|$in||$out|\n" if $DEBUG;
149 my $str = Bio::SeqIO->new
150 ( '-file'=> test_input_file('test.metafasta'),
151 '-format' => 'metafasta');
152 ok $seq = $str->next_seq;
154 my $outfile = test_output_file();
155 my $strout = Bio::SeqIO->new
156 ('-file'=> ">". $outfile,
157 '-format' => 'metafasta');
158 ok $strout->write_seq($seq);
160 diff (test_input_file('test.metafasta'),
166 $str = Bio::AlignIO->new
167 ( '-file'=> test_input_file('testaln.metafasta'),
168 '-format' => 'metafasta');
169 ok my $aln = $str->next_aln;
171 $outfile = test_output_file();
172 $strout = Bio::AlignIO->new
173 ('-file'=> ">". $outfile,
174 '-format' => 'metafasta');
175 ok $strout->write_aln($aln);
177 diff (test_input_file('testaln.metafasta'),
183 ### tests for Meta::Array
187 ok $seq = Bio::Seq::Meta::Array->new
194 # create a sequence object
195 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA",
201 is $seq->is_flush, 1;
202 #is $seq->meta_text, " ";
203 is $seq->meta_text, '0 0 0 0 0 0 0 0 0 0';
205 # create some random meta values, but not for the last residue
206 $metastring = "a a - b b 0 b b 0";
207 is join (' ', @{$seq->meta($metastring)}), $metastring. ' 0';
208 is $seq->meta_text, $metastring. ' 0';
210 # truncate the sequence by assignment
212 $seq->alphabet('dna');
213 is $seq->meta_text, 'a a - b b 0';
215 # truncate the sequence with trunc()
216 is $seq->strand(-1), -1;
217 ok $seq = $seq->trunc(1,5);
218 is $seq->seq, 'AT-CG';
219 is $seq->meta_text, 'a a - b b';
223 #is $seq->meta_length, 6;
224 #ok $seq->force_flush(1);
225 #is $seq->meta_length, 5;
228 ok $seq = $seq->revcom;
229 is $seq->seq, 'CG-AT';
230 is $seq->meta_text, 'b b - a a';
235 is $seq->subseq(2,4), 'G-A';
237 is $seq->submeta_text(2,4), 'b - a';
238 is $seq->submeta_text(2,undef, 'c - c'), 'c - c';
239 is $seq->submeta_text(2,4), 'c - c';
240 is $seq->meta_text, 'b c - c a';
242 is $seq->meta_text(''), '0 0 0 0 0';
243 is $seq->submeta_text(2,undef, 'c - c'), 'c - c';
244 is $seq->meta_text, '0 c - c 0';
246 # add named meta annotations
247 $first = '1 10 - 222 23';
248 is $seq->named_meta_text('first', $first), $first;
249 is $seq->named_meta_text('first'), $first;
250 $second = '[ [ - ] ]';
251 ok $seq->named_meta_text('second', $second);
253 # undefined range arguments
254 is $seq->named_submeta_text('second', 3, 4), '- ]';
255 is $seq->named_submeta_text('second', 3), '- ] ]';
256 is $seq->named_submeta_text('second'), '[ [ - ] ]';
258 @names = $seq->meta_names;
260 is $names[0], 'DEFAULT';
266 # testing the forcing of flushed meta values
272 ok $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA",
276 is $seq->submeta(4, 6, '456'), '456';
277 is $seq->meta_length, 6;
280 is $seq->meta, " 456";
282 ok $seq->force_flush(1);
283 is $seq->meta, " 456 ";
284 ok $seq->seq('aaatttc');
285 is $seq->meta, " 456 ";
287 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA",
291 is join (' ', @{$seq->submeta(4, 6, '4 5 6')}), '4 5 6';
292 is $seq->meta_length, 6;
295 is $seq->meta_text, "0 0 0 4 5 6";
296 ok $seq->force_flush(1);
297 is $seq->meta_text, "0 0 0 4 5 6 0 0 0 0";
299 ok $seq->seq('aaatttc');
300 is $seq->meta_text, "0 0 0 4 5 6 0";
301 is $seq->meta_length, 7;
304 ok $seq = Bio::Seq::Quality->new( -seq => "AT-CGATCGA",
308 is join (' ', @{$seq->submeta(4, 6, '4 5 6')}), '4 5 6';
309 is $seq->meta_length, 6;
312 is $seq->meta_text, "0 0 0 4 5 6";
314 ok $seq->force_flush(1);
316 is $seq->meta_text, "0 0 0 4 5 6 0 0 0 0";
318 ok $seq->seq('aaatttc');
319 is $seq->meta_text, "0 0 0 4 5 6 0";
320 is $seq->meta_length, 7;
321 is $seq->trace_length, 7;
322 #is $seq->quality_length, 7;
324 is $seq->is_flush, 1;
325 is $seq->trace_is_flush, 1;
326 is $seq->quality_is_flush, 1;
328 # quality: trace_lengths, trace_is_flush, quality_is_flush