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
|
# -*-Perl-*- Test Harness script for Bioperl
# $Id: SeqIO.t 15112 2008-12-08 18:12:38Z sendu $
use strict;
BEGIN {
use lib '.';
use Bio::Root::Test;
test_begin(-tests => 41);
use_ok('Bio::SeqIO');
}
my $verbose = test_debug();
# Basic read and/or write tests for SeqIO. Specific tests for
# given module should go into their own file.
my @formats = qw(gcg fasta raw pir tab ace );
# The following files or formats are failing: swiss genbank interpro embl
foreach my $format (@formats) {
print "======== $format ========\n" if $verbose;
read_write($format);
}
sub read_write {
my $format = shift;
my $seq;
my $str = Bio::SeqIO->new(-file=> test_input_file("test.$format"),
-format => $format);
ok $seq = $str->next_seq();
print "Sequence 1 of 2 from $format stream:\n", $seq->seq, "\n\n" if $verbose;
unless ($format eq 'raw') {
is $seq->id, 'roa1_drome',"ID for format $format";
is $seq->length, 358;
}
unless ($format eq 'gcg') { # GCG file can contain only one sequence
ok $seq = $str->next_seq();
print "Sequence 2 of 2 from $format stream:\n", $seq->seq, $seq->seq, "\n" if $verbose;
}
my $outfile = test_output_file();
my $out = Bio::SeqIO->new(-file => ">$outfile",
-format => $format);
ok $out->write_seq($seq);
if ($format eq 'fasta') {
my $id_type;
ok($id_type = $out->preferred_id_type('accession.version'),
'accession.version');
}
ok -s $outfile;
}
# from testformats.pl
SKIP: {
test_skip(-tests => 6, -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 %files = (
#'test.embl' => 'embl',
#'test.ace' => 'ace',
'test.fasta' => 'fasta',
#'test.game' => 'game',
'test.gcg' => 'gcg',
#'test.genbank' => 'genbank',
'test.raw' => 'raw',
#'test_badlf.gcg' => 'gcg'
);
while( my ($file, $type) = each %files ) {
my $filename = test_input_file($file);
print "processing file $filename\n" if $verbose;
open(FILE, "< $filename") or die("cannot open $filename");
my @datain = <FILE>;
my $in = new IO::String(join('', @datain));
my $seqin = new Bio::SeqIO( -fh => $in,
-format => $type);
my $out = new IO::String;
my $seqout = new Bio::SeqIO( -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;
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";
}
}
}
|