Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / t / Phyml.t
blob685ce0179ea12319e8126a18dab6bfd70625277e
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     test_begin(-tests => 46);
9     use_ok('Bio::Tools::Run::Phylo::Phyml');
10     use_ok('Bio::AlignIO');
13 # setup input files etc
14 my $inputfilename = test_input_file("protpars.phy");
15 ok (-e $inputfilename, 'Found protein input file');
17 my $factory = Bio::Tools::Run::Phylo::Phyml->new(-verbose => test_debug());
18 isa_ok($factory, 'Bio::Tools::Run::Phylo::Phyml');
20 # test default factory values
21 is ($factory->program_dir, $ENV{'PHYMLDIR'}, 'program_dir returned correct default');
22 is ($factory->program_name(), 'phyml', 'Correct exe default name');
24 is ($factory->data_format, 'i', 'data_format, default');
25 is ($factory->data_format('s'), 's', 'data_format, sequential');
26 is ($factory->data_format('i'), 'i', 'data_format, interleaved');
28 is ($factory->dataset_count, 1, 'dataset_count, default');
29 is ($factory->dataset_count(2), 2, 'data_count, 2');
31 is ($factory->kappa, 'e', 'kappa, default');
32 is ($factory->kappa(4), '4.0', 'kappa');
34 is ($factory->invar, 'e', 'invar, default');
35 is ($factory->invar(.5), '0.5', 'invar');
37 is ($factory->category_number, 1, 'category_number, default');
38 is ($factory->category_number(4), 4, 'category_number');
40 is ($factory->alpha, 'e', 'alpha, default');
41 is ($factory->alpha(1.0), '1.0', 'alpha');
42 is ($factory->alpha('e'), 'e', 'alpha');
44 is ($factory->tree, 'BIONJ', 'tree, default');
45 # not a valid tree for this MSA, just testing
46 my $mock_treefile = test_input_file("treefile.example");
47 is ($factory->tree($mock_treefile), $mock_treefile, 'tree');
48 is ($factory->tree('BIONJ'), 'BIONJ', 'tree');
50 # test the program itself
51 SKIP: {
52     test_skip(-requires_executable => $factory,
53               -tests => 23);
55     cmp_ok $factory->version, '>', '2.4','version';
56     # test version-specific parameters
57     if ($factory->version >= 3 ) {
58         is ($factory->data_type, 'aa', 'data_type, default');
59         is ($factory->data_type('nt'), 'nt', 'data_type, dna');
60         is ($factory->data_type('aa'), 'aa', 'data_type, aa');
62         is ($factory->model, 'LG', 'model, default');
64         is ($factory->opt, 'n', 'opt, default');
65         is ($factory->opt('tl'), 'tl', 'opt_topology');
67         is ($factory->freq, undef, 'freq, default');
68         is ($factory->freq('d'), 'd', 'freq');
70         is ($factory->search, 'NNI', 'search, default');
71         is ($factory->search('SPR'), 'SPR', 'search');
73         is ($factory->rand_start, 0, 'rand_start, default');
74         is ($factory->rand_start(1), 1, 'rand_start');
76         is ($factory->rand_starts, 1, 'rand_starts, default');
77         is ($factory->rand_starts(10), 10, 'rand_starts');
79         cmp_ok $factory->rand_seed, '>=', 1, 'rand_seed, default';
80         is ($factory->rand_seed(10), 10, 'rand_seed');
81         $factory->search('NNI'); #to take the fastest option for running
83     } else { # version 2.4.4
85         is ($factory->data_type, '1', 'data_type, default');
86         is ($factory->data_type('dna'), '0', 'data_type, dna');
87         is ($factory->data_type('protein'), '1', 'data_type, protein');
89         is ($factory->model, 'JTT', 'model, default');
91         is ($factory->opt_topology, 'y', 'opt_topology, default');
92         is ($factory->opt_topology('0'), 'n', 'opt_topology');
93         is ($factory->opt_topology('1'), 'y', 'opt_topology');
95         is ($factory->opt_lengths, 'y', 'opt_lengths, default');
96         is ($factory->opt_lengths('0'), 'n', 'opt_lengths');
97         is ($factory->opt_lengths('1'), 'y', 'opt_lengths');
99         for (1..6) {ok 1;} # to have same number of tests for all versions
100     }
101 #    $factory->save_tempfiles(1);
102 #    my $workdir = '/tmp/phyml_test';
103 #    $factory->tempdir($workdir);
105     # using filename input
106     my $tree = $factory->run($inputfilename);
107     isa_ok($tree, 'Bio::Tree::Tree');
108     my @leaves = $tree->get_leaf_nodes;
109     is (@leaves, 3, 'Result tree from filename input had correct number of leaves');
111     if ($factory->version >= 3){
112         is substr($factory->stats, 2, 9), "ooooooooo", 'stats()';
113     } else { # PhyML v2
114         is substr($factory->stats, 0, 9), "\n- PHYML ", 'stats()';
115     }
117     is substr($factory->tree_string, 0, 9), 'BIONJ(SIN', 'tree_string()';
120     # using AlignIO on a DNA MSA
121     $inputfilename = test_input_file("dna_seqs1.phy");
122     ok (-e $inputfilename, 'Found DNA input file');
124     my $alignio = Bio::AlignIO->new(-file => $inputfilename);
125     my $aln = $alignio->next_aln;
127     my $alphabet;
128     if ($factory->version >= 3){
129         $alphabet = 'nt';
130     } else {
131         $alphabet = 'dna';
132     }
134     #testing passing attributes to the constructor
135     my %args = (
136         -data_type => $alphabet,
137         -model => 'JC69',
138         -kappa => 4,
139         -invar => 'e',
140         -category_number => 4,
141         -alpha => 'e',
142         -tree => 'BIONJ',
143         -verbose => 0
144         );
146     $factory = Bio::Tools::Run::Phylo::Phyml->new(%args);
147     $factory->save_tempfiles(1);
148     $tree = $factory->run($aln);
149     @leaves = $tree->get_leaf_nodes;
150     is (@leaves, 5, 'Result tree from DNA SimpleAlign input had correct number of leaves');