1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 58);
14 my $verbose = test_debug();
16 my @formats = qw(gcg fasta raw pir tab ace );
17 # The following files or formats are failing: swiss genbank interpro embl
19 for my $format (@formats) {
20 print "======== $format ========\n" if $verbose;
22 my $str = Bio::SeqIO->new( -file => test_input_file("test.$format"),
25 is $str->format(), $format;
27 ok $seq = $str->next_seq();
28 print "Sequence 1 of 2 from $format stream:\n", $seq->seq, "\n\n" if $verbose;
29 unless ($format eq 'raw') {
30 is $seq->id, 'roa1_drome',"ID for format $format";
34 unless ($format eq 'gcg') { # GCG file can contain only one sequence
35 ok $seq = $str->next_seq();
36 print "Sequence 2 of 2 from $format stream:\n", $seq->seq, $seq->seq, "\n" if $verbose;
39 my $outfile = test_output_file();
40 my $out = Bio::SeqIO->new( -file => ">$outfile",
42 ok $out->write_seq($seq);
43 if ($format eq 'fasta') {
45 ok($id_type = $out->preferred_id_type('accession.version'),
56 test_skip(-tests => 6, -requires_modules => [qw(Algorithm::Diff
59 use_ok 'Algorithm::Diff';
60 eval "use Algorithm::Diff qw(diff LCS);";
61 use_ok 'IO::ScalarArray';
65 #'test.embl' => 'embl',
67 'test.fasta' => 'fasta',
68 #'test.game' => 'game',
70 #'test.genbank' => 'genbank',
72 #'test_badlf.gcg' => 'gcg'
75 while( my ($file, $type) = each %files ) {
76 my $filename = test_input_file($file);
77 print "processing file $filename\n" if $verbose;
78 open my $FILE, '<', $filename or die "Could not read file '$filename': $!\n";
82 my $in = IO::String->new( join('', @datain) );
83 my $seqin = Bio::SeqIO->new( -fh => $in,
85 my $out = IO::String->new();
86 my $seqout = Bio::SeqIO->new( -fh => $out,
89 while( defined($seq = $seqin->next_seq) ) {
90 $seqout->write_seq($seq);
94 my $strref = $out->string_ref;
95 my @dataout = map { $_."\n"} split(/\n/, $$strref );
96 my @diffs = &diff( \@datain, \@dataout);
99 if(@diffs && $verbose) {
100 foreach my $d ( @diffs ) {
101 foreach my $diff ( @$d ) {
103 print $diff->[0], $diff->[1], "\n>", $diff->[2], "\n";
106 print "in is \n", join('', @datain), "\n";
107 print "out is \n", join('',@dataout), "\n";
112 # simple tests specific to Bio::SeqIO interface (applicable to all SeqIO
115 ##############################################
116 # test format() and variant() in Bio::RootIO
117 ##############################################
119 my $in = Bio::SeqIO->new(
120 -file => test_input_file('bug2901.fa'),
123 is $in->format, 'fasta';
124 is $in->variant, undef;
126 $in = Bio::SeqIO->new(
127 -file => test_input_file('fastq', 'illumina_faked.fastq'),
129 -variant => 'illumina',
131 is $in->format, 'fastq';
132 is $in->variant, 'illumina';
135 ######################################################
136 # test format detection from different inputs
137 ######################################################
139 $in = Bio::SeqIO->new( -file => test_input_file('test.fastq') );
140 is $in->format, 'fastq';
142 open my $fh, '<', test_input_file('test.genbank') or die "Could not read file 'test.genbank': $!\n";
143 $in = Bio::SeqIO->new( -fh => $fh );
144 is $in->format, 'genbank';
147 my $string = ">seq\nACGATCG\n";
148 $in = Bio::SeqIO->new( -string => $string );
149 is $in->format, 'fasta';
152 ############ EXCEPTION HANDLING ############
155 local $TODO = 'file/fh-based tests should be in Bio::Root::IO, see issue #3204';
158 } qr/No file, fh, or string argument provided/, 'Must pass a file or file handle';
162 Bio::SeqIO->new(-fh => undef);
163 } qr/fh argument provided, but with an undefined value/,
164 'Must pass a file or file handle';
167 Bio::SeqIO->new(-file => undef);
168 } qr/file argument provided, but with an undefined value/,
169 'Must pass a file or file handle';
172 Bio::SeqIO->new(-file => 'foo.bar');
173 } qr/Could not read file 'foo.bar':/,
174 'Must pass a real file';