skip tests if the cloning class used happens to be Storable, see bug #3447
[bioperl-live.git] / t / SeqIO / raw.t
blob1efa2ba30221f148b8aa5163f903b7115ff6645a
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               => 25,
11                            -requires_modules    => [],
12                            -requires_networking => 0,
13                           );
14         
15         use_ok('Bio::SeqIO::raw');
18 my $verbose = test_debug();
20 my $format = 'raw';
21 my $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test.$format"),
22                                                         -format => $format);
24 isa_ok($seqio_obj, 'Bio::SeqIO');
27 is $seqio_obj->variant, 'multiple';
29 my @methods = qw(next_seq write_seq);
30 foreach my $method (@methods) {
31         can_ok($seqio_obj, $method) || 
32                 diag "$method method not implemented for $format";      
35 # checking the first sequence object
36 my $seq_obj = $seqio_obj->next_seq();
37 isa_ok($seq_obj, 'Bio::Seq');
38 my %expected = ('seq'         => 'MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGL' .
39                                                                  'DYRTTDENLKAHEKWGNIVDVVVMKDPRTKRSRGFGFI' .
40                                                                  'TYSHSSMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPN' .
41                                                                  'AGATVKKLFVGALKDDHDEQSIRDYFQHFGNIVDNIVI' .
42                                                                  'DKETGKKRGFAFVEFDDYDPVDKVVLQKQHQLNGKMVD' .
43                                                                  'VKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGN' .
44                                                                  'QNGGGNWNNGGNNWGNNRGNDNWGNNSFGGGGGGGGGY' .
45                                                                  'GGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGNDFGGY' .
46                                                                  'QQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGN' .
47                                                                  'YGNNQGFNNGGNNRRY',
48                                 'length'      => '358',
49                            );
50 is   ($seq_obj->seq(),         $expected{'seq'},         'sequence');
51 is   ($seq_obj->length(),      $expected{'length'},      'length');
54 # checking the second sequence object
55 my $seq_obj2  = $seqio_obj->next_seq();
56 isa_ok($seq_obj2, 'Bio::Seq');
57 my %expected2 = ('seq'         => 'MNKQRGTYSEVSLAQDPKRQQRKLKGNKISISGTKQEI' .
58                                                                   'FQVELNLQNASSDHQGNDKTYHCKGLLPPPEKLTAEVL' .
59                                                                   'GIICIVLMATVLKTIVLIPCIGVLEQNNFSLNRRMQKA' .
60                                                                   'RHCGHCPEEWITYSNSCYYIGKERRTWEERVCWPVLRR' .
61                                                                   'TLICFL',
62                                  'length'      => '158',
63                             );
64 is   ($seq_obj2->seq(),         $expected2{'seq'},         'sequence');
65 is   ($seq_obj2->length(),      $expected2{'length'},      'length');
66         
67 # from testformats.pl
68 SKIP: {
70     test_skip(-tests => 2,
71               -requires_modules => [qw(Algorithm::Diff
72                                     IO::ScalarArray
73                                     IO::String)]);
74     use_ok('Algorithm::Diff', qw(diff LCS));
75     
76         my ($file, $type) = ("test.$format", $format);
77     my $filename = test_input_file($file);
78     print "processing file $filename\n" if $verbose;
79     open(FILE, "< $filename") or die("cannot open $filename");
80     my @datain = <FILE>;
81     my $in = IO::String->new(join('', @datain));
82     my $seqin = Bio::SeqIO->new( -fh => $in,
83                 -format => $type);
84     my $out = IO::String->new;
85     my $seqout = Bio::SeqIO->new( -fh => $out,
86                  -format => $type);
87     my $seq;
88     while( defined($seq = $seqin->next_seq) ) { 
89         $seqout->write_seq($seq);
90     }
91     $seqout->close();
92     $seqin->close();
93     my $strref = $out->string_ref;
94     my @dataout = map { $_."\n"} split(/\n/, $$strref );
95     my @diffs = &diff( \@datain, \@dataout);
96     is(@diffs, 0, "$format format can round-trip");
97     
98     if(@diffs && $verbose) {
99         use Data::Dumper;  # should be safe for 5.005 and greater
100         foreach my $d ( @diffs ) {
101             print STDERR Dumper $d;
102             foreach my $diff ( @$d ) {
103                 chomp($diff->[2]);
104                 print $diff->[0], $diff->[1], "\n>", $diff->[2], "\n";
105             }
106         }
107         print "in is \n", join('', @datain), "\n";
108         print "out is \n", join('',@dataout), "\n";     
109     }
112 # test raw variants
113 my @seq = qw(MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGLDYRTTDENLKAHEKWGNIVDVV
114 VMKDPRTKRSRGFGFITYSHSSMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPNAGATVK
115 KLFVGALKDDHDEQSIRDYFQHFGNIVDNIVIDKETGKKRGFAFVEFDDYDPVDKVVLQK
116 QHQLNGKMVDVKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGNQNGGGNWNNGGN
117 NWGNNRGNDNWGNNSFGGGGGGGGGYGGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGND
118 FGGYQQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGNYGNNQGFNNGGNNRRY);
120 $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test2.raw"),
121                                                         -format => 'raw');
123 is($seqio_obj->variant, 'multiple');
125 my $ct = 0;
127 while (my $seq = $seqio_obj->next_seq) {
128     is($seq->seq, $seq[$ct]);
129     $ct++;
132 is($ct, 6);
134 $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test2.raw"),
135                                                         -format => 'raw-single');
137 is($seqio_obj->variant, 'single');
139 my $seq = $seqio_obj->next_seq;
140 is($seq->seq, join('', @seq));
142 $seqio_obj = Bio::SeqIO->new(-file      => test_input_file("test2.raw"),
143                             -format     => 'raw',
144                             -variant    => 'single');
146 is($seqio_obj->variant, 'single');
148 $seq = $seqio_obj->next_seq;
149 is($seq->seq, join('', @seq));