fix pass-thru test count (off by one)
[bioperl-run.git] / t / EMBOSS.t
blob27f05e15276fbc8d884c88b4f5eb9b8de13eddb3
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
4 # Before `./Build install' is performed this script should be runnable with
5 # `./Build test'. After `./Build install' it should work as `perl test.t'
7 use strict;
9 BEGIN {
10     use Bio::Root::Test;
11     test_begin(
12         -tests            => 31,
13         -requires_modules => [qw(XML::Twig)]
14     );
15     use_ok('Bio::Root::IO');
16     use_ok('Bio::SeqIO');
17     use_ok('Bio::AlignIO');
18     use_ok('Bio::Factory::EMBOSS');
21 my $compseqoutfile = test_output_file();
22 my $wateroutfile   = test_output_file();
23 my $consoutfile    = test_output_file();
24 my $verbose        = test_debug();
26 ## End of black magic.
28 ## Insert additional test code below but remember to change
29 ## the print "1..x\n" in the BEGIN block to reflect the
30 ## total number of tests that will be run.
32 my $factory = Bio::Factory::EMBOSS->new();
33 ok($factory);
35 SKIP: {
36     my $compseqapp = $factory->program('compseq');
38     $factory->verbose($verbose);
40     skip( 'EMBOSS not installed', 26 ) if ! $compseqapp;
42     my $version = $factory->version;
44     my %input = (
45         -word     => 4,
46         -sequence => test_input_file('dna1.fa'),
47         -outfile  => $compseqoutfile
48     );
49     $compseqapp->run( \%input );
50     ok( -e $compseqoutfile );
52     my $water = $factory->program('water');
53     ok($water);
55     # testing in-memory use of
56     my $in = Bio::SeqIO->new(
57         -format => 'fasta',
58         -file   => test_input_file('cysprot1a.fa')
59     );
60     my $seq = $in->next_seq();
62     my @amino;
63     $in = Bio::SeqIO->new(
64         -format => 'fasta',
65         -file   => test_input_file('amino.fa')
66     );
67     while ( my $s = $in->next_seq ) {
68         push @amino, $s;
69     }
71     my %expected;
72     if ( $version ge '2.8.0' ) {
73         $water->run(
74             {   -asequence => $seq,
75                 -bsequence => \@amino,
76                 -gapopen   => '10.0',
77                 -gapextend => '0.5',
78                 -outfile   => $wateroutfile
79             }
80         );
81         %expected = (
82             'alnlen' => 394,
83             'opid'   => '30.71',
84             'apid'   => '40.20'
85         );
87     } else {
88         $water->run(
89             {   -sequencea => $seq,
90                 -seqall    => \@amino,
91                 -gapopen   => '10.0',
92                 -gapextend => '0.5',
93                 -outfile   => $wateroutfile
94             }
95         );
96         %expected = (
97             'alnlen' => 339,
98             'opid'   => '33.04',
99             'apid'   => '40.58'
100         );
102     }
103     ok( -e $wateroutfile );
105     my $alnin = Bio::AlignIO->new(
106         -format => 'emboss',
107         -file   => $wateroutfile
108     );
110     ok($alnin);
111     my $aln = $alnin->next_aln;
112     ok($aln);
113     is( $aln->length,                      43 );
114     is( $aln->overall_percentage_identity, 100 );
115     is( $aln->average_percentage_identity, 100 );
117     my ($first) = $aln->each_seq();
118     ok( $first->seq(), 'SCWSFSTTGNVEGQHFISQNKLVSLSEQNLVDCDHECMEYEGE' );
119     $aln = $alnin->next_aln;
120     ok($aln);
122     is( $aln->length, $expected{'alnlen'} );
123     is( sprintf( "%.2f", $aln->overall_percentage_identity ),
124         $expected{'opid'} );
125     is( sprintf( "%.2f", $aln->average_percentage_identity ),
126         $expected{'apid'} );
128     my $cons = $factory->program('cons');
129     $cons->verbose(0);
130     $in = Bio::AlignIO->new(
131         -format => 'msf',
132         -file   => test_input_file('cysprot.msf')
133     );
134     my $aln2 = $in->next_aln;
135     if ( $version ge '2.8.0' ) {
136         $cons->run(
137             {   -sequence => $aln2,
138                 -outseq   => $consoutfile
139             }
140         );
141     } else {
142         $cons->run(
143             {   -msf    => $aln2,
144                 -outseq => $consoutfile
145             }
146         );
147     }
148     ok( -e $consoutfile );
150     # testing acd parsing and EMBOSSacd methods
152     $compseqapp = $factory->program('compseq');
154     ok my $acd = $compseqapp->acd;
155     is $compseqapp->acd->name, 'compseq';
156     ok my $compseq_mand_acd = $compseqapp->acd->mandatory;
157     ok $compseq_mand_acd->mandatory->qualifier('-word');
158     is $compseq_mand_acd->mandatory->qualifier('-supper1'), 0;
159     is $acd->qualifier('-ppppppp'), 0;
160     ok $acd->qualifier('-reverse');
161     is $acd->category('-reverse'),  'optional';
162     like $acd->values('-reverse'),  qr/(?:Yes\/No|true)/;
163     like $acd->descr('-reverse'),   qr/(?:boolean|true)/;
164     is $acd->unnamed('-reverse'),   0;
165     like $acd->default('-reverse'), qr/(?:Yes\/No|true)/;
168 __END__
170 ## comparing input and ACD qualifiers
171 ## commented out because verbose > 1 prints error messages
172 ## that would confuse users running tests
174 $compseqapp->verbose(1);
175 %input = ( '-word' => 4,
176        '-outfile' => $compseqoutfile);
177 eval {
178     my $a = $compseqapp->run(\%input);
180 ok 1 if $@; # '-sequence' missing
182  %input = ( '-word' => 4,
183        '-incorrect_option' => 'no value',
184        '-sequence' => test_input_file('dna1.fa'),
185        '-outfile' => $compseqoutfile);
186 eval {
187     $compseqapp->run(\%input);
189 ok 1 if $@; # -incorrect_option is incorrect