maint: remove Travis stuff which has been replaced with Github actions (#325)
[bioperl-live.git] / t / SeqIO / raw.t
blob49fbfa891134e84feb3fecf8aa9679488e20d798
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     
9     test_begin(-tests               => 25,
10                            -requires_modules    => [],
11                            -requires_networking => 0,
12                           );
13         
14         use_ok('Bio::SeqIO::raw');
17 my $verbose = test_debug();
19 my $format = 'raw';
20 my $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test.$format"),
21                                                         -format => $format);
23 isa_ok($seqio_obj, 'Bio::SeqIO');
26 is $seqio_obj->variant, 'multiple';
28 my @methods = qw(next_seq write_seq);
29 foreach my $method (@methods) {
30         can_ok($seqio_obj, $method) || 
31                 diag "$method method not implemented for $format";      
34 # checking the first sequence object
35 my $seq_obj = $seqio_obj->next_seq();
36 isa_ok($seq_obj, 'Bio::Seq');
37 my %expected = ('seq'         => 'MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGL' .
38                                                                  'DYRTTDENLKAHEKWGNIVDVVVMKDPRTKRSRGFGFI' .
39                                                                  'TYSHSSMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPN' .
40                                                                  'AGATVKKLFVGALKDDHDEQSIRDYFQHFGNIVDNIVI' .
41                                                                  'DKETGKKRGFAFVEFDDYDPVDKVVLQKQHQLNGKMVD' .
42                                                                  'VKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGN' .
43                                                                  'QNGGGNWNNGGNNWGNNRGNDNWGNNSFGGGGGGGGGY' .
44                                                                  'GGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGNDFGGY' .
45                                                                  'QQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGN' .
46                                                                  'YGNNQGFNNGGNNRRY',
47                                 'length'      => '358',
48                            );
49 is   ($seq_obj->seq(),         $expected{'seq'},         'sequence');
50 is   ($seq_obj->length(),      $expected{'length'},      'length');
53 # checking the second sequence object
54 my $seq_obj2  = $seqio_obj->next_seq();
55 isa_ok($seq_obj2, 'Bio::Seq');
56 my %expected2 = ('seq'         => 'MNKQRGTYSEVSLAQDPKRQQRKLKGNKISISGTKQEI' .
57                                                                   'FQVELNLQNASSDHQGNDKTYHCKGLLPPPEKLTAEVL' .
58                                                                   'GIICIVLMATVLKTIVLIPCIGVLEQNNFSLNRRMQKA' .
59                                                                   'RHCGHCPEEWITYSNSCYYIGKERRTWEERVCWPVLRR' .
60                                                                   'TLICFL',
61                                  'length'      => '158',
62                             );
63 is   ($seq_obj2->seq(),         $expected2{'seq'},         'sequence');
64 is   ($seq_obj2->length(),      $expected2{'length'},      'length');
65         
66 # from testformats.pl
67 SKIP: {
69     test_skip(-tests => 2,
70               -requires_modules => [qw(Algorithm::Diff
71                                     IO::ScalarArray
72                                     IO::String)]);
73     use_ok('Algorithm::Diff', qw(diff LCS));
74     
75         my ($file, $type) = ("test.$format", $format);
76     my $filename = test_input_file($file);
77     print "processing file $filename\n" if $verbose;
78     open my $FILE, '<', $filename or die "Could not read file '$filename': $!\n";
79     my @datain = <$FILE>;
80     close $FILE;
82     my $in = IO::String->new(join('', @datain));
83     my $seqin = Bio::SeqIO->new( -fh => $in,
84                 -format => $type);
85     my $out = IO::String->new;
86     my $seqout = Bio::SeqIO->new( -fh => $out,
87                  -format => $type);
88     my $seq;
89     while( defined($seq = $seqin->next_seq) ) { 
90         $seqout->write_seq($seq);
91     }
92     $seqout->close();
93     $seqin->close();
94     my $strref = $out->string_ref;
95     my @dataout = map { $_."\n"} split(/\n/, $$strref );
96     my @diffs = &diff( \@datain, \@dataout);
97     is(@diffs, 0, "$format format can round-trip");
98     
99     if(@diffs && $verbose) {
100         use Data::Dumper;  # should be safe for 5.005 and greater
101         foreach my $d ( @diffs ) {
102             print STDERR Dumper $d;
103             foreach my $diff ( @$d ) {
104                 chomp($diff->[2]);
105                 print $diff->[0], $diff->[1], "\n>", $diff->[2], "\n";
106             }
107         }
108         print "in is \n", join('', @datain), "\n";
109         print "out is \n", join('',@dataout), "\n";     
110     }
113 # test raw variants
114 my @seq = qw(MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGLDYRTTDENLKAHEKWGNIVDVV
115 VMKDPRTKRSRGFGFITYSHSSMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPNAGATVK
116 KLFVGALKDDHDEQSIRDYFQHFGNIVDNIVIDKETGKKRGFAFVEFDDYDPVDKVVLQK
117 QHQLNGKMVDVKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGNQNGGGNWNNGGN
118 NWGNNRGNDNWGNNSFGGGGGGGGGYGGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGND
119 FGGYQQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGNYGNNQGFNNGGNNRRY);
121 $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test2.raw"),
122                                                         -format => 'raw');
124 is($seqio_obj->variant, 'multiple');
126 my $ct = 0;
128 while (my $seq = $seqio_obj->next_seq) {
129     is($seq->seq, $seq[$ct]);
130     $ct++;
133 is($ct, 6);
135 $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test2.raw"),
136                                                         -format => 'raw-single');
138 is($seqio_obj->variant, 'single');
140 my $seq = $seqio_obj->next_seq;
141 is($seq->seq, join('', @seq));
143 $seqio_obj = Bio::SeqIO->new(-file      => test_input_file("test2.raw"),
144                             -format     => 'raw',
145                             -variant    => 'single');
147 is($seqio_obj->variant, 'single');
149 $seq = $seqio_obj->next_seq;
150 is($seq->seq, join('', @seq));