3 our $API_VERSION = qv
('1.1.6');
6 use File
::Path
qw(mkpath rmtree);
9 use lib
'.'; # for core package test scripts only
14 -requires_modules
=> [q
(Bio
::SeqIO
::msout
)],
15 -requires_networking
=> 0
18 use_ok
('Bio::SeqIO::msout');
22 # skip tests if the msout.pm module is too old.
23 my $api_version = $Bio::SeqIO
::msout
::API_VERSION
;
25 '>=', qv
('1.1.5'), "Bio::SeqIO::msout is at least api version 1.1.5" );
27 test_file_1
( 0, "msout/msout_infile1" );
28 test_file_2
( 0, "msout/msout_infile2" );
29 test_file_3
( 0, "msout/msout_infile3" );
31 # tests to run for api versions >= 1.1.6
33 skip q
($Bio::SeqIO
::msout
::API_VERSION
< 1.1.6) , 22 unless $api_version >= qv
('1.1.6');
34 test_file_4
( 0, q
(msout
/msout_infile4
) );
41 $dir = test_input_file
($dir);
52 $dir = test_input_file
($dir);
57 else { warn "Tried to remove $dir, but it does not exist" }
61 ##############################################################################
63 ##############################################################################
67 $infile = test_input_file
($infile);
69 #print_file1( $infile, $gzip );
71 my $file_sequence = $infile;
73 $file_sequence = "gunzip -c <$file_sequence |";
75 my $msout = Bio
::SeqIO
->new(
76 -file
=> "$file_sequence",
80 isa_ok
( $msout, 'Bio::SeqIO::msout' );
82 my $rh_base_conversion_table = $msout->get_base_conversion_table;
88 MS_INFO_LINE
=> 'ms 6 3 -s 7 -I 3 3 2 1',
92 LAST_READ_HAP_NUM
=> 0,
93 POSITIONS
=> [qw(79.1001 80.1001 81.101 82.101 83.10001 84.801 85)],
94 CURRENT_RUN_SEGSITES
=> 7
97 foreach my $attribute ( keys %attributes ) {
98 my $func = lc($attribute);
100 if ( $attribute =~ m/POPS|SEEDS|POSITIONS/ ) {
101 $func = ucfirst($func);
104 $func = 'get_' . $func;
105 my @returns = $msout->$func();
106 my ( $return, $got );
108 # If there were more than one return value, then compare references to
109 # arrays instead of scalars
110 unless ( @returns > 1 ) {
111 $got = shift @returns;
113 else { $got = \
@returns }
115 my $expected = $attributes{$attribute};
117 if ( defined $got && defined $expected ) {
118 is_deeply
( $got, $expected, "Get $attribute" );
120 else { is_deeply
( $got, $expected, "Get $attribute" ) }
123 # Testing next_hap at beginning of run
125 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_seq );
126 my @data_expected = qw(1111111);
127 is_deeply
( \
@data_got, \
@data_expected,
128 "Get next_hap at beginning of run" );
130 # Testing next_hap after beginning of run
132 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_seq );
133 @data_expected = qw(5555555);
134 is_deeply
( \
@data_got, \
@data_expected,
135 "Get next_hap after beginning of run" );
137 # Surprise test! testing msout::outgroup
138 my $outgroup = $msout->outgroup;
139 is
( $outgroup, 1, "Testing msout::outgroup" );
141 # Testing next_pop after beginning of pop
143 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
144 @data_expected = qw(4444444);
145 is_deeply
( \
@data_got, \
@data_expected,
146 "Get next_pop after beginning of pop" );
148 # Testing next_pop at beginning of pop
150 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
151 @data_expected = qw(4444444 5555555);
152 is_deeply
( \
@data_got, \
@data_expected,
153 "Get next_pop at beginning of pop" );
155 # Testing next_run after beginning of run
157 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_run );
158 @data_expected = qw(4444444);
159 is_deeply
( \
@data_got, \
@data_expected,
160 "Get next_run after beginning of run" );
162 # Testing next_pop at beginning of run
164 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
165 @data_expected = qw(5555555 5555555 5555555);
166 is_deeply
( \
@data_got, \
@data_expected,
167 "Get next_pop at beginning of run" );
169 # Testing next_hap after pop
170 @data_got = $msout->get_next_hap;
171 @data_expected = qw(1010101);
172 is_deeply
( \
@data_got, \
@data_expected, "Get next_hap after pop" );
174 # Testing next_run after pop and hap
176 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_run );
177 @data_expected = qw(1111111 1515151);
178 is_deeply
( \
@data_got, \
@data_expected, "Get next_run after pop and hap" );
180 # Testing next_run at beginning of run
182 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_run );
190 is_deeply
( \
@data_got, \
@data_expected,
191 "Get next_run at beginning of run" );
193 is
( $msout->get_next_run_num, undef, 'have all lines been read?' );
197 ##############################################################################
199 ##############################################################################
203 $infile = test_input_file
($infile);
205 #print_file2( $infile, $gzip );
207 my $file_sequence = $infile;
209 $file_sequence = "gunzip -c <$file_sequence |";
212 my $msout = Bio
::SeqIO
->new(
213 -file
=> "$file_sequence",
217 isa_ok
( $msout, 'Bio::SeqIO::msout' );
222 SEEDS
=> [qw(1 1 1)],
223 MS_INFO_LINE
=> 'ms 6 3',
227 LAST_READ_HAP_NUM
=> 0,
228 POSITIONS
=> [qw(79.1001 80.1001 81.101 82.101 83.10001 84.801 85)],
229 CURRENT_RUN_SEGSITES
=> 7
232 foreach my $attribute ( keys %attributes ) {
233 my $func = lc($attribute);
235 if ( $attribute =~ m/POPS|SEEDS|POSITIONS/ ) {
236 $func = ucfirst($func);
239 $func = 'get_' . $func;
240 my @returns = $msout->$func();
241 my ( $return, $got );
243 # If there were more than one return value, then compare references to
244 # arrays instead of scalars
245 unless ( @returns > 1 ) {
246 $got = shift @returns;
248 else { $got = \
@returns }
250 my $expected = $attributes{$attribute};
252 if ( defined $got && defined $expected ) {
253 is_deeply
( $got, $expected, "Get $attribute" );
255 else { is_deeply
( $got, $expected, "Get $attribute" ) }
258 my $rh_base_conversion_table = $msout->get_base_conversion_table;
260 # Testing next_hap at beginning of run
261 my @data_got = $msout->get_next_hap;
262 my @data_expected = '1111111';
263 is_deeply
( \
@data_got, \
@data_expected,
264 "Get next_hap at beginning of run" );
266 # Testing next_hap after beginning of run
268 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_seq );
269 @data_expected = '5555555';
270 is_deeply
( \
@data_got, \
@data_expected,
271 "Get next_hap after beginning of run" );
273 # Surprise test! testing msout::outgroup
274 my $outgroup = $msout->outgroup;
275 is
( $outgroup, 0, "Testing msout::outgroup" );
277 # Testing next_pop after beginning of pop
279 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
285 is_deeply
( \
@data_got, \
@data_expected,
286 "Get next_pop after beginning of pop" );
288 # Testing next_pop at beginning of pop/run
290 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
298 is_deeply
( \
@data_got, \
@data_expected,
299 "Get next_pop at beginning of pop/run" );
301 # Testing next_run at beginning of run
303 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_run );
311 is_deeply
( \
@data_got, \
@data_expected,
312 "Get next_run at beginning of run" );
314 # Testing next_hap at beginning of run 2
316 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_seq );
317 @data_expected = '1515151';
318 is_deeply
( \
@data_got, \
@data_expected,
319 "Get next_hap at beginning of run 2" );
321 # Testing next_run after hap
323 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_run );
330 is_deeply
( \
@data_got, \
@data_expected, "Get next_run after hap" );
332 is
( $msout->get_next_run_num, 5, 'next run should be 5.' );
334 # getting the last hap of the file via next hap
335 # Testing next_run after hap
336 @data_got = $msout->get_next_hap;
337 @data_expected = qw( 5555555 );
338 is_deeply
( \
@data_got, \
@data_expected, "Get last hap through next_hap" );
343 ##############################################################################
345 ##############################################################################
349 $infile = test_input_file
($infile);
351 #print_file3( $infile, $gzip );
353 my $file_sequence = $infile;
355 $file_sequence = "gunzip -c <$file_sequence |";
357 my $msout = Bio
::SeqIO
->new(
358 -file
=> "$file_sequence",
362 isa_ok
( $msout, 'Bio::SeqIO::msout' );
364 my $rh_base_conversion_table = $msout->get_base_conversion_table;
366 isa_ok
( $msout, 'Bio::SeqIO::msout' );
371 SEEDS
=> [qw(1 1 1)],
372 MS_INFO_LINE
=> 'ms 3 1',
376 LAST_READ_HAP_NUM
=> 0,
377 POSITIONS
=> [qw(79.1001 80.1001 81.101 82.101 83.10001 84.801 85)],
378 CURRENT_RUN_SEGSITES
=> 7
381 foreach my $attribute ( keys %attributes ) {
382 my $func = lc($attribute);
384 if ( $attribute =~ m/POPS|SEEDS|POSITIONS/ ) {
385 $func = ucfirst($func);
388 $func = 'get_' . $func;
389 my @returns = $msout->$func();
390 my ( $return, $got );
392 # If there were more than one return value, then compare references to
393 # arrays instead of scalars
394 unless ( @returns > 1 ) {
395 $got = shift @returns;
397 else { $got = \
@returns }
399 my $expected = $attributes{$attribute};
401 if ( defined $got && defined $expected ) {
402 is_deeply
( $got, $expected, "Get $attribute" );
404 else { is_deeply
( $got, $expected, "Get $attribute" ) }
407 # Testing next_hap at beginning of run
409 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
410 my @data_expected = qw(1111111 5555555 4444444);
411 is_deeply
( \
@data_got, \
@data_expected, "Get next_pop at end of run" );
413 is
( $msout->get_next_run_num, undef, 'have all lines been read?' );
415 # Testing what happens when we read from empty stream
416 @data_got = $msout->get_next_pop;
418 is_deeply
( \
@data_got, \
@data_expected, "Get next_pop at eof" );
420 # Testing what happens when we read from empty stream
421 @data_got = $msout->get_next_run;
423 is_deeply
( \
@data_got, \
@data_expected, "Get next_run at eof" );
425 # Testing what happens when we read from empty stream
426 @data_got = $msout->get_next_hap;
427 @data_expected = undef;
428 is_deeply
( \
@data_got, \
@data_expected, "Get next_hap at eof" );
430 # Testing what happens when we read from empty stream
431 @data_got = $msout->get_next_seq;
433 is_deeply
( \
@data_got, \
@data_expected, "Get next_seq at eof" );
438 ##############################################################################
440 ##############################################################################
442 # All this does is test to see if Bio::SeqIO::msout can handle ms output files
443 # with multiple newline characters randomly interspersed in the file.
447 $infile = test_input_file
($infile);
449 #print_file4( $infile, $gzip );
451 my $file_sequence = $infile;
453 $file_sequence = "gunzip -c <$file_sequence |";
455 my $msout = Bio
::SeqIO
->new(
456 -file
=> "$file_sequence",
460 isa_ok
( $msout, 'Bio::SeqIO::msout' );
462 my $rh_base_conversion_table = $msout->get_base_conversion_table;
467 SEEDS
=> [qw(1 1 1)],
468 MS_INFO_LINE
=> 'ms 6 3 -s 7 -I 3 3 2 1',
472 LAST_READ_HAP_NUM
=> 0,
473 POSITIONS
=> [qw(79.1001 80.1001 81.101 82.101 83.10001 84.801 85)],
474 CURRENT_RUN_SEGSITES
=> 7
477 foreach my $attribute ( keys %attributes ) {
478 my $func = lc($attribute);
480 if ( $attribute =~ m/POPS|SEEDS|POSITIONS/ ) {
481 $func = ucfirst($func);
484 $func = 'get_' . $func;
485 my @returns = $msout->$func();
486 my ( $return, $got );
488 # If there were more than one return value, then compare references to
489 # arrays instead of scalars
490 unless ( @returns > 1 ) {
491 $got = shift @returns;
493 else { $got = \
@returns }
495 my $expected = $attributes{$attribute};
497 if ( defined $got && defined $expected ) {
498 is_deeply
( $got, $expected, "Get $attribute" );
500 else { is_deeply
( $got, $expected, "Get $attribute" ) }
503 # Testing next_hap at beginning of run
505 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_seq );
506 my @data_expected = qw(1111111);
507 is_deeply
( \
@data_got, \
@data_expected,
508 "Get next_hap at beginning of run" );
510 # Testing next_hap after beginning of run
512 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_seq );
513 @data_expected = qw(5555555);
514 is_deeply
( \
@data_got, \
@data_expected,
515 "Get next_hap after beginning of run" );
517 # Surprise test! testing msout::outgroup
518 my $outgroup = $msout->outgroup;
519 is
( $outgroup, 1, "Testing msout::outgroup" );
521 # Testing next_pop after beginning of pop
523 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
524 @data_expected = qw(4444444);
525 is_deeply
( \
@data_got, \
@data_expected,
526 "Get next_pop after beginning of pop" );
528 # Testing next_pop at beginning of pop
530 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
531 @data_expected = qw(4444444 5555555);
532 is_deeply
( \
@data_got, \
@data_expected,
533 "Get next_pop at beginning of pop" );
535 # Testing next_run after beginning of run
537 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_run );
538 @data_expected = qw(4444444);
539 is_deeply
( \
@data_got, \
@data_expected,
540 "Get next_run after beginning of run" );
542 # Testing next_pop at beginning of run
544 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_pop );
545 @data_expected = qw(5555555 5555555 5555555);
546 is_deeply
( \
@data_got, \
@data_expected,
547 "Get next_pop at beginning of run" );
549 # Testing next_hap after pop
550 @data_got = $msout->get_next_hap;
551 @data_expected = qw(1010101);
552 is_deeply
( \
@data_got, \
@data_expected, "Get next_hap after pop" );
554 # Testing next_run after pop and hap
556 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_run );
557 @data_expected = qw(1111111 1515151);
558 is_deeply
( \
@data_got, \
@data_expected, "Get next_run after pop and hap" );
560 # Testing next_run at beginning of run
562 convert_bases_to_nums
( $rh_base_conversion_table, $msout->get_next_run );
570 is_deeply
( \
@data_got, \
@data_expected,
571 "Get next_run at beginning of run" );
573 is
( $msout->get_next_run_num, undef, 'have all lines been read?' );
578 my $destination = shift;
582 ms 6 3 -s 7 -I 3 3 2 1
587 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
596 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
605 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
618 else { $gzip = ' '; }
619 open OUT
, "$gzip >$destination" or die "Unable to open $destination\n";
627 my $destination = shift;
636 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
645 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
654 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
663 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
672 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
680 else { $gzip = ' '; }
682 open OUT
, "$gzip >$destination" or die "Unable to open $destination\n";
690 my $destination = shift;
699 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
708 else { $gzip = ' '; }
710 open OUT
, "$gzip >$destination" or die "Unable to open $destination\n";
718 my $destination = shift;
726 ms 6 3 -s 7 -I 3 3 2 1
737 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
755 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
771 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
790 else { $gzip = ' '; }
791 open OUT
, "$gzip >$destination" or die "Unable to open $destination\n";
799 my ( $ra_in, $out ) = @_;
800 unless ( open OUT
, ">$out" ) {
801 die "\nCould not open outfile $out!!\n\n";
803 print OUT
("@$ra_in");
807 sub convert_bases_to_nums
{
809 my ( $rh_base_conversion_table, @seqs ) = @_;
812 foreach my $seq (@seqs) {
813 my $seqstring = $seq->seq;
814 foreach my $base ( keys %{$rh_base_conversion_table} ) {
815 $seqstring =~ s/($base)/$rh_base_conversion_table->{$base}/g;
817 push @out_seqstrings, $seqstring;
820 return @out_seqstrings;