Allow falling back to any strigified Bio::AnnotationI for 'gene_name'
[bioperl-live.git] / t / SeqIO / gcg.t
blob3592a1500dd4164db89fee13ad97c19998b0b93e
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(FILE, "< $filename") or die("cannot open $filename");
84     my @datain = <FILE>;
85     my $in = new IO::String(join('', @datain));
86     my $seqin = new Bio::SeqIO( -fh => $in,
87                 -format => $type);
88     my $out = new IO::String;
89     my $seqout = new Bio::SeqIO( -fh => $out,
90                  -format => $type);
91     my $seq;
92     while( defined($seq = $seqin->next_seq) ) { 
93     $seqout->write_seq($seq);
94     }
95     $seqout->close();
96     $seqin->close();
97     my $strref = $out->string_ref;
98     my @dataout = map { $_."\n"} split(/\n/, $$strref );
99     my @diffs = &diff( \@datain, \@dataout);
100     is(@diffs, 0, "$format format can round-trip");
101     
102     if(@diffs && $verbose) {
103         foreach my $d ( @diffs ) {
104             foreach my $diff ( @$d ) {
105                 chomp($diff->[2]);
106                 print $diff->[0], $diff->[1], "\n>", $diff->[2], "\n";
107             }
108         }
109         print "in is \n", join('', @datain), "\n";
110         print "out is \n", join('',@dataout), "\n";     
111     }