maint: remove Travis stuff which has been replaced with Github actions (#325)
[bioperl-live.git] / t / SeqTools / GuessSeqFormat.t
blobefe277a7fe6574143c84ecb85577460d0350cf51
1 # -*-Perl-*- Test Harness script for Bioperl
2 # $Id$
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8    
9     test_begin(-tests => 105);
10    
11     use_ok 'Bio::Tools::GuessSeqFormat';
12     use_ok 'Bio::SeqIO';
13     use_ok 'Bio::AlignIO';
17 ok my $guesser = Bio::Tools::GuessSeqFormat->new;
18 isa_ok $guesser, 'Bio::Tools::GuessSeqFormat';
22 # Test guesser interfaces
25 # 1/ File guess
26 ok $guesser = Bio::Tools::GuessSeqFormat->new(
27     -file => test_input_file('test.fasta'),
28 ), 'File input';
29 is $guesser->guess, 'fasta';
31 # 2/ String guess
32 my $string = ">test1 no comment
33 agtgctagctagctagctagct
34 >test2 no comment
35 gtagttatgc
37 ok $guesser = Bio::Tools::GuessSeqFormat->new(
38     -text => $string,
39 ), 'String input';
40 is $guesser->guess, 'fasta';
42 # 3/ Filehandle guess
43 SKIP: {
44     test_skip(-tests => 2, -requires_modules => [qw(IO::String)]);
45     require IO::String;
46     my $fh = IO::String->new($string);
47     ok $guesser = Bio::Tools::GuessSeqFormat->new(
48         -fh => $fh,
49     ), 'Filehandle input';
50     is $guesser->guess, 'fasta';
55 # Test behavior with unknown format
58 is $guesser = Bio::Tools::GuessSeqFormat->new(
59     -file => test_input_file('test.waba'), # Bio::SearchIO::waba
60 )->guess, undef, 'Unknown file format';
62 throws_ok {
63     Bio::SeqIO->new( -file=>test_input_file('test.waba') );
64 } qr/Could not guess format/;
68 # Test SeqIO formats
71 my @fmts = qw{ace embl fasta fastq game gcg genbank pir raw swiss tab};
73 for my $fmt (@fmts) {
74     SKIP: {
75         test_skip(
76             -tests => 4,
77             -requires_modules => [qw(XML::Writer XML::Parser::PerlSAX)]
78         ) if $fmt eq 'game';
79         test_skip(
80             -tests => 4,
81             -requires_module  => 'Data::Stag'
82         ) if $fmt eq 'swiss';
84         my $guess = Bio::Tools::GuessSeqFormat->new(
85             -file => test_input_file("test.$fmt"),
86         )->guess;
87         is $guess, $fmt, "$fmt format";
89         ok my $input = Bio::SeqIO->new( -file=>test_input_file("test.$fmt") );
90         ok my $seq = $input->next_seq();
91         isa_ok $seq, 'Bio::PrimarySeqI';
92     }
97 # Test AlignIO formats
100 @fmts = qw{clustalw fasta fastq mase mega msf nexus pfam phylip prodom selex};
102 ## Instead of this, we should instead have a mock of those modules.
103 ## Two reasons: 1) this modules are dependent on ourselves so this
104 ## tests will only be triggered when updating. 2) it's not really our
105 ## job to check if the other module reads file correctly, we just need
106 ## to ensure that it's called to read the file.
107 SKIP: {
108     test_skip(-tests => 4,
109               -requires_modules => ['Bio::AlignIO::stockholm']);
110     push(@fmts, 'stockholm');
114 my %skip_module = map {$_=>1} qw{ fastq };
116 for my $fmt (@fmts) {
117     my $guess = Bio::Tools::GuessSeqFormat->new(
118         -file => test_input_file("testaln.$fmt")
119     )->guess;
120     is $guess, $fmt, "$fmt format";
121     next if $skip_module{$fmt};
123     ok my $input = Bio::AlignIO->new( -file=>test_input_file("testaln.$fmt") );
124     ok my $seq = $input->next_aln();
125     isa_ok $seq, 'Bio::Align::AlignI';
130 # Other formats
133 my %fmts = (
134    blast    => test_input_file('blastp2215.blast'),
135    gcgblast => test_input_file('test.gcgblast'),
136    vcf      => test_input_file('example.vcf'),
139 while (my ($fmt, $file) = each %fmts) {
140     my $guess = Bio::Tools::GuessSeqFormat->new(
141         -file => $file,
142     )->guess;
143     is $guess, $fmt, "$fmt format";