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) = @_;
135 open my $FH_IN, '<', $infile or die "Could not read file '$infile': $!\n";
136 $in .= $_ while (<$FH_IN>);
139 open my $FH_OUT, '<', $outfile or die "Could not read file '$outfile': $!\n";
140 $out .= $_ while (<$FH_OUT>);
142 print "|$in||$out|\n" if $DEBUG;
148 my $str = Bio::SeqIO->new
149 ( '-file'=> test_input_file('test.metafasta'),
150 '-format' => 'metafasta');
151 ok $seq = $str->next_seq;
153 my $outfile = test_output_file();
154 my $strout = Bio::SeqIO->new
155 ('-file'=> ">". $outfile,
156 '-format' => 'metafasta');
157 ok $strout->write_seq($seq);
159 diff (test_input_file('test.metafasta'),
165 $str = Bio::AlignIO->new
166 ( '-file'=> test_input_file('testaln.metafasta'),
167 '-format' => 'metafasta');
168 ok my $aln = $str->next_aln;
170 $outfile = test_output_file();
171 $strout = Bio::AlignIO->new
172 ('-file'=> ">". $outfile,
173 '-format' => 'metafasta');
174 ok $strout->write_aln($aln);
176 diff (test_input_file('testaln.metafasta'),
182 ### tests for Meta::Array
186 ok $seq = Bio::Seq::Meta::Array->new
193 # create a sequence object
194 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA",
200 is $seq->is_flush, 1;
201 #is $seq->meta_text, " ";
202 is $seq->meta_text, '0 0 0 0 0 0 0 0 0 0';
204 # create some random meta values, but not for the last residue
205 $metastring = "a a - b b 0 b b 0";
206 is join (' ', @{$seq->meta($metastring)}), $metastring. ' 0';
207 is $seq->meta_text, $metastring. ' 0';
209 # truncate the sequence by assignment
211 $seq->alphabet('dna');
212 is $seq->meta_text, 'a a - b b 0';
214 # truncate the sequence with trunc()
215 is $seq->strand(-1), -1;
216 ok $seq = $seq->trunc(1,5);
217 is $seq->seq, 'AT-CG';
218 is $seq->meta_text, 'a a - b b';
222 #is $seq->meta_length, 6;
223 #ok $seq->force_flush(1);
224 #is $seq->meta_length, 5;
227 ok $seq = $seq->revcom;
228 is $seq->seq, 'CG-AT';
229 is $seq->meta_text, 'b b - a a';
234 is $seq->subseq(2,4), 'G-A';
236 is $seq->submeta_text(2,4), 'b - a';
237 is $seq->submeta_text(2,undef, 'c - c'), 'c - c';
238 is $seq->submeta_text(2,4), 'c - c';
239 is $seq->meta_text, 'b c - c a';
241 is $seq->meta_text(''), '0 0 0 0 0';
242 is $seq->submeta_text(2,undef, 'c - c'), 'c - c';
243 is $seq->meta_text, '0 c - c 0';
245 # add named meta annotations
246 $first = '1 10 - 222 23';
247 is $seq->named_meta_text('first', $first), $first;
248 is $seq->named_meta_text('first'), $first;
249 $second = '[ [ - ] ]';
250 ok $seq->named_meta_text('second', $second);
252 # undefined range arguments
253 is $seq->named_submeta_text('second', 3, 4), '- ]';
254 is $seq->named_submeta_text('second', 3), '- ] ]';
255 is $seq->named_submeta_text('second'), '[ [ - ] ]';
257 @names = $seq->meta_names;
259 is $names[0], 'DEFAULT';
265 # testing the forcing of flushed meta values
271 ok $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA",
275 is $seq->submeta(4, 6, '456'), '456';
276 is $seq->meta_length, 6;
279 is $seq->meta, " 456";
281 ok $seq->force_flush(1);
282 is $seq->meta, " 456 ";
283 ok $seq->seq('aaatttc');
284 is $seq->meta, " 456 ";
286 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA",
290 is join (' ', @{$seq->submeta(4, 6, '4 5 6')}), '4 5 6';
291 is $seq->meta_length, 6;
294 is $seq->meta_text, "0 0 0 4 5 6";
295 ok $seq->force_flush(1);
296 is $seq->meta_text, "0 0 0 4 5 6 0 0 0 0";
298 ok $seq->seq('aaatttc');
299 is $seq->meta_text, "0 0 0 4 5 6 0";
300 is $seq->meta_length, 7;
303 ok $seq = Bio::Seq::Quality->new( -seq => "AT-CGATCGA",
307 is join (' ', @{$seq->submeta(4, 6, '4 5 6')}), '4 5 6';
308 is $seq->meta_length, 6;
311 is $seq->meta_text, "0 0 0 4 5 6";
313 ok $seq->force_flush(1);
315 is $seq->meta_text, "0 0 0 4 5 6 0 0 0 0";
317 ok $seq->seq('aaatttc');
318 is $seq->meta_text, "0 0 0 4 5 6 0";
319 is $seq->meta_length, 7;
320 is $seq->trace_length, 7;
321 #is $seq->quality_length, 7;
323 is $seq->is_flush, 1;
324 is $seq->trace_is_flush, 1;
325 is $seq->quality_is_flush, 1;
327 # quality: trace_lengths, trace_is_flush, quality_is_flush