tests pass, find the right nodes more explicitly
[bioperl-run.git] / t / PAML.t
blob933c5dbb364ab3b25bc043a2cf5b172d61554816
1 # This is -*-Perl-*- code
2 ## Bioperl Test Harness Script for Modules
3 ##
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($NUMTESTS);
12 my $error;
14 BEGIN { 
15     # to handle systems with no installed Test module
16     # we include the t dir (where a copy of Test.pm is located)
17     # as a fallback
18     eval { require Test; };
19     $error = 0;
20     if( $@ ) {
21         use lib 't';
22     }
23     use Test;
25     $NUMTESTS = 18;
26     plan tests => $NUMTESTS;
28     unless (eval "require IO::String; 1;") {
29         print STDERR "IO::String not installed. Skipping tests $Test::ntest to $NUMTESTS.\n";
30         for ($Test::ntest..$NUMTESTS){
31             skip(1,1);    
32         }
33         exit(0);
34     }
37 if( $error ==  1 ) {
38     exit(0);
40 END { 
41     foreach ( $Test::ntest .. $NUMTESTS ) {
42         skip("unable to run all of the PAML tests",1);
43     }
45 my $testnum;
46 my $verbose = 0;
48 ## End of black magic.
50 ## Insert additional test code below but remember to change
51 ## the print "1..x\n" in the BEGIN block to reflect the
52 ## total number of tests that will be run. 
54 use Bio::Tools::Phylo::PAML; # PAML parser
55 use Bio::Root::IO;
57 my $inpaml = new Bio::Tools::Phylo::PAML(-file => 
58                                          Bio::Root::IO->catfile(qw(t data 
59                                                                    codeml.mlc)));
61 ok($inpaml);
63 use Bio::Tools::Run::Phylo::PAML::Codeml;
64 use Bio::Tools::Run::Phylo::PAML::Yn00;
65 use Bio::AlignIO;
66 my $codeml = new Bio::Tools::Run::Phylo::PAML::Codeml(-verbose => $verbose);
67 unless ($codeml->executable) {
68   warn("PAML not is installed. skipping tests $Test::ntest to $NUMTESTS\n");
69   exit(0) ;
72 my $in = new Bio::AlignIO(-format => 'phylip',
73                           -file   => Bio::Root::IO->catfile(qw(t data 
74                                                                gf-s85.phylip)));
75 my $aln = $in->next_aln;
76 $codeml->alignment($aln);
77 my ($rc,$results) = $codeml->run();
79 ok($rc,1);
80 if( ! defined $results ) { 
81     exit(0);
84 my $result = $results->next_result;
85 my $MLmatrix = $result->get_MLmatrix;
87 my ($vnum) = ($result->version =~ /(\d+\.\d+)/);
88 # PAML 2.12 results
89 if( $vnum == 3.12 ) {
90     ok($MLmatrix->[0]->[1]->{'dN'}, 0.0693);
91     ok($MLmatrix->[0]->[1]->{'dS'},1.1459);
92     ok($MLmatrix->[0]->[1]->{'omega'}, 0.0605);
93     ok($MLmatrix->[0]->[1]->{'S'}, 273.5);
94     ok($MLmatrix->[0]->[1]->{'N'}, 728.5);
95     ok($MLmatrix->[0]->[1]->{'t'}, 1.0895);
96 } elsif( $vnum >= 3.13 ) {
97 # PAML 2.13 results
98     ok($MLmatrix->[0]->[1]->{'dN'}, 0.0713);
99     ok($MLmatrix->[0]->[1]->{'dS'},1.2462);
100     ok(sprintf("%.4f",$MLmatrix->[0]->[1]->{'omega'}), 0.0572);
101     ok($MLmatrix->[0]->[1]->{'S'}, 278.8);
102     ok($MLmatrix->[0]->[1]->{'N'}, 723.2);
103     ok(sprintf("%.4f",$MLmatrix->[0]->[1]->{'t'}), 1.1946);
104 } else { 
105     for( 1..6) { 
106         skip("Can't test the result output, don't know about PAML version ".$result->version,1);
107     }
110 ok($codeml->error_string !~ /Error/); # we don't expect any errors;
112 my $yn00 = Bio::Tools::Run::Phylo::PAML::Yn00->new();
113 $yn00->alignment($aln);
114 ($rc,$results) = $yn00->run();
115 ok($rc,1);
116 if( ! defined $results ) { 
117     exit(0);
119 $result = $results->next_result;
120 $MLmatrix = $result->get_MLmatrix;
122 ok($MLmatrix->[0]->[1]->{'dN'}, 0.0846);
123 ok($MLmatrix->[0]->[1]->{'dS'}, 1.0926);
124 ok($MLmatrix->[0]->[1]->{'omega'}, 0.0774);
125 ok($MLmatrix->[0]->[1]->{'S'}, 278.4);
126 ok($MLmatrix->[0]->[1]->{'N'}, 723.6);
127 ok($MLmatrix->[0]->[1]->{'t'}, 1.0941);
129 ok($yn00->error_string !~ /Error/); # we don't expect any errors;
132 $codeml = new Bio::Tools::Run::Phylo::PAML::Codeml
133     (-params => { 'alpha' => 1.53 },
134      -verbose => $verbose);
136 ok($codeml);