sync with trunk to r15684
[bioperl-live.git] / t / SeqIO / fasta.t
bloba35e6c093a23342620b90e4a65ab07886ae6a1f1
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               => 18,
11                            -requires_modules    => [],
12                            -requires_networking => 0,
13                           );
14         
15         use_ok('Bio::SeqIO::fasta');
18 my $verbose = test_debug();
20 my $format = 'fasta';
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 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 is   ($seq_obj->primary_id(),  $expected{'primary_id'},  'primary_id');
52 like ($seq_obj->description(), $expected{'description'}, 'description');
55 # checking the second sequence object
56 my $seq_obj2  = $seqio_obj->next_seq();
57 isa_ok($seq_obj2, 'Bio::Seq');
58 my %expected2 = ('seq'         => 'MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGL' .
59                                                                   'DYRTTDENLKAHEKWGNIVDVVVMKDPTSTSTSTSTST' .
60                                                                   'STSTSTMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPN' .
61                                                                   'AGATVKKLFVGALKDDHDEQSIRDYFQHLLLLLLLDLL' .
62                                                                   'LLDLLLLDLLLFVEFDDYDPVDKVVLQKQHQLNGKMVD' .
63                                                                   'VKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGN' .
64                                                                   'QNGGGNWNNGGNNWGNNRGNDNWGNNSFGGGGGGGGGY' .
65                                                                   'GGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGNDFGGY' .
66                                                                   'QQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGN' .
67                                                                   'YGNNQGFNNGGNNRRY',
68                                  'length'      => '358',
69                                  'primary_id'  => 'roa2_drome',
70                                  'description' => qr(Rea guano ligand),
71                             );
72 is   ($seq_obj2->seq(),         $expected2{'seq'},         'sequence');
73 is   ($seq_obj2->length(),      $expected2{'length'},      'length');
74 is   ($seq_obj2->primary_id(),  $expected2{'primary_id'},  'primary_id');
75 like ($seq_obj2->description(), $expected2{'description'}, 'description');
76         
77 # from testformats.pl
78 SKIP: {
79     test_skip(-tests => 4, -requires_modules => [qw(Algorithm::Diff
80                                                     IO::ScalarArray
81                                                     IO::String)]);
82     use_ok('Algorithm::Diff');
83     eval "use Algorithm::Diff qw(diff LCS);";
84     use_ok('IO::ScalarArray');
85     use_ok('IO::String');
86     
87         my ($file, $type) = ("test.$format", $format);
88     my $filename = test_input_file($file);
89     print "processing file $filename\n" if $verbose;
90     open(FILE, "< $filename") or die("cannot open $filename");
91     my @datain = <FILE>;
92     my $in = new IO::String(join('', @datain));
93     my $seqin = new Bio::SeqIO( -fh => $in,
94                 -format => $type);
95     my $out = new IO::String;
96     my $seqout = new Bio::SeqIO( -fh => $out,
97                  -format => $type);
98     my $seq;
99     while( defined($seq = $seqin->next_seq) ) { 
100     $seqout->write_seq($seq);
101     }
102     $seqout->close();
103     $seqin->close();
104     my $strref = $out->string_ref;
105     my @dataout = map { $_."\n"} split(/\n/, $$strref );
106     my @diffs = &diff( \@datain, \@dataout);
107     is(@diffs, 0, "$format format can round-trip");
108     
109     if(@diffs && $verbose) {
110         foreach my $d ( @diffs ) {
111             foreach my $diff ( @$d ) {
112                 chomp($diff->[2]);
113                 print $diff->[0], $diff->[1], "\n>", $diff->[2], "\n";
114             }
115         }
116         print "in is \n", join('', @datain), "\n";
117         print "out is \n", join('',@dataout), "\n";     
118     }