1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 132);
11 use_ok('Bio::Seq::Meta');
12 use_ok('Bio::Seq::Meta::Array');
14 use_ok('Bio::AlignIO');
15 use_ok('Bio::Seq::Quality');
18 my $DEBUG = test_debug();
20 ok my $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA");
22 is $seq->revcom->seq, 'TCGATCG-AT';
24 ok $seq->force_flush(1);
26 $seq->seq("AT-CGATCGATT");
28 ok not $seq->force_flush(0);
30 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA");
32 is $seq->revcom->seq, 'TCGATCG-AT';
33 is $seq->meta_text, "";
34 ok $seq->force_flush(1);
35 $seq->seq("AT-CGATCGATT");
36 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0 0 0";
37 ok not $seq->force_flush(0);
39 ok $seq = Bio::Seq::Quality->new( -seq => "AT-CGATCGA");
40 is $seq->meta_text, "";
41 ok $seq->force_flush(1);
42 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0";
43 $seq->seq("AT-CGATCGATT");
44 is $seq->meta_text, "0 0 0 0 0 0 0 0 0 0 0 0";
45 ok not $seq->force_flush(0);
47 ok $seq = Bio::Seq::Meta->new
54 # create a sequence object
55 ok $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA",
62 is $seq->meta_length, 10;
64 # Create some random meta values, but gap in the wrong place
65 my $metastring = "a-abb bb ";
66 $seq->meta($metastring);
69 # create some random meta values, but not for the last residue
70 $metastring = "aa-bb bb";
71 ok $seq->meta($metastring), $metastring. " ";
73 # truncate the sequence by assignment
76 $seq->alphabet('dna');
77 is $seq->meta, 'aa-bb ';
82 # truncate the sequence with trunc()
83 is $seq->strand(-1), -1;
84 ok $seq = $seq->trunc(1,5);
87 is $seq->seq, 'AT-CG';
88 is $seq->meta, 'aa-bb';
92 ok $seq = $seq->revcom;
93 is $seq->seq, 'CG-AT';
94 is $seq->meta, 'bb-aa';
98 is $seq->subseq(2,4), 'G-A';
99 is $seq->submeta(2,4), 'b-a';
100 is $seq->submeta(2,undef, 'c-c'), 'c-ca';
101 is $seq->submeta(2,4), 'c-c';
102 is $seq->meta, 'bc-ca';
103 is $seq->meta(''), ' ';
104 is $seq->submeta(2,undef, 'c-c'), 'c-c ';
105 is $seq->meta, ' c-c ';
107 # add named meta annotations
110 is $seq->named_meta('first', $first), $first;
111 is $seq->named_meta('first'), $first;
113 my $second = '[[-]]';
114 ok $seq->named_meta('second', $second);
116 # undefined range arguments
117 is $seq->named_submeta('second', 3, 4), '-]';
118 is $seq->named_submeta('second', 3), '-]]';
119 is $seq->named_submeta('second'), '[[-]]';
121 my @names = $seq->meta_names;
123 is $names[0], 'DEFAULT';
132 my ($infile, $outfile) = @_;
134 open my $FH_IN, '<', $infile or die "Could not read file '$infile': $!\n";
135 $in .= $_ while (<$FH_IN>);
138 open my $FH_OUT, '<', $outfile or die "Could not read file '$outfile': $!\n";
139 $out .= $_ while (<$FH_OUT>);
141 print "|$in||$out|\n" if $DEBUG;
147 my $str = Bio::SeqIO->new
148 ( '-file'=> test_input_file('test.metafasta'),
149 '-format' => 'metafasta');
150 ok $seq = $str->next_seq;
152 my $outfile = test_output_file();
153 my $strout = Bio::SeqIO->new
154 ('-file'=> ">". $outfile,
155 '-format' => 'metafasta');
156 ok $strout->write_seq($seq);
158 diff (test_input_file('test.metafasta'),
164 $str = Bio::AlignIO->new
165 ( '-file'=> test_input_file('testaln.metafasta'),
166 '-format' => 'metafasta');
167 ok my $aln = $str->next_aln;
169 $outfile = test_output_file();
170 $strout = Bio::AlignIO->new
171 ('-file'=> ">". $outfile,
172 '-format' => 'metafasta');
173 ok $strout->write_aln($aln);
175 diff (test_input_file('testaln.metafasta'),
181 ### tests for Meta::Array
185 ok $seq = Bio::Seq::Meta::Array->new
192 # create a sequence object
193 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA",
199 is $seq->is_flush, 1;
200 #is $seq->meta_text, " ";
201 is $seq->meta_text, '0 0 0 0 0 0 0 0 0 0';
203 # create some random meta values, but not for the last residue
204 $metastring = "a a - b b 0 b b 0";
205 is join (' ', @{$seq->meta($metastring)}), $metastring. ' 0';
206 is $seq->meta_text, $metastring. ' 0';
208 # truncate the sequence by assignment
210 $seq->alphabet('dna');
211 is $seq->meta_text, 'a a - b b 0';
213 # truncate the sequence with trunc()
214 is $seq->strand(-1), -1;
215 ok $seq = $seq->trunc(1,5);
216 is $seq->seq, 'AT-CG';
217 is $seq->meta_text, 'a a - b b';
221 #is $seq->meta_length, 6;
222 #ok $seq->force_flush(1);
223 #is $seq->meta_length, 5;
226 ok $seq = $seq->revcom;
227 is $seq->seq, 'CG-AT';
228 is $seq->meta_text, 'b b - a a';
233 is $seq->subseq(2,4), 'G-A';
235 is $seq->submeta_text(2,4), 'b - a';
236 is $seq->submeta_text(2,undef, 'c - c'), 'c - c';
237 is $seq->submeta_text(2,4), 'c - c';
238 is $seq->meta_text, 'b c - c a';
240 is $seq->meta_text(''), '0 0 0 0 0';
241 is $seq->submeta_text(2,undef, 'c - c'), 'c - c';
242 is $seq->meta_text, '0 c - c 0';
244 # add named meta annotations
245 $first = '1 10 - 222 23';
246 is $seq->named_meta_text('first', $first), $first;
247 is $seq->named_meta_text('first'), $first;
248 $second = '[ [ - ] ]';
249 ok $seq->named_meta_text('second', $second);
251 # undefined range arguments
252 is $seq->named_submeta_text('second', 3, 4), '- ]';
253 is $seq->named_submeta_text('second', 3), '- ] ]';
254 is $seq->named_submeta_text('second'), '[ [ - ] ]';
256 @names = $seq->meta_names;
258 is $names[0], 'DEFAULT';
264 # testing the forcing of flushed meta values
270 ok $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA",
274 is $seq->submeta(4, 6, '456'), '456';
275 is $seq->meta_length, 6;
278 is $seq->meta, " 456";
280 ok $seq->force_flush(1);
281 is $seq->meta, " 456 ";
282 ok $seq->seq('aaatttc');
283 is $seq->meta, " 456 ";
285 ok $seq = Bio::Seq::Meta::Array->new( -seq => "AT-CGATCGA",
289 is join (' ', @{$seq->submeta(4, 6, '4 5 6')}), '4 5 6';
290 is $seq->meta_length, 6;
293 is $seq->meta_text, "0 0 0 4 5 6";
294 ok $seq->force_flush(1);
295 is $seq->meta_text, "0 0 0 4 5 6 0 0 0 0";
297 ok $seq->seq('aaatttc');
298 is $seq->meta_text, "0 0 0 4 5 6 0";
299 is $seq->meta_length, 7;
302 ok $seq = Bio::Seq::Quality->new( -seq => "AT-CGATCGA",
306 is join (' ', @{$seq->submeta(4, 6, '4 5 6')}), '4 5 6';
307 is $seq->meta_length, 6;
310 is $seq->meta_text, "0 0 0 4 5 6";
312 ok $seq->force_flush(1);
314 is $seq->meta_text, "0 0 0 4 5 6 0 0 0 0";
316 ok $seq->seq('aaatttc');
317 is $seq->meta_text, "0 0 0 4 5 6 0";
318 is $seq->meta_length, 7;
319 is $seq->trace_length, 7;
320 #is $seq->quality_length, 7;
322 is $seq->is_flush, 1;
323 is $seq->trace_is_flush, 1;
324 is $seq->quality_is_flush, 1;
326 # quality: trace_lengths, trace_is_flush, quality_is_flush