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 113 114 115 116 117 118 119 120 121
|
# -*-Perl-*- mode (to keep my emacs happy)
# $Id: GuessSeqFormat.t,v 1.3 2003/12/10 22:43:26 heikki Exp $
# test for Bio::Tools::GuessSeqFormat
# written by Heikki Lehvaslaiho
use strict;
my $NUMTESTS;
BEGIN {
eval { require Test; };
if( $@ ) {
use lib 't','..';
}
use Test;
$NUMTESTS = 46;
plan tests => $NUMTESTS;
}
use Bio::SeqIO;
use Bio::AlignIO;
use Bio::Tools::GuessSeqFormat;
use Data::Dumper;
ok 1;
my $format;
my $verbose =1;
#
# Seqio formats
#
#not tested: waba
my @seqformats = qw{ ace embl fasta game gcg
genbank mase pfam pir raw swiss tab };
my %no_seqio_module = map {$_=>1} qw {gcgblast gcgfasta mase pfam};
my $guessed_format = new Bio::Tools::GuessSeqFormat
(-file => Bio::Root::IO->catfile("t","data","test.waba"))->guess;
ok $guessed_format, undef ;
eval {
my $input = Bio::SeqIO->new
(-file=>Bio::Root::IO->catfile("t","data","test.waba"));
ok my $seq = $input->next_seq();
};
$@ ? ok 1 : ok 0;
foreach $format (@seqformats) {
my $guessed_format = new Bio::Tools::GuessSeqFormat
(-file => Bio::Root::IO->catfile("t","data","test.$format"),
#-verbose=> $verbose;
)->guess;
$format =~ s/\..*$//;
ok $guessed_format, $format;
next if $no_seqio_module{$format};
eval {
my $input = Bio::SeqIO->new
(-file=>Bio::Root::IO->catfile("t","data","test.$format"));
ok my $seq = $input->next_seq();
};
ok 0, 1, $@ if $@;
}
#
# AlignIO formats
#
@seqformats = qw{ aln:clustalw fasta mase msf nexus pfam phylip
prodom stockholm}; # not selex (same as pfam, mainly)
my %no_alignio_module = map {$_=>1} qw {};
foreach my $ext (@seqformats) {
my $format;
($ext, $format) = split /:/, $ext;
my $guesser = new Bio::Tools::GuessSeqFormat
(-file => Bio::Root::IO->catfile("t","data","testaln.$ext"));
$format ||= $ext;
ok $guesser->guess(), $format;
next if $no_alignio_module{$format};
eval {
my $input = Bio::AlignIO->new
(-file=>Bio::Root::IO->catfile("t","data","testaln.$ext"));
ok my $seq = $input->next_aln();
};
ok 0, 1, $@ if $@;
}
#
# File handle tests
#
use IO::String;
my $string = ">test1 no comment
agtgctagctagctagctagct
>test2 no comment
gtagttatgc
";
my $stringfh = new IO::String($string);
my $seqio = new Bio::SeqIO(-fh => $stringfh);
while( my $seq = $seqio->next_seq ) {
ok $seq->id =~ /test/;
}
#
# text guessing
#
ok new Bio::Tools::GuessSeqFormat( -text => $string )->guess, 'fasta';
|