Bio::SeqIO::agave: move to its own distribution
[bioperl-live.git] / t / SeqIO / fasta.t
blob5e7823266c3a49a78e605135523c731d62106280
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     
9     test_begin(-tests               => 22,
10                -requires_modules    => [],
11                -requires_networking => 0,
12               );
14     use_ok('Bio::SeqIO::fasta');
17 my $verbose = test_debug();
19 my $format = 'fasta';
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 my %expected = ('seq'         => 'MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGL' .
35                                  'DYRTTDENLKAHEKWGNIVDVVVMKDPRTKRSRGFGFI' .
36                                  'TYSHSSMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPN' .
37                                  'AGATVKKLFVGALKDDHDEQSIRDYFQHFGNIVDNIVI' .
38                                  'DKETGKKRGFAFVEFDDYDPVDKVVLQKQHQLNGKMVD' .
39                                  'VKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGN' .
40                                  'QNGGGNWNNGGNNWGNNRGNDNWGNNSFGGGGGGGGGY' .
41                                  'GGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGNDFGGY' .
42                                  'QQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGN' .
43                                  'YGNNQGFNNGGNNRRY',
44                 'length'      => '358',
45                 'primary_id'  => 'roa1_drome',
46                 'description' => qr(Rea guano receptor type III),
47                );
48 is   ($seq_obj->seq(),         $expected{'seq'},         'sequence');
49 is   ($seq_obj->length(),      $expected{'length'},      'length');
50 is   ($seq_obj->primary_id(),  $expected{'primary_id'},  'primary_id');
51 like ($seq_obj->description(), $expected{'description'}, 'description');
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'         => 'MVNSNQNQNGNSNGHDDDFPQDSITEPEHMRKLFIGGL' .
58                                   'DYRTTDENLKAHEKWGNIVDVVVMKDPTSTSTSTSTST' .
59                                   'STSTSTMIDEAQKSRPHKIDGRVEPKRAVPRQDIDSPN' .
60                                   'AGATVKKLFVGALKDDHDEQSIRDYFQHLLLLLLLDLL' .
61                                   'LLDLLLLDLLLFVEFDDYDPVDKVVLQKQHQLNGKMVD' .
62                                   'VKKALPKNDQQGGGGGRGGPGGRAGGNRGNMGGGNYGN' .
63                                   'QNGGGNWNNGGNNWGNNRGNDNWGNNSFGGGGGGGGGY' .
64                                   'GGGNNSWGNNNPWDNGNGGGNFGGGGNNWNGGNDFGGY' .
65                                   'QQNYGGGPQRGGGNFNNNRMQPYQGGGGFKAGGGNQGN' .
66                                   'YGNNQGFNNGGNNRRY',
67                  'length'      => '358',
68                  'primary_id'  => 'roa2_drome',
69                  'description' => qr(Rea guano ligand),
70                 );
71 is   ($seq_obj2->seq(),         $expected2{'seq'},         'sequence');
72 is   ($seq_obj2->length(),      $expected2{'length'},      'length');
73 is   ($seq_obj2->primary_id(),  $expected2{'primary_id'},  'primary_id');
74 like ($seq_obj2->description(), $expected2{'description'}, 'description');
76 # from testformats.pl
77 SKIP: {
78     test_skip(-tests => 4, -requires_modules => [qw(Algorithm::Diff
79                                                     IO::ScalarArray
80                                                     IO::String)]);
81     use_ok('Algorithm::Diff');
82     eval "use Algorithm::Diff qw(diff LCS);";
83     use_ok('IO::ScalarArray');
84     use_ok('IO::String');
85     
86     my ($file, $type) = ("test.$format", $format);
87     my $filename = test_input_file($file);
88     print "processing file $filename\n" if $verbose;
89     open my $FILE, '<', $filename or die "Could not read file '$filename': $!\n";
90     my @datain = <$FILE>;
91     close $FILE;
93     my $in = new IO::String(join('', @datain));
94     my $seqin = new Bio::SeqIO( -fh => $in,
95                 -format => $type);
96     my $out = new IO::String;
97     my $seqout = new Bio::SeqIO( -fh => $out,
98                  -format => $type);
99     my $seq;
100     while( defined($seq = $seqin->next_seq) ) {
101     $seqout->write_seq($seq);
102     }
103     $seqout->close();
104     $seqin->close();
105     my $strref = $out->string_ref;
106     my @dataout = map { $_."\n"} split(/\n/, $$strref );
107     my @diffs = &diff( \@datain, \@dataout);
108     is(@diffs, 0, "$format format can round-trip");
109     
110     if(@diffs && $verbose) {
111         foreach my $d ( @diffs ) {
112             foreach my $diff ( @$d ) {
113                 chomp($diff->[2]);
114                 print $diff->[0], $diff->[1], "\n>", $diff->[2], "\n";
115             }
116         }
117         print "in is \n", join('', @datain), "\n";
118         print "out is \n", join('',@dataout), "\n";
119     }
123 # bug 1508
124 # test genbank, gcg, ace against fasta (should throw an exception on each)
126 for my $file (qw(roa1.genbank test.gcg test.ace test.raw)) {
127     my $in = Bio::SeqIO->new(-file   => test_input_file($file),
128                              -format => 'fasta');
129     throws_ok {$in->next_seq}
130         qr/The sequence does not appear to be FASTA format/, "dies with $file";