Bio::DB::Universal: move into its own distribution
[bioperl-live.git] / t / SeqIO / raw.t
blobe1e6f1ee06c40390845f20d45706249470459568
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 my $FILE, '<', $filename or die "Could not read file '$filename': $!\n";
80     my @datain = <$FILE>;
81     close $FILE;
83     my $in = IO::String->new(join('', @datain));
84     my $seqin = Bio::SeqIO->new( -fh => $in,
85                 -format => $type);
86     my $out = IO::String->new;
87     my $seqout = Bio::SeqIO->new( -fh => $out,
88                  -format => $type);
89     my $seq;
90     while( defined($seq = $seqin->next_seq) ) { 
91         $seqout->write_seq($seq);
92     }
93     $seqout->close();
94     $seqin->close();
95     my $strref = $out->string_ref;
96     my @dataout = map { $_."\n"} split(/\n/, $$strref );
97     my @diffs = &diff( \@datain, \@dataout);
98     is(@diffs, 0, "$format format can round-trip");
99     
100     if(@diffs && $verbose) {
101         use Data::Dumper;  # should be safe for 5.005 and greater
102         foreach my $d ( @diffs ) {
103             print STDERR Dumper $d;
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     }
114 # test raw variants
115 my @seq = qw(MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGLDYRTTDENLKAHEKWGNIVDVV
116 VMKDPRTKRSRGFGFITYSHSSMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPNAGATVK
117 KLFVGALKDDHDEQSIRDYFQHFGNIVDNIVIDKETGKKRGFAFVEFDDYDPVDKVVLQK
118 QHQLNGKMVDVKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGNQNGGGNWNNGGN
119 NWGNNRGNDNWGNNSFGGGGGGGGGYGGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGND
120 FGGYQQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGNYGNNQGFNNGGNNRRY);
122 $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test2.raw"),
123                                                         -format => 'raw');
125 is($seqio_obj->variant, 'multiple');
127 my $ct = 0;
129 while (my $seq = $seqio_obj->next_seq) {
130     is($seq->seq, $seq[$ct]);
131     $ct++;
134 is($ct, 6);
136 $seqio_obj = Bio::SeqIO->new(-file   => test_input_file("test2.raw"),
137                                                         -format => 'raw-single');
139 is($seqio_obj->variant, 'single');
141 my $seq = $seqio_obj->next_seq;
142 is($seq->seq, join('', @seq));
144 $seqio_obj = Bio::SeqIO->new(-file      => test_input_file("test2.raw"),
145                             -format     => 'raw',
146                             -variant    => 'single');
148 is($seqio_obj->variant, 'single');
150 $seq = $seqio_obj->next_seq;
151 is($seq->seq, join('', @seq));