~ubuntu-branches/ubuntu/oneiric/bioperl/oneiric

« back to all changes in this revision

Viewing changes to t/GuessSeqFormat.t

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*-Perl-*- mode (to keep my emacs happy)
 
2
# $Id: GuessSeqFormat.t,v 1.3 2003/12/10 22:43:26 heikki Exp $
 
3
 
 
4
# test for Bio::Tools::GuessSeqFormat
 
5
# written by Heikki Lehvaslaiho
 
6
 
 
7
use strict;
 
8
my $NUMTESTS;
 
9
 
 
10
BEGIN {
 
11
    eval { require Test; };
 
12
    if( $@ ) {
 
13
        use lib 't','..';
 
14
    }
 
15
    use Test;
 
16
    $NUMTESTS = 46;
 
17
    plan tests => $NUMTESTS;
 
18
 
 
19
}
 
20
 
 
21
use Bio::SeqIO;
 
22
use Bio::AlignIO;
 
23
use Bio::Tools::GuessSeqFormat;
 
24
use Data::Dumper;
 
25
 
 
26
ok 1;
 
27
 
 
28
my $format;
 
29
my $verbose =1;
 
30
#
 
31
# Seqio formats
 
32
#
 
33
 
 
34
#not tested:  waba 
 
35
my @seqformats = qw{ ace embl fasta game gcg 
 
36
                     genbank mase  pfam pir raw swiss tab };
 
37
 
 
38
my %no_seqio_module = map {$_=>1} qw {gcgblast gcgfasta mase pfam};
 
39
 
 
40
my $guessed_format = new Bio::Tools::GuessSeqFormat
 
41
        (-file => Bio::Root::IO->catfile("t","data","test.waba"))->guess;
 
42
ok $guessed_format, undef ;
 
43
 
 
44
eval {
 
45
    my $input = Bio::SeqIO->new
 
46
        (-file=>Bio::Root::IO->catfile("t","data","test.waba"));
 
47
    ok my $seq = $input->next_seq();
 
48
};
 
49
$@ ? ok 1 : ok 0;
 
50
 
 
51
foreach $format (@seqformats) {
 
52
    my $guessed_format = new Bio::Tools::GuessSeqFormat
 
53
        (-file => Bio::Root::IO->catfile("t","data","test.$format"),
 
54
         #-verbose=> $verbose;
 
55
        )->guess;
 
56
    $format =~ s/\..*$//;
 
57
    ok $guessed_format, $format;
 
58
    next if $no_seqio_module{$format};
 
59
 
 
60
    eval {
 
61
        my $input = Bio::SeqIO->new
 
62
            (-file=>Bio::Root::IO->catfile("t","data","test.$format"));
 
63
        ok my $seq = $input->next_seq();
 
64
    };
 
65
    ok 0, 1, $@ if $@;
 
66
}
 
67
 
 
68
 
 
69
#
 
70
# AlignIO formats
 
71
#
 
72
 
 
73
@seqformats = qw{ aln:clustalw fasta mase msf nexus pfam phylip
 
74
                  prodom stockholm}; # not selex (same as pfam, mainly)
 
75
 
 
76
my %no_alignio_module = map {$_=>1} qw {};
 
77
 
 
78
foreach my $ext (@seqformats) {
 
79
    my $format;
 
80
    ($ext, $format) = split /:/, $ext;
 
81
    my $guesser = new Bio::Tools::GuessSeqFormat
 
82
        (-file => Bio::Root::IO->catfile("t","data","testaln.$ext"));
 
83
    $format ||= $ext;
 
84
    ok $guesser->guess(), $format;
 
85
 
 
86
    next if $no_alignio_module{$format};
 
87
 
 
88
    eval {
 
89
        my $input = Bio::AlignIO->new
 
90
            (-file=>Bio::Root::IO->catfile("t","data","testaln.$ext"));
 
91
        ok my $seq = $input->next_aln();
 
92
    };
 
93
    ok 0, 1, $@ if $@;
 
94
 
 
95
}
 
96
 
 
97
 
 
98
#
 
99
# File handle tests
 
100
#
 
101
 
 
102
use IO::String;
 
103
 
 
104
my $string = ">test1 no comment
 
105
agtgctagctagctagctagct
 
106
>test2 no comment
 
107
gtagttatgc
 
108
";
 
109
 
 
110
my $stringfh = new IO::String($string);
 
111
 
 
112
my $seqio = new Bio::SeqIO(-fh => $stringfh);
 
113
while( my $seq = $seqio->next_seq ) {
 
114
    ok $seq->id =~ /test/;
 
115
}
 
116
 
 
117
#
 
118
# text guessing
 
119
#
 
120
 
 
121
ok new Bio::Tools::GuessSeqFormat( -text => $string )->guess, 'fasta';