Fix tests; need to look at Analysis::soap::results()
[bioperl-run.git] / t / EMBOSS.t
blob21e7e56aa8069ecd6f954d98c6f3fb52e69c785b
2 # -*-Perl-*-
3 ## Bioperl Test Harness Script for Modules
4 ## $Id$
6 # Before `make install' is performed this script should be runnable with
7 # `make test'. After `make install' it should work as `perl test.t'
9 use strict;
10 use vars qw($error $NTESTS);
11 BEGIN {
12     $error = 0;
13     # to handle systems with no installed Test module
14     # we include the t dir (where a copy of Test.pm is located)
15     # as a fallback
16     eval { require Test; };
17     if( $@ ) {
18         use lib 't';
19     }
20     use Test;
21     $NTESTS = 30;
22     plan tests => $NTESTS;
23     eval { 
24      require XML::Twig;
25      require Bio::EMBOSS::Factory;
26     };
27     if( $@ ) {
28      $error = 1;
29     }
30  }
32 use Bio::Root::IO;
33 use Bio::SeqIO;
34 use Bio::AlignIO;
35 my $compseqoutfile = 'dna1.4.compseq';
36 my $wateroutfile   = 'cysprot.water';
37 my $consoutfile    = 'cysprot.cons';
38 END {
39     foreach ( $Test::ntest..$NTESTS ) {
40         skip("EMBOSS not installed locally or XML::Twig not installed",1);
41     }
42     unlink($compseqoutfile);
43     unlink($wateroutfile);
44     unlink($consoutfile);
46 exit(0) if $error;
47 my $verbose = $ENV{'BIOPERLDEBUG'} || -1;
48 ok(1);
50 ## End of black magic.
52 ## Insert additional test code below but remember to change
53 ## the print "1..x\n" in the BEGIN block to reflect the
54 ## total number of tests that will be run.
56 my $factory = new Bio::Factory::EMBOSS(-verbose => $verbose);
57 ok($factory);
58 my $compseqapp = $factory->program('compseq');
59 exit if( $compseqapp->executable ) ;
61 my $version = $factory->version;
63 if( ! $compseqapp ) { 
64     # no EMBOSS installed
65     exit(0);
68 ok($compseqapp);
69 my %input = ( '-word' => 4,
70               '-sequence' => Bio::Root::IO->catfile('t',
71                                                    'data',
72                                                    'dna1.fa'),
73               '-outfile' => $compseqoutfile);
74 $compseqapp->run(\%input);
75 ok(-e $compseqoutfile);
76 #if( open(IN, $compseqoutfile) ) {
77 #    while(<IN>) { print }
80 my $water = $factory->program('water');
82 ok ($water);
84 # testing in-memory use of 
85 my $in = new Bio::SeqIO(-format => 'fasta',
86                         -file =>  Bio::Root::IO->catfile('t',
87                                                          'data',
88                                                          'cysprot1a.fa'));
89 my $seq = $in->next_seq();
90 ok($seq);
91 my @amino;
92 $in = new Bio::SeqIO(-format => 'fasta',
93                      -file =>  Bio::Root::IO->catfile('t',
94                                                       'data',
95                                                       'amino.fa'));
96 while( my $s = $in->next_seq) {
97     push @amino, $s;
100 my %expected;
101 if( $version ge '2.8.0' ) {
102     $water->run({ '-asequence' => $seq,
103                   '-bsequence'    => \@amino,
104                   '-gapopen'   => '10.0',
105                   '-gapextend' => '0.5',
106                   '-outfile'   => $wateroutfile});
107     %expected = ( 'alnlen' => 394,
108                   'opid'    => '30.71',
109                   'apid'    => '40.20');
110                   
111 } else {
112     $water->run({ '-sequencea' => $seq,
113                   '-seqall'    => \@amino,
114                   '-gapopen'   => '10.0',
115                   '-gapextend' => '0.5',
116                   '-outfile'   => $wateroutfile});
117     %expected = ( 'alnlen' => 339,
118                   'opid'    => '33.04',
119                   'apid'    => '40.58');
122 ok(-e $wateroutfile);
124 my $alnin = new Bio::AlignIO(-format => 'emboss',
125                             -file   => $wateroutfile);
127 ok( $alnin);
128 my $aln = $alnin->next_aln;
129 ok($aln);
130 ok($aln->length, 43);
131 ok($aln->overall_percentage_identity, 100);
132 ok($aln->average_percentage_identity, 100);
134 my ($first) = $aln->each_seq();
135 ok($first->seq(), 'SCWSFSTTGNVEGQHFISQNKLVSLSEQNLVDCDHECMEYEGE');
136 $aln = $alnin->next_aln;
137 ok($aln);
139 ok($aln->length, $expected{'alnlen'});
140 ok(sprintf("%.2f",$aln->overall_percentage_identity), $expected{'opid'});
141 ok(sprintf("%.2f",$aln->average_percentage_identity), $expected{'apid'});
144 my $cons = $factory->program('cons');
145 $cons->verbose(0);
146 $in = new Bio::AlignIO(-format => 'msf',
147                        -file   => Bio::Root::IO->catfile('t',
148                                                          'data',
149                                                          'cysprot.msf'));
150 my $aln2 = $in->next_aln;
151 if( $version ge '2.8.0' ) {
152     $cons->run({ '-sequence' => $aln2,
153                  '-outseq'   => $consoutfile});
154 } else {
155     $cons->run({ '-msf'   => $aln2,
156                  '-outseq'=> $consoutfile});
158 ok(-e $consoutfile);
161 # testing acd parsing and EMBOSSacd methods
163 $compseqapp = $factory->program('compseq');
165 exit unless $compseqapp->acd;
166 ok my $acd = $compseqapp->acd;
167 ok $compseqapp->acd->name, 'compseq';
168 ok my $compseq_mand_acd = $compseqapp->acd->mandatory;
169 ok $compseq_mand_acd->mandatory->qualifier('-word');
170 ok $compseq_mand_acd->mandatory->qualifier('-supper1'), 0;
171 ok $acd->qualifier('-ppppppp'), 0;
172 ok $acd->qualifier('-reverse');
173 ok $acd->category('-reverse'), 'optional';
174 ok $acd->values('-reverse'), qr/Yes\/No/;
175 ok $acd->descr('-reverse'), 'Set this to be true if you also wish to also count words in the reverse complement of a nucleic sequence.';
176 ok $acd->unnamed('-reverse'), 0;
177 ok $acd->default('-reverse'), 'No';
179 ## comparing input and ACD qualifiers
180 ## commented out because verbose > 1 prints error messages
181 ## that would confuse users running tests
183 #$compseqapp->verbose(1);
184 #%input = ( '-word' => 4,
185 #          '-outfile' => $compseqoutfile);
186 #eval {
187 #    my $a = $compseqapp->run(\%input);
189 #ok 1 if $@; # '-sequence' missing
191 #%input = ( '-word' => 4,
192 #          '-incorrect_option' => 'no value',
193 #          '-sequence' => Bio::Root::IO->catfile('t',
194 #                                                'data',
195 #                                                'dna1.fa'),
196 #          '-outfile' => $compseqoutfile);
197 #eval {
198 #    $compseqapp->run(\%input);
200 #ok 1 if $@; # -incorrect_option is incorrect