3 our $API_VERSION = qv
('1.1.3');
6 use File
::Path
qw(mkpath rmtree);
14 -requires_modules
=> [q
(Bio
::SeqIO
::mbsout
)],
15 -requires_networking
=> 0
18 use_ok
('Bio::SeqIO::mbsout');
21 # skip tests if the msout.pm module is too old.
22 cmp_ok
( $Bio::SeqIO
::mbsout
::API_VERSION
,
23 '>=', qv
('1.1.3'), "Bio::SeqIO::mbsout is at least api version 1.1.3" );
26 test_file_1
( 0, "mbsout/mbsout_infile1" );
27 test_file_2
( 0, "mbsout/mbsout_infile2" );
28 test_file_3
( 0, "mbsout/mbsout_infile3" );
34 $dir = test_input_file
($dir);
42 ##############################################################################
44 ##############################################################################
48 $infile = test_input_file
($infile);
50 #print_file1( $infile, $gzip );
52 my $file_sequence = $infile;
54 $file_sequence = "gunzip -c <$file_sequence |";
56 my $mbsout = Bio
::SeqIO
->new(
57 -file
=> "$file_sequence",
61 isa_ok
( $mbsout, 'Bio::SeqIO::mbsout' );
63 my $rh_base_conversion_table = $mbsout->get_base_conversion_table;
65 isa_ok
( $mbsout, 'Bio::SeqIO::mbsout' );
71 'command: mbs 6 -t 0.001 -r 0.00025 -s 5000 2500 -f 3 1 traj ',
74 LAST_READ_HAP_NUM
=> 0,
75 POSITIONS
=> [qw(79.1001 80.1001 81.101 82.101 83.10001 84.801 85)],
76 CURRENT_RUN_SEGSITES
=> 7,
77 POP_MUT_PARAM_PER_SITE
=> 0.001,
78 POP_RECOMB_PARAM_PER_SITE
=> 0.00025,
83 TRAJ_FILENAME
=> 'traj'
86 foreach my $attribute ( keys %attributes ) {
87 my $func = lc($attribute);
89 if ( $attribute =~ m/POPS|SEEDS|POSITIONS/ ) {
90 $func = ucfirst($func);
93 $func = 'get_' . $func;
94 my @returns = $mbsout->$func();
97 # If there were more than one return value, then compare references to
98 # arrays instead of scalars
99 unless ( @returns > 1 ) {
100 $got = shift @returns;
102 else { $got = \
@returns }
104 my $expected = $attributes{$attribute};
106 if ( defined $got && defined $expected ) {
107 is_deeply
( $got, $expected, "Get $attribute" );
109 else { is_deeply
( $got, $expected, "Get $attribute" ) }
112 # Testing next_hap at beginning of run
114 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_seq );
115 my @data_expected = qw(1111111);
116 is_deeply
( \
@data_got, \
@data_expected,
117 "Get next_hap at beginning of run" );
119 # Testing next_hap after beginning of run
121 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_seq );
122 @data_expected = qw(5555555);
123 is_deeply
( \
@data_got, \
@data_expected,
124 "Get next_hap after beginning of run" );
126 # Testing next_pop after beginning of pop
128 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_seq );
129 @data_expected = qw(4444444);
130 is_deeply
( \
@data_got, \
@data_expected,
131 "Get next_pop after beginning of pop" );
134 @data_got = $mbsout->get_next_hap;
135 @data_expected = qw(4444444);
136 is_deeply
( \
@data_got, \
@data_expected, "Get next_hap" );
139 @data_got = $mbsout->get_next_hap;
140 @data_expected = qw(5555555);
141 is_deeply
( \
@data_got, \
@data_expected, "Get next_hap" );
143 # Testing next_run after beginning of run
145 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_run );
146 @data_expected = qw(4444444);
147 is_deeply
( \
@data_got, \
@data_expected,
148 "Get next_run after beginning of run" );
150 # Testing next_run at beginning of run
152 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_run );
153 @data_expected = qw(5555555 5555555 5555555 1010101 1111111 1515151);
154 is_deeply
( \
@data_got, \
@data_expected,
155 "Get next_run at beginning of run" );
157 # Testing next_run at beginning of run
159 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_run );
167 is_deeply
( \
@data_got, \
@data_expected,
168 "Get next_run at beginning of run" );
170 is
( $mbsout->get_next_run_num, undef, 'have all lines been read?' );
174 ##############################################################################
176 ##############################################################################
180 $infile = test_input_file
($infile);
182 #print_file2( $infile, $gzip );
184 my $file_sequence = $infile;
186 $file_sequence = "gunzip -c <$file_sequence |";
189 my $mbsout = Bio
::SeqIO
->new(
190 -file
=> "$file_sequence",
194 isa_ok
( $mbsout, 'Bio::SeqIO::mbsout' );
200 'command: mbs 6 -t 0.001 -r 0.00025 -s 5000 2500 -f 5 1 traj ',
203 LAST_READ_HAP_NUM
=> 0,
204 POSITIONS
=> [qw(79.1001 80.1001 81.101 82.101 83.10001 84.801 85)],
205 CURRENT_RUN_SEGSITES
=> 7,
206 POP_MUT_PARAM_PER_SITE
=> 0.001,
207 POP_RECOMB_PARAM_PER_SITE
=> 0.00025,
212 TRAJ_FILENAME
=> 'traj'
215 foreach my $attribute ( keys %attributes ) {
216 my $func = lc($attribute);
217 if ( $attribute =~ m/POSITIONS/ ) {
218 $func = ucfirst($func);
220 elsif ( $attribute =~ m/\_file/ ) {
224 $func = 'get_' . $func;
225 my @returns = $mbsout->$func();
226 my ( $return, $got );
228 # If there were more than one return value, then compare references to
229 # arrays instead of scalars
230 unless ( @returns > 1 ) {
231 $got = shift @returns;
233 else { $got = \
@returns }
235 my $expected = $attributes{$attribute};
237 if ( defined $got && defined $expected ) {
238 is_deeply
( $got, $expected, "Get $attribute" );
240 else { is_deeply
( $got, $expected, "Get $attribute" ) }
243 my $rh_base_conversion_table = $mbsout->get_base_conversion_table;
245 # Testing next_hap at beginning of run
246 my @data_got = $mbsout->get_next_hap;
247 my @data_expected = qw(1111111);
248 is_deeply
( \
@data_got, \
@data_expected,
249 "Get next_hap at beginning of run" );
251 # Testing next_hap after beginning of run
253 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_seq );
254 @data_expected = '5555555';
255 is_deeply
( \
@data_got, \
@data_expected,
256 "Get next_hap after beginning of run" );
258 # Surprise test! testing mbsout::outgroup
259 my $outgroup = $mbsout->outgroup;
260 is
( $outgroup, 0, "Testing mbsout::outgroup" );
262 # Testing next_run after beginning of run
264 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_run );
270 is_deeply
( \
@data_got, \
@data_expected,
271 "Get next_run after beginning of run" );
273 # Testing next_run after beginning of run
275 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_run );
283 is_deeply
( \
@data_got, \
@data_expected,
284 "Get next_run after beginning of run" );
286 # Testing next_run at beginning of run
288 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_run );
296 is_deeply
( \
@data_got, \
@data_expected,
297 "Get next_run at beginning of run" );
299 # Testing next_hap at beginning of run 2
301 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_seq );
302 @data_expected = '1515151';
303 is_deeply
( \
@data_got, \
@data_expected,
304 "Get next_hap at beginning of run 2" );
306 # Testing next_run after hap
308 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_run );
315 is_deeply
( \
@data_got, \
@data_expected, "Get next_run after hap" );
317 is
( $mbsout->get_next_run_num, 5, 'next run should be 5.' );
322 ##############################################################################
324 ##############################################################################
328 $infile = test_input_file
($infile);
330 #print_file3( $infile, $gzip );
332 my $file_sequence = $infile;
334 $file_sequence = "gunzip -c <$file_sequence |";
336 my $mbsout = Bio
::SeqIO
->new(
337 -file
=> "$file_sequence",
341 isa_ok
( $mbsout, 'Bio::SeqIO::mbsout' );
343 my $rh_base_conversion_table = $mbsout->get_base_conversion_table;
349 'command: mbs 3 -t 0.001 -r 0.00025 -s 5000 2500 -f 1 1 traj ',
352 LAST_READ_HAP_NUM
=> 0,
353 POSITIONS
=> [qw(79.1001 80.1001 81.101 82.101 83.10001 84.801 85)],
354 CURRENT_RUN_SEGSITES
=> 7,
355 POP_MUT_PARAM_PER_SITE
=> 0.001,
356 POP_RECOMB_PARAM_PER_SITE
=> 0.00025,
361 TRAJ_FILENAME
=> 'traj'
364 foreach my $attribute ( keys %attributes ) {
365 my $func = lc($attribute);
367 if ( $attribute =~ m/POPS|SEEDS|POSITIONS/ ) {
368 $func = ucfirst($func);
371 $func = 'get_' . $func;
372 my @returns = $mbsout->$func();
373 my ( $return, $got );
375 # If there were more than one return value, then compare references to
376 # arrays instead of scalars
377 unless ( @returns > 1 ) {
378 $got = shift @returns;
380 else { $got = \
@returns }
382 my $expected = $attributes{$attribute};
384 if ( defined $got && defined $expected ) {
385 is_deeply
( $got, $expected, "Get $attribute" );
387 else { is_deeply
( $got, $expected, "Get $attribute" ) }
390 # Testing next_run at beginning of run
392 convert_bases_to_nums
( $rh_base_conversion_table, $mbsout->get_next_run );
393 my @data_expected = qw(1111111 5555555 4444444);
394 is_deeply
( \
@data_got, \
@data_expected,
395 "Get next_run at end/beginning of run" );
397 is
( $mbsout->get_next_run_num, undef, 'have all lines been read?' );
399 # Testing what happens when we read from empty stream
400 @data_got = $mbsout->get_next_run;
402 is_deeply
( \
@data_got, \
@data_expected, "Get next_run at eof" );
404 # Testing what happens when we read from empty stream
405 @data_got = $mbsout->get_next_hap;
406 @data_expected = undef;
407 is_deeply
( \
@data_got, \
@data_expected, "Get next_hap at eof" );
409 # Testing what happens when we read from empty stream
410 @data_got = $mbsout->get_next_seq;
412 is_deeply
( \
@data_got, \
@data_expected, "Get next_seq at eof" );
418 my $destination = shift;
422 command: mbs 6 -t 0.001 -r 0.00025 -s 5000 2500 -f 3 1 traj
424 //0-1 allele: a a a d d d d
426 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
433 //1-1 allele: a a a a d d d
435 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
442 //2-1 allele: a d d d d d d
444 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
457 else { $gzip = ' '; }
458 open my $OUT, "$gzip >$destination" or croak
"Could not write file '$destination': $!\n";
466 my $destination = shift;
470 command: mbs 6 -t 0.001 -r 0.00025 -s 5000 2500 -f 5 1 traj
472 //0-1 allele: a a a d d d d
474 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
481 //1-1 allele: a a a d d d d
483 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
490 //2-1 allele: a a a d d d d
493 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
500 //3-1 allele: a a a a a d d
503 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
510 //4-1 allele: a a d d d d d
513 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
521 else { $gzip = ' '; }
523 open my $OUT, "$gzip >$destination" or croak
"Could not write file '$destination': $!\n";
531 my $destination = shift;
535 command: mbs 3 -t 0.001 -r 0.00025 -s 5000 2500 -f 1 1 traj
537 //0-1 allele: a a a d d d d
539 positions: 79.1001 80.1001 81.101 82.101 83.10001 84.801 85
548 else { $gzip = ' '; }
550 open my $OUT, "$gzip >$destination" or croak
"Could not write file '$destination': $!\n";
557 my ( $ra_in, $out ) = @_;
558 open my $OUT, '>', $out or croak
"\nCould not write outfile '$out': $!\n";
559 print $OUT ("@$ra_in");
563 sub convert_bases_to_nums
{
564 my ( $rh_base_conversion_table, @seqs ) = @_;
567 foreach my $seq (@seqs) {
568 my $seqstring = $seq->seq;
569 foreach my $base ( keys %{$rh_base_conversion_table} ) {
570 $seqstring =~ s/($base)/$rh_base_conversion_table->{$base}/g;
572 push @out_seqstrings, $seqstring;
574 return @out_seqstrings;