File: Variation_IO.t

package info (click to toggle)
libbio-variation-perl 1.7.5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: perl: 3,217; xml: 946; makefile: 2
file content (104 lines) | stat: -rw-r--r-- 2,642 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*-Perl-*- Test Harness script for Bioperl
# $Id$

use strict;

BEGIN { 
    use lib '.';
    use Bio::Root::Test;
    
    test_begin(-tests => 26,
			   -requires_modules => ['Text::Wrap 98', 'XML::Writer']);
	
	use_ok('Bio::Variation::IO');
}

sub io {
    my ($t_file, $o_file, $out_format) = @_; 
    my $res;
	
    my ($o_ext) = $out_format eq 'flat' ? 'dat' : 'xml';
    my ($o_format) = $out_format;
    my ($t_name) = $t_file =~ /(.*)....$/;
	
    my( $before );
    {
        local $/ = undef;
        open my $BEFORE, '<', "$t_name.$o_ext" or die "Could not read file '$t_name.$o_ext': $!\n";
        $before = <$BEFORE>;
        close $BEFORE;
    }

    ok $before;#"Error in reading input file [$t_name.$o_ext]";

    my $in = Bio::Variation::IO->new( -file => $t_file);
    my  @entries ;
    while (my $e = $in->next) {
        push @entries, $e;
    }
    my $count = scalar @entries;
    cmp_ok @entries, '>', 0;# "No SeqDiff objects [$count]";

    my $out = Bio::Variation::IO->new( -FILE => ">$o_file", 
				       -FORMAT => $o_format);
    my $out_ok = 1;
    foreach my $e (@entries) {
        $out->write($e) or $out_ok = 0;
    }
    undef($out);  # Flush to disk
    ok $out_ok;#  "error writing variants";

    my( $after );
    {
        local $/ = undef;
        open my $AFTER, '<', $o_file or die "Could not read file '$o_file': $!\n";
        $after = <$AFTER>;
        close $AFTER;
    }

    ok $after;# "Error in reading in again the output file [$o_file]";
    is $before, $after, "test output file compared to input";
    print STDERR `diff $t_file $o_file` if $before ne $after;
}

io  (test_input_file('mutations.dat'), 
     test_output_file(), 'flat'); #1..5
io  (test_input_file('polymorphism.dat'), 
     test_output_file(), 'flat'); #6..10

SKIP: {
	test_skip(-tests => 15, -requires_modules => [qw(XML::Twig
												     XML::Writer
												     IO::String)]);

	eval {
		if( $XML::Writer::VERSION >= 0.5 ) { 
		io  (test_input_file('mutations.xml'), 
			 test_output_file(), 'xml'); #10..12
		} else { 
		io  (test_input_file('mutations.old.xml'), 
			 test_output_file(), 'xml'); #10..12
		}
	};
	
	eval {
		if( $XML::Writer::VERSION >= 0.5 ) { 
		io  (test_input_file('polymorphism.xml'), 
			 test_output_file(), 'xml'); #13..14
		} else { 
		io  (test_input_file('polymorphism.old.xml'), 
			 test_output_file(), 'xml'); #13..14
	
		}
	};
	
	eval { 
		if( $XML::Writer::VERSION >= 0.5 ) { 
		io  (test_input_file('mutations.dat'), 
			 test_output_file(), 'xml'); #15..25
		} else { 
		io  (test_input_file('mutations.old.dat'), 
			 test_output_file(), 'xml'); #15..25
		}
	};
}