Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / t / EMBOSS.t
blob5e95f71e35dfd18ac912e31a14add4ebf5a96435
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;
8 BEGIN {
9     use Bio::Root::Test;
10     test_begin(-tests => 32,
11                            -requires_modules => [qw(XML::Twig)]);
12         use_ok('Bio::Root::IO');
13         use_ok('Bio::SeqIO');
14         use_ok('Bio::AlignIO');
15         use_ok('Bio::Factory::EMBOSS');
18 my $compseqoutfile = test_output_file();
19 my $wateroutfile   = test_output_file();
20 my $consoutfile    = test_output_file();
21 my $verbose = test_debug();
23 ## End of black magic.
25 ## Insert additional test code below but remember to change
26 ## the print "1..x\n" in the BEGIN block to reflect the
27 ## total number of tests that will be run.
29 my $factory = Bio::Factory::EMBOSS->new();
30 ok($factory);
32 SKIP: {
33         my $compseqapp = $factory->program('compseq');
34         
35     $factory->verbose($verbose);
36     
37         skip('EMBOSS not installed',27) if !$compseqapp;
38         
39         my $version = $factory->version;
40         
41         my %input = ( '-word' => 4,
42                           '-sequence' => test_input_file('dna1.fa'),
43                           '-outfile' => $compseqoutfile);
44         $compseqapp->run(\%input);
45         ok(-e $compseqoutfile);
46         
47         my $water = $factory->program('water');
48         
49         ok ($water);
50         
51         # testing in-memory use of 
52         my $in = Bio::SeqIO->new(-format => 'fasta',
53                                 -file =>  test_input_file('cysprot1a.fa'));
54         my $seq = $in->next_seq();
55         ok($seq);
56         my @amino;
57         $in = Bio::SeqIO->new(-format => 'fasta',
58                                  -file =>  test_input_file('amino.fa'));
59         while( my $s = $in->next_seq) {
60                 push @amino, $s;
61         }
62         
63         my %expected;
64         if( $version ge '2.8.0' ) {
65                 $water->run({ '-asequence' => $seq,
66                           '-bsequence'    => \@amino,
67                           '-gapopen'   => '10.0',
68                           '-gapextend' => '0.5',
69                           '-outfile'   => $wateroutfile});
70                 %expected = ( 'alnlen' => 394,
71                           'opid'    => '30.71',
72                           'apid'    => '40.20');
73                           
74         } else {
75                 $water->run({ '-sequencea' => $seq,
76                           '-seqall'    => \@amino,
77                           '-gapopen'   => '10.0',
78                           '-gapextend' => '0.5',
79                           '-outfile'   => $wateroutfile});
80                 %expected = ( 'alnlen' => 339,
81                           'opid'    => '33.04',
82                           'apid'    => '40.58');
83         
84         }
85         ok(-e $wateroutfile);
86         
87         my $alnin = Bio::AlignIO->new(-format => 'emboss',
88                                         -file   => $wateroutfile);
89         
90         ok( $alnin);
91         my $aln = $alnin->next_aln;
92         ok($aln);
93         is($aln->length, 43);
94         is($aln->overall_percentage_identity, 100);
95         is($aln->average_percentage_identity, 100);
96         
97         my ($first) = $aln->each_seq();
98         ok($first->seq(), 'SCWSFSTTGNVEGQHFISQNKLVSLSEQNLVDCDHECMEYEGE');
99         $aln = $alnin->next_aln;
100         ok($aln);
101         
102         is($aln->length, $expected{'alnlen'});
103         is(sprintf("%.2f",$aln->overall_percentage_identity), $expected{'opid'});
104         is(sprintf("%.2f",$aln->average_percentage_identity), $expected{'apid'});
105         
106         
107         my $cons = $factory->program('cons');
108         $cons->verbose(0);
109         $in = Bio::AlignIO->new(-format => 'msf',
110                                    -file   => test_input_file('cysprot.msf'));
111         my $aln2 = $in->next_aln;
112         if( $version ge '2.8.0' ) {
113                 $cons->run({ '-sequence' => $aln2,
114                          '-outseq'   => $consoutfile});
115         } else {
116                 $cons->run({ '-msf'   => $aln2,
117                          '-outseq'=> $consoutfile});
118         }
119         ok(-e $consoutfile);
120         
121         # testing acd parsing and EMBOSSacd methods
122         
123         $compseqapp = $factory->program('compseq');
124         
125         ok my $acd = $compseqapp->acd;
126         is $compseqapp->acd->name, 'compseq';
127         ok my $compseq_mand_acd = $compseqapp->acd->mandatory;
128         ok $compseq_mand_acd->mandatory->qualifier('-word');
129         is $compseq_mand_acd->mandatory->qualifier('-supper1'), 0;
130         is $acd->qualifier('-ppppppp'), 0;
131         ok $acd->qualifier('-reverse');
132         is $acd->category('-reverse'), 'optional';
133         like $acd->values('-reverse'), qr/(?:Yes\/No|true)/;
134         like $acd->descr('-reverse'), qr/(?:boolean|true)/;
135         is $acd->unnamed('-reverse'), 0;
136         like $acd->default('-reverse'), qr/(?:Yes\/No|true)/;
139 __END__
141 ## comparing input and ACD qualifiers
142 ## commented out because verbose > 1 prints error messages
143 ## that would confuse users running tests
145 $compseqapp->verbose(1);
146 %input = ( '-word' => 4,
147        '-outfile' => $compseqoutfile);
148 eval {
149     my $a = $compseqapp->run(\%input);
151 ok 1 if $@; # '-sequence' missing
153  %input = ( '-word' => 4,
154        '-incorrect_option' => 'no value',
155        '-sequence' => test_input_file('dna1.fa'),
156        '-outfile' => $compseqoutfile);
157 eval {
158     $compseqapp->run(\%input);
160 ok 1 if $@; # -incorrect_option is incorrect