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