1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 58);
15 my $verbose = test_debug();
17 my @formats = qw(gcg fasta raw pir tab ace );
18 # The following files or formats are failing: swiss genbank interpro embl
20 for my $format (@formats) {
21 print "======== $format ========\n" if $verbose;
23 my $str = Bio::SeqIO->new( -file => test_input_file("test.$format"),
26 is $str->format(), $format;
28 ok $seq = $str->next_seq();
29 print "Sequence 1 of 2 from $format stream:\n", $seq->seq, "\n\n" if $verbose;
30 unless ($format eq 'raw') {
31 is $seq->id, 'roa1_drome',"ID for format $format";
35 unless ($format eq 'gcg') { # GCG file can contain only one sequence
36 ok $seq = $str->next_seq();
37 print "Sequence 2 of 2 from $format stream:\n", $seq->seq, $seq->seq, "\n" if $verbose;
40 my $outfile = test_output_file();
41 my $out = Bio::SeqIO->new( -file => ">$outfile",
43 ok $out->write_seq($seq);
44 if ($format eq 'fasta') {
46 ok($id_type = $out->preferred_id_type('accession.version'),
57 test_skip(-tests => 6, -requires_modules => [qw(Algorithm::Diff
60 use_ok 'Algorithm::Diff';
61 eval "use Algorithm::Diff qw(diff LCS);";
62 use_ok 'IO::ScalarArray';
66 #'test.embl' => 'embl',
68 'test.fasta' => 'fasta',
69 #'test.game' => 'game',
71 #'test.genbank' => 'genbank',
73 #'test_badlf.gcg' => 'gcg'
76 while( my ($file, $type) = each %files ) {
77 my $filename = test_input_file($file);
78 print "processing file $filename\n" if $verbose;
79 open my $FILE, '<', $filename or die "Could not read file '$filename': $!\n";
83 my $in = IO::String->new( join('', @datain) );
84 my $seqin = Bio::SeqIO->new( -fh => $in,
86 my $out = IO::String->new();
87 my $seqout = Bio::SeqIO->new( -fh => $out,
90 while( defined($seq = $seqin->next_seq) ) {
91 $seqout->write_seq($seq);
95 my $strref = $out->string_ref;
96 my @dataout = map { $_."\n"} split(/\n/, $$strref );
97 my @diffs = &diff( \@datain, \@dataout);
100 if(@diffs && $verbose) {
101 foreach my $d ( @diffs ) {
102 foreach my $diff ( @$d ) {
104 print $diff->[0], $diff->[1], "\n>", $diff->[2], "\n";
107 print "in is \n", join('', @datain), "\n";
108 print "out is \n", join('',@dataout), "\n";
113 # simple tests specific to Bio::SeqIO interface (applicable to all SeqIO
116 ##############################################
117 # test format() and variant() in Bio::RootIO
118 ##############################################
120 my $in = Bio::SeqIO->new(
121 -file => test_input_file('bug2901.fa'),
124 is $in->format, 'fasta';
125 is $in->variant, undef;
127 $in = Bio::SeqIO->new(
128 -file => test_input_file('fastq', 'illumina_faked.fastq'),
130 -variant => 'illumina',
132 is $in->format, 'fastq';
133 is $in->variant, 'illumina';
136 ######################################################
137 # test format detection from different inputs
138 ######################################################
140 $in = Bio::SeqIO->new( -file => test_input_file('test.fastq') );
141 is $in->format, 'fastq';
143 open my $fh, '<', test_input_file('test.genbank') or die "Could not read file 'test.genbank': $!\n";
144 $in = Bio::SeqIO->new( -fh => $fh );
145 is $in->format, 'genbank';
148 my $string = ">seq\nACGATCG\n";
149 $in = Bio::SeqIO->new( -string => $string );
150 is $in->format, 'fasta';
153 ############ EXCEPTION HANDLING ############
156 local $TODO = 'file/fh-based tests should be in Bio::Root::IO, see issue #3204';
159 } qr/No file, fh, or string argument provided/, 'Must pass a file or file handle';
163 Bio::SeqIO->new(-fh => undef);
164 } qr/fh argument provided, but with an undefined value/,
165 'Must pass a file or file handle';
168 Bio::SeqIO->new(-file => undef);
169 } qr/file argument provided, but with an undefined value/,
170 'Must pass a file or file handle';
173 Bio::SeqIO->new(-file => 'foo.bar');
174 } qr/Could not read file 'foo.bar':/,
175 'Must pass a real file';