Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed missing detection of format in SeqIO when given a -string

  • Loading branch information...
commit f4ff43f0531e0433baf63234a5b6e122fe38f698 1 parent edf561c
@fangly fangly authored
Showing with 44 additions and 27 deletions.
  1. +4 −3 Bio/SeqIO.pm
  2. +1 −0  Changes
  3. +39 −24 t/SeqIO/SeqIO.t
View
7 Bio/SeqIO.pm
@@ -396,13 +396,14 @@ sub new {
# Guess from filename extension
$format = $class->_guess_format( $param{-file} );
}
-
if (! $format ) {
# Guess from content
if ($param{-file}) {
- $format = Bio::Tools::GuessSeqFormat->new(-file => $param{-file})->guess;
+ $format = Bio::Tools::GuessSeqFormat->new(-file => $param{-file} )->guess;
} elsif ($param{-fh}) {
- $format = Bio::Tools::GuessSeqFormat->new(-fh => $param{-fh})->guess;
+ $format = Bio::Tools::GuessSeqFormat->new(-fh => $param{-fh} )->guess;
+ } elsif ($param{-string}) {
+ $format = Bio::Tools::GuessSeqFormat->new(-text => $param{-string})->guess;
}
}
View
1  Changes
@@ -82,6 +82,7 @@ CPAN releases are branched from 'master'.
* Fixed tests failing in Windows because of using Linux commands [fjossandon]
* Closed many open filehandles that prevented temporary files deletion [fjossandon]
* Fixed broken MeSH parser [fjossandon]
+ * Fixed missing detection of format in SeqIO when given a -string [fangly]
1.6.923
View
63 t/SeqIO/SeqIO.t
@@ -7,9 +7,9 @@ BEGIN {
use lib '.';
use Bio::Root::Test;
- test_begin(-tests => 55);
+ test_begin(-tests => 58);
- use_ok('Bio::SeqIO');
+ use_ok 'Bio::SeqIO';
}
my $verbose = test_debug();
@@ -17,18 +17,13 @@ my $verbose = test_debug();
my @formats = qw(gcg fasta raw pir tab ace );
# The following files or formats are failing: swiss genbank interpro embl
-foreach my $format (@formats) {
+for 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);
+ my $str = Bio::SeqIO->new( -file => test_input_file("test.$format"),
+ -format => $format );
- is $str->format(), $format;
+ is $str->format(), $format;
ok $seq = $str->next_seq();
print "Sequence 1 of 2 from $format stream:\n", $seq->seq, "\n\n" if $verbose;
@@ -43,8 +38,8 @@ sub read_write {
}
my $outfile = test_output_file();
- my $out = Bio::SeqIO->new(-file => ">$outfile",
- -format => $format);
+ my $out = Bio::SeqIO->new( -file => ">$outfile",
+ -format => $format );
ok $out->write_seq($seq);
if ($format eq 'fasta') {
my $id_type;
@@ -55,15 +50,17 @@ sub read_write {
ok -s $outfile;
}
+
+
# from testformats.pl
SKIP: {
test_skip(-tests => 6, -requires_modules => [qw(Algorithm::Diff
IO::ScalarArray
IO::String)]);
- use_ok('Algorithm::Diff');
+ use_ok 'Algorithm::Diff';
eval "use Algorithm::Diff qw(diff LCS);";
- use_ok('IO::ScalarArray');
- use_ok('IO::String');
+ use_ok 'IO::ScalarArray';
+ use_ok 'IO::String';
my %files = (
#'test.embl' => 'embl',
@@ -79,17 +76,17 @@ SKIP: {
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");
+ open(FILE, "< $filename") or die("Could not 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 $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->write_seq($seq);
}
$seqout->close();
$seqin->close();
@@ -133,6 +130,24 @@ $in = Bio::SeqIO->new(
is $in->format, 'fastq';
is $in->variant, 'illumina';
+
+######################################################
+# test format detection from different inputs
+######################################################
+
+$in = Bio::SeqIO->new( -file => test_input_file('test.fastq') );
+is $in->format, 'fastq';
+
+open my $fh, '<', test_input_file('test.genbank');
+$in = Bio::SeqIO->new( -fh => $fh );
+is $in->format, 'genbank';
+close $fh;
+
+my $string = ">seq\nACGATCG\n";
+$in = Bio::SeqIO->new( -string => $string );
+is $in->format, 'fasta';
+
+
############ EXCEPTION HANDLING ############
TODO: {
Please sign in to comment.
Something went wrong with that request. Please try again.