Add tests for memory leaks and weaken for Issue #81
[bioperl-live.git] / t / SeqIO / gcg.t
blobd67200539843496644ec86a893c39b8d66f186d2
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7         use lib '.';
8     use Bio::Root::Test;
9     
10     test_begin(-tests               => 17,
11                            -requires_modules    => [],
12                            -requires_networking => 0,
13                           );
14         
15         use_ok('Bio::SeqIO::gcg');
18 my $verbose = test_debug();
20 my $format = 'gcg';
21 my $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test.$format"),
22                                                         -format => $format);
24 isa_ok($seqio_obj, 'Bio::SeqIO');
26 my @methods = qw(next_seq write_seq);
27 foreach my $method (@methods) {
28         can_ok($seqio_obj, $method) || 
29                 diag "$method method not implemented for $format";      
32 # checking the first sequence object
33 my $seq_obj = $seqio_obj->next_seq();
34 isa_ok($seq_obj, 'Bio::Seq');
35 isa_ok($seq_obj, 'Bio::Seq::RichSeq');
36 my %expected = ('seq'         => 'MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGL' .
37                                                                  'DYRTTDENLKAHEKWGNIVDVVVMKDPRTKRSRGFGFI' .
38                                                                  'TYSHSSMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPN' .
39                                                                  'AGATVKKLFVGALKDDHDEQSIRDYFQHFGNIVDNIVI' .
40                                                                  'DKETGKKRGFAFVEFDDYDPVDKVVLQKQHQLNGKMVD' .
41                                                                  'VKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGN' .
42                                                                  'QNGGGNWNNGGNNWGNNRGNDNWGNNSFGGGGGGGGGY' .
43                                                                  'GGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGNDFGGY' .
44                                                                  'QQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGN' .
45                                                                  'YGNNQGFNNGGNNRRY',
46                                 'length'      => '358',
47                                 'primary_id'  => 'roa1_drome',
48                                 'description' => qr(Rea guano receptor type III),
49                            );
50 is   ($seq_obj->seq(),         $expected{'seq'},         'sequence');
51 is   ($seq_obj->length(),      $expected{'length'},      'length');
52 TODO: {
53         local $TODO = 'possible bug: RichSeq not setting primary_id?';
54         is   ($seq_obj->primary_id(),  $expected{'primary_id'},  'primary_id');
56 like ($seq_obj->description(), $expected{'description'}, 'description');
58 # test DOS linefeeds in gcg parser
59 my $str = Bio::SeqIO->new(-file => test_input_file('test_badlf.gcg'),
60                                                                   -verbose => $verbose,
61                                                                   -format => 'GCG');
62 ok($str);
63 my $seq = $str->next_seq();
64 isa_ok ($seq, 'Bio::SeqI');
65 is(length($seq->seq), $seq->length);
66 print "Sequence 1 of 1 from GCG stream:\n", $seq->seq, "\n" if( $verbose);
70 # from testformats.pl
71 SKIP: {
72     test_skip(-tests => 4, -requires_modules => [qw(Algorithm::Diff
73                                                     IO::ScalarArray
74                                                     IO::String)]);
75     use_ok('Algorithm::Diff');
76     eval "use Algorithm::Diff qw(diff LCS);";
77     use_ok('IO::ScalarArray');
78     use_ok('IO::String');
79     
80     my ($file, $type) = ("test.$format", $format);
81     my $filename = test_input_file($file);
82     print "processing file $filename\n" if $verbose;
83     open my $FILE, '<', $filename or die "Could not read file '$filename': $!\n";
84     my @datain = <$FILE>;
85     close $FILE;
87     my $in = new IO::String(join('', @datain));
88     my $seqin = new Bio::SeqIO( -fh => $in,
89                 -format => $type);
90     my $out = new IO::String;
91     my $seqout = new Bio::SeqIO( -fh => $out,
92                  -format => $type);
93     my $seq;
94     while( defined($seq = $seqin->next_seq) ) { 
95     $seqout->write_seq($seq);
96     }
97     $seqout->close();
98     $seqin->close();
99     my $strref = $out->string_ref;
100     my @dataout = map { $_."\n"} split(/\n/, $$strref );
101     my @diffs = &diff( \@datain, \@dataout);
102     is(@diffs, 0, "$format format can round-trip");
103     
104     if(@diffs && $verbose) {
105         foreach my $d ( @diffs ) {
106             foreach my $diff ( @$d ) {
107                 chomp($diff->[2]);
108                 print $diff->[0], $diff->[1], "\n>", $diff->[2], "\n";
109             }
110         }
111         print "in is \n", join('', @datain), "\n";
112         print "out is \n", join('',@dataout), "\n";     
113     }