use safe_parse (deafferret++); tests now run, but fail with EMBOSS 6.2.0
[bioperl-run.git] / t / EMBOSS.t
blobab448eb13318dec5d200e8084b2984cc2a64602c
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
3 ## $Id$
5 # Before `make install' is performed this script should be runnable with
6 # `make test'. After `make install' it should work as `perl test.t'
8 use strict;
9 BEGIN {
10     use Bio::Root::Test;
11     test_begin(-tests => 31,
12                            -requires_modules => [qw(XML::Twig Bio::Factory::EMBOSS)]);
13         use_ok('Bio::Root::IO');
14         use_ok('Bio::SeqIO');
15         use_ok('Bio::AlignIO');
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(-verbose => $verbose);
30 ok($factory);
32 SKIP: {
33         my $compseqapp = $factory->program('compseq');
34         
35         skip('EMBOSS not installed',27) if !$compseqapp;
36         
37         my $version = $factory->version;
38         
39         my %input = ( '-word' => 4,
40                           '-sequence' => test_input_file('dna1.fa'),
41                           '-outfile' => $compseqoutfile);
42         $compseqapp->run(\%input);
43         ok(-e $compseqoutfile);
44         
45         my $water = $factory->program('water');
46         
47         ok ($water);
48         
49         # testing in-memory use of 
50         my $in = Bio::SeqIO->new(-format => 'fasta',
51                                 -file =>  test_input_file('cysprot1a.fa'));
52         my $seq = $in->next_seq();
53         ok($seq);
54         my @amino;
55         $in = Bio::SeqIO->new(-format => 'fasta',
56                                  -file =>  test_input_file('amino.fa'));
57         while( my $s = $in->next_seq) {
58                 push @amino, $s;
59         }
60         
61         my %expected;
62         if( $version ge '2.8.0' ) {
63                 $water->run({ '-asequence' => $seq,
64                           '-bsequence'    => \@amino,
65                           '-gapopen'   => '10.0',
66                           '-gapextend' => '0.5',
67                           '-outfile'   => $wateroutfile});
68                 %expected = ( 'alnlen' => 394,
69                           'opid'    => '30.71',
70                           'apid'    => '40.20');
71                           
72         } else {
73                 $water->run({ '-sequencea' => $seq,
74                           '-seqall'    => \@amino,
75                           '-gapopen'   => '10.0',
76                           '-gapextend' => '0.5',
77                           '-outfile'   => $wateroutfile});
78                 %expected = ( 'alnlen' => 339,
79                           'opid'    => '33.04',
80                           'apid'    => '40.58');
81         
82         }
83         ok(-e $wateroutfile);
84         
85         my $alnin = Bio::AlignIO->new(-format => 'emboss',
86                                         -file   => $wateroutfile);
87         
88         ok( $alnin);
89         my $aln = $alnin->next_aln;
90         ok($aln);
91         is($aln->length, 43);
92         is($aln->overall_percentage_identity, 100);
93         is($aln->average_percentage_identity, 100);
94         
95         my ($first) = $aln->each_seq();
96         ok($first->seq(), 'SCWSFSTTGNVEGQHFISQNKLVSLSEQNLVDCDHECMEYEGE');
97         $aln = $alnin->next_aln;
98         ok($aln);
99         
100         is($aln->length, $expected{'alnlen'});
101         is(sprintf("%.2f",$aln->overall_percentage_identity), $expected{'opid'});
102         is(sprintf("%.2f",$aln->average_percentage_identity), $expected{'apid'});
103         
104         
105         my $cons = $factory->program('cons');
106         $cons->verbose(0);
107         $in = Bio::AlignIO->new(-format => 'msf',
108                                    -file   => test_input_file('cysprot.msf'));
109         my $aln2 = $in->next_aln;
110         if( $version ge '2.8.0' ) {
111                 $cons->run({ '-sequence' => $aln2,
112                          '-outseq'   => $consoutfile});
113         } else {
114                 $cons->run({ '-msf'   => $aln2,
115                          '-outseq'=> $consoutfile});
116         }
117         ok(-e $consoutfile);
118         
119         # testing acd parsing and EMBOSSacd methods
120         
121         $compseqapp = $factory->program('compseq');
122         
123         ok my $acd = $compseqapp->acd;
124         is $compseqapp->acd->name, 'compseq';
125         ok my $compseq_mand_acd = $compseqapp->acd->mandatory;
126         ok $compseq_mand_acd->mandatory->qualifier('-word');
127         is $compseq_mand_acd->mandatory->qualifier('-supper1'), 0;
128         is $acd->qualifier('-ppppppp'), 0;
129         ok $acd->qualifier('-reverse');
130         is $acd->category('-reverse'), 'optional';
131         like $acd->values('-reverse'), qr/Yes\/No/;
132         is $acd->descr('-reverse'), 'Set this to be true if you also wish to also count words in the reverse complement of a nucleic sequence.';
133         is $acd->unnamed('-reverse'), 0;
134         is $acd->default('-reverse'), 'No';
137         __END__
138         
139         ## comparing input and ACD qualifiers
140         ## commented out because verbose > 1 prints error messages
141         ## that would confuse users running tests
142         
143         $compseqapp->verbose(1);
144         %input = ( '-word' => 4,
145                    '-outfile' => $compseqoutfile);
146         eval {
147                 my $a = $compseqapp->run(\%input);
148         };
149         ok 1 if $@; # '-sequence' missing
150         
151          %input = ( '-word' => 4,
152                    '-incorrect_option' => 'no value',
153                    '-sequence' => test_input_file('dna1.fa'),
154                    '-outfile' => $compseqoutfile);
155         eval {
156                 $compseqapp->run(\%input);
157         };
158         ok 1 if $@; # -incorrect_option is incorrect