Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update and modernization of GuessSeqFormat tests

  • Loading branch information...
commit 48fc1ec9fb246e6666fe6c4625c88f7b3e0d7b51 1 parent 5dea659
Florent Angly fangly authored
Showing with 86 additions and 95 deletions.
  1. +86 −95 t/SeqTools/GuessSeqFormat.t
181 t/SeqTools/GuessSeqFormat.t
View
@@ -8,122 +8,113 @@ BEGIN {
use lib '.';
use Bio::Root::Test;
- test_begin(-tests => 52);
+ test_begin(-tests => 96);
- use_ok('Bio::SeqIO');
- use_ok('Bio::AlignIO');
- use_ok('Bio::Tools::GuessSeqFormat');
+ use_ok 'Bio::Tools::GuessSeqFormat';
+ use_ok 'Bio::SeqIO';
+ use_ok 'Bio::AlignIO';
}
-my @seqformats = qw{ ace embl fasta fastq gcg genbank mase
- pfam pir raw swiss tab game};
-my $format;
+my $fmt;
+my $seq;
my $verbose = test_debug();
-#
-# Seqio formats
-#
-
-#not tested: waba
-my %no_seqio_module = map {$_=>1} qw {gcgblast gcgfasta mase pfam};
+ok my $guesser = Bio::Tools::GuessSeqFormat->new;
+isa_ok $guesser, 'Bio::Tools::GuessSeqFormat';
-my $guessed_format = Bio::Tools::GuessSeqFormat->new
- (-file => test_input_file('test.waba'))->guess;
-is $guessed_format, undef ;
-
-my $seq;
-
-eval {
- my $input = Bio::SeqIO->new
- (-file=>test_input_file('test.waba'));
- $seq = $input->next_seq();
-};
-
-ok !$seq;
-
-$@ ? ok 1 : ok 0;
-
-foreach $format (@seqformats) {
- SKIP: {
- if ($format eq 'game') {
- test_skip(-tests => 2, -requires_modules => [qw(XML::Writer XML::Parser::PerlSAX)]);
- }
-
- my $guessed_format = Bio::Tools::GuessSeqFormat->new
- (-file => test_input_file("test.$format"),
- #-verbose=> $verbose;
- )->guess;
- $format =~ s/\..*$//;
- is $guessed_format, $format, "Guessed:$format";
- next if $no_seqio_module{$format};
-
- eval {
- my $input = Bio::SeqIO->new
- (-file=>test_input_file("test.$format"));
- $seq = $input->next_seq();
- };
-
- my $implemented = $format eq 'ace' ? 'Bio::PrimarySeqI' : 'Bio::SeqI';
-
- isa_ok $seq, $implemented;
-
- is 0, 1, $@ if $@;
- }
-}
#
-# AlignIO formats
+# Test guesser interfaces
#
-@seqformats = qw{ aln:clustalw fasta fastq mase msf nexus pfam phylip
- prodom stockholm}; # not selex (same as pfam, mainly)
+# File guess
+ok $guesser = Bio::Tools::GuessSeqFormat->new(
+ -file => test_input_file('test.fasta'),
+), 'File input';
+is $guesser->guess, 'fasta';
-my %no_alignio_module = map {$_=>1} qw { fastq };
-
-foreach my $ext (@seqformats) {
- my $format;
- ($ext, $format) = split /:/, $ext;
- my $guesser = Bio::Tools::GuessSeqFormat->new
- (-file => test_input_file("testaln.$ext"));
- $format ||= $ext;
- ok $guesser->guess(), $format;
-
- next if $no_alignio_module{$format};
+# String guess
+my $string = ">test1 no comment
+agtgctagctagctagctagct
+>test2 no comment
+gtagttatgc
+";
+ok $guesser = Bio::Tools::GuessSeqFormat->new(
+ -text => $string,
+), 'String input';
+is $guesser->guess, 'fasta';
- eval {
- my $input = Bio::AlignIO->new
- (-file=>test_input_file("testaln.$ext"));
- $seq = $input->next_aln();
- };
-
- isa_ok $seq, 'Bio::Align::AlignI';
- #ok 0, 1, $@ if $@;
+# Filehandle guess
+SKIP: {
+ test_skip(-tests => 2, -requires_modules => [qw(IO::String)]);
+ require IO::String;
+ my $fh = IO::String->new($string);
+ ok $guesser = Bio::Tools::GuessSeqFormat->new(
+ -text => $string,
+ ), 'Filehandle input';
+ is $guesser->guess, 'fasta';
}
#
-# File handle tests
+# Test SeqIO formats
#
-SKIP: {
- test_skip(-tests => 3, -requires_modules => [qw(IO::String)]);
-
- my $string = ">test1 no comment
-agtgctagctagctagctagct
->test2 no comment
-gtagttatgc
-";
- my $stringfh = new IO::String($string);
-
- my $seqio = Bio::SeqIO->new(-fh => $stringfh);
- while( my $seq = $seqio->next_seq ) {
- ok $seq->id =~ /test/;
+# waba is not guessed
+is $guesser = Bio::Tools::GuessSeqFormat->new(
+ -file => test_input_file('test.waba'),
+)->guess, undef;
+
+throws_ok {
+ Bio::SeqIO->new( -file=>test_input_file('test.waba') );
+} qr/Could not guess format/;
+
+# other seq formats
+my @fmts = qw{ace embl fasta fastq gcg genbank mase pfam pir raw swiss tab game};
+my %skip_module = map {$_=>1} qw {gcgblast gcgfasta mase pfam};
+
+for $fmt (@fmts) {
+ SKIP: {
+ test_skip(
+ -tests => 4,
+ -requires_modules => [qw(XML::Writer XML::Parser::PerlSAX)]
+ ) if $fmt eq 'game';
+
+ my $guess = Bio::Tools::GuessSeqFormat->new(
+ -file => test_input_file("test.$fmt"),
+ #-verbose=> $verbose;
+ )->guess;
+ is $guess, $fmt, "$fmt format";
+ next if $skip_module{$fmt};
+
+ ok my $input = Bio::SeqIO->new( -file=>test_input_file("test.$fmt") );
+ ok $seq = $input->next_seq();
+ isa_ok $seq, 'Bio::PrimarySeqI';
}
-
+}
+
+
#
-# text guessing
+# Test AlignIO formats
#
- ok new Bio::Tools::GuessSeqFormat( -text => $string )->guess, 'fasta';
+@fmts = qw{ aln:clustalw fasta fastq mase msf nexus pfam phylip prodom stockholm};
+# not selex (same as pfam, mainly)
+%skip_module = map {$_=>1} qw { fastq };
+
+for my $ext (@fmts) {
+ ($ext, my $fmt) = split /:/, $ext;
+ $fmt ||= $ext;
+
+ my $guess = Bio::Tools::GuessSeqFormat->new(
+ -file => test_input_file("testaln.$ext")
+ )->guess;
+ is $guess, $fmt;
+ next if $skip_module{$fmt};
+
+ ok my $input = Bio::AlignIO->new( -file=>test_input_file("testaln.$ext") );
+ ok $seq = $input->next_aln();
+ isa_ok $seq, 'Bio::Align::AlignI';
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.