22
21
# skip tests if the msout.pm module is too old.
23
22
my $api_version = $Bio::SeqIO::msout::API_VERSION;
25
'>=', qv('1.1.5'), "Bio::SeqIO::msout is at least api version 1.1.5" );
23
cmp_ok( $api_version, '>=', qv('1.1.5'),
24
"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" );
26
test_file_1( 0, "msout/msout_infile1" ); # 23 tests
27
test_file_2( 0, "msout/msout_infile2" ); # 22 tests
28
test_file_3( 0, "msout/msout_infile3" ); # 17 tests
31
30
# 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) );
32
skip q($Bio::SeqIO::msout::API_VERSION < 1.1.6), 22
33
unless $api_version >= qv('1.1.6');
34
test_file_1( 0, q(msout/msout_infile4) );
37
# tests to run for api versions >= 1.1.7
39
skip q($Bio::SeqIO::msout::API_VERSION < 1.1.7), 4
40
unless $api_version >= qv('1.1.7');
41
bad_test_file_1( 0, q(msout/bad_msout_infile1) ); # 2 tests
42
bad_test_file_2( 0, q(msout/bad_msout_infile2) ); # 2 tests
45
# tests to run for api version >= 1.1.8
47
skip q($Bio::SeqIO::msout::API_VERSION < 1.1.8), 75
48
unless $api_version >= qv('1.1.8');
50
test_file_1( 0, "msout/msout_infile1", 100 );
51
test_file_2( 0, "msout/msout_infile2", 10 );
52
test_file_1( 0, q(msout/msout_infile4), 100 );
53
bad_test_file_1( 0, q(msout/bad_msout_infile1), 1000 );
54
bad_test_file_2( 0, q(msout/bad_msout_infile2), 1000 );
55
bad_n_sites( 0, q(msout/msout_infile1) ); # 2 tests
41
$dir = test_input_file($dir);
62
$dir = Bio::Root::Test::test_input_file($dir);
43
64
unless ( -d $dir ) {
141
179
# Testing next_pop after beginning of pop
143
181
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_pop );
144
@data_expected = qw(4444444);
182
if ( !defined($n_sites) ) {
183
@data_expected = qw(4444444);
187
qw(4000000000000000000000004000004000400000000000000000000000000000000400000004000000004000000000000000);
145
189
is_deeply( \@data_got, \@data_expected,
146
190
"Get next_pop after beginning of pop" );
148
192
# Testing next_pop at beginning of pop
150
194
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_pop );
151
@data_expected = qw(4444444 5555555);
195
if ( !defined($n_sites) ) {
196
@data_expected = qw(4444444 5555555);
200
qw(4000000000000000000000004000004000400000000000000000000000000000000400000004000000004000000000000000 5000000000000000000000005000005000500000000000000000000000000000000500000005000000005000000000000000);
152
202
is_deeply( \@data_got, \@data_expected,
153
203
"Get next_pop at beginning of pop" );
155
205
# Testing next_run after beginning of run
157
207
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_run );
158
@data_expected = qw(4444444);
208
if ( !defined($n_sites) ) {
209
@data_expected = qw(4444444);
213
qw(4000000000000000000000004000004000400000000000000000000000000000000400000004000000004000000000000000);
159
215
is_deeply( \@data_got, \@data_expected,
160
216
"Get next_run after beginning of run" );
162
218
# Testing next_pop at beginning of run
164
220
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_pop );
165
@data_expected = qw(5555555 5555555 5555555);
221
if ( !defined($n_sites) ) {
222
@data_expected = qw(5555555 5555555 5555555);
226
qw(5000000000000000000000005000005000500000000000000000000000000000000500000005000000005000000000000000 5000000000000000000000005000005000500000000000000000000000000000000500000005000000005000000000000000 5000000000000000000000005000005000500000000000000000000000000000000500000005000000005000000000000000);
166
228
is_deeply( \@data_got, \@data_expected,
167
229
"Get next_pop at beginning of run" );
199
267
##############################################################################
203
$infile = test_input_file($infile);
272
$infile = Bio::Root::Test::test_input_file($infile);
205
#print_file2( $infile, $gzip );
274
# the files are now part of the git repo and don't have to be printed
275
# print_file2( $infile, $gzip );
207
277
my $file_sequence = $infile;
209
$file_sequence = "gunzip -c <$file_sequence |";
279
$file_sequence = "gzip -dc <$file_sequence |";
212
282
my $msout = Bio::SeqIO->new(
213
-file => "$file_sequence",
283
-file => "$file_sequence",
285
-n_sites => $n_sites,
217
288
isa_ok( $msout, 'Bio::SeqIO::msout' );
219
290
my %attributes = (
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)],
294
SEEDS => [qw(1 1 1)],
295
MS_INFO_LINE => 'ms 6 3',
299
LAST_READ_HAP_NUM => 0,
300
POSITIONS => [qw(0.01 0.25 0.31 0.35 0.68 0.76 0.85)],
229
301
CURRENT_RUN_SEGSITES => 7
277
354
# Testing next_pop after beginning of pop
279
356
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_pop );
357
if ( !defined($n_sites) ) {
358
@data_expected = qw(4444444 4444444 5555555 4444444);
361
@data_expected = qw(4444044400 4444044400 5555055500 4444044400);
285
363
is_deeply( \@data_got, \@data_expected,
286
364
"Get next_pop after beginning of pop" );
288
366
# Testing next_pop at beginning of pop/run
290
368
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_pop );
369
if ( !defined($n_sites) ) {
370
@data_expected = qw(5555555 5555555 5555555 1010101 1111111 1515151);
374
qw(5555055500 5555055500 5555055500 1010010100 1111011100 1515015100);
298
376
is_deeply( \@data_got, \@data_expected,
299
377
"Get next_pop at beginning of pop/run" );
301
379
# Testing next_run at beginning of run
303
381
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_run );
382
if ( !defined($n_sites) ) {
383
@data_expected = qw(1414141 1414141 1515151 1414141 1515151 1515151);
387
qw(1414014100 1414014100 1515015100 1414014100 1515015100 1515015100);
311
389
is_deeply( \@data_got, \@data_expected,
312
390
"Get next_run at beginning of run" );
314
392
# Testing next_hap at beginning of run 2
316
394
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_seq );
317
@data_expected = '1515151';
395
if ( !defined($n_sites) ) {
396
@data_expected = '1515151';
399
@data_expected = '1515015100';
318
401
is_deeply( \@data_got, \@data_expected,
319
402
"Get next_hap at beginning of run 2" );
321
404
# Testing next_run after hap
323
406
convert_bases_to_nums( $rh_base_conversion_table, $msout->get_next_run );
407
if ( !defined($n_sites) ) {
408
@data_expected = qw(5050505 5151515 5555555 5454545 5454545);
412
qw(5050050500 5151051500 5555055500 5454054500 5454054500);
330
414
is_deeply( \@data_got, \@data_expected, "Get next_run after hap" );
332
416
is( $msout->get_next_run_num, 5, 'next run should be 5.' );
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";
798
520
sub print_to_file {
799
521
my ( $ra_in, $out ) = @_;
800
522
unless ( open OUT, ">$out" ) {
820
542
return @out_seqstrings;
546
sub bad_test_file_1 {
547
##############################################################################
549
##############################################################################
551
# This sub tests to see if msout.pm will catch if the msinfo line's
552
# advertized haps are less than are actually in the file
557
$infile = test_input_file($infile);
559
my $file_sequence = $infile;
561
$file_sequence = "gunzip -c <$file_sequence |";
563
my $msout = Bio::SeqIO->new(
564
-file => "$file_sequence",
566
-n_sites => $n_sites,
569
isa_ok( $msout, 'Bio::SeqIO::msout' );
571
throws_ok { $msout->get_next_run }
572
qr/msout file has only 2 hap\(s\), which is less than indicated in msinfo line \( 9 \)/,
573
q(Caught error in bad msout file 1);
577
sub bad_test_file_2 {
578
##############################################################################
580
##############################################################################
582
# This sub tests to see if msout.pm will catch if the msinfo line's
583
# advertized haps are more than are actually in the file
588
$infile = test_input_file($infile);
590
my $file_sequence = $infile;
592
$file_sequence = "gunzip -c <$file_sequence |";
594
my $msout = Bio::SeqIO->new(
595
-file => "$file_sequence",
597
-n_sites => $n_sites,
600
isa_ok( $msout, 'Bio::SeqIO::msout' );
602
throws_ok { $msout->get_next_run }
603
qr/\'\/\/\' not encountered when expected. There are more haplos in one of the msOUT runs than advertised in the msinfo line/,
604
q(Caught error in bad msout file 2);
609
##############################################################################
611
##############################################################################
613
# this sub tests if msout.pm dies when n_sites is smaller than segsites
616
$infile = Bio::Root::Test::test_input_file($infile);
618
my $file_sequence = $infile;
620
$file_sequence = "gzip -dc <$file_sequence |";
622
my $msout = Bio::SeqIO->new(
623
-file => "$file_sequence",
628
throws_ok { $msout->set_n_sites(-1) } qr|first argument needs to be a positive integer. argument supplied: -1|;
630
# test nsites smaller than next hap
631
$msout->set_n_sites(1);
632
throws_ok{$msout->get_next_seq} qr/n_sites needs to be at least the number of segsites of every run/, 'too few n_sites failed OK';