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