Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / t / Semphy.t
blob8de6371dff002b0f50bf3658b89c7a104148d953
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     test_begin(-tests => 19);
9     use_ok('Bio::Tools::Run::Phylo::Semphy');
12 # setup input files
13 my $alignfilename = test_input_file('semphy.seq');
14 my $treefilename = test_input_file('semphy.tree');
16 # object setup and testing
17 my $factory = Bio::Tools::Run::Phylo::Semphy->new(-quiet => 1, -z => '2.0', -H => 1, -jtt => 1, -S => 1);
19 isa_ok($factory, 'Bio::Tools::Run::Phylo::Semphy');
20 ok $factory->can('alphabet'), 'has a created method not in args';
21 is $factory->ratio, '2.0', 'ratio param was set via -z';
22 ok $factory->jtt, 'jtt switch was set';
24 is ($factory->program_dir, $ENV{'SEMPHYDIR'}, 'program_dir returned correct default');
25 is ($factory->program_name(), 'semphy', 'Correct exe default name');
27 # test the program itself
28 SKIP: {
29     test_skip(-requires_executable => $factory,
30               -tests => 12);
31     use_ok('Bio::TreeIO');
32     my $tree_out_file = test_output_file();
33     my $to = Bio::TreeIO->new(-format => 'newick', 
34                               -file => ">$tree_out_file");
35     
36     # run Semphy with an alignment
37     ok my $tree1 = $factory->run($alignfilename);
38     $to->write_tree($tree1);
39     
40     # or with alignment object
41     use_ok('Bio::AlignIO');
42     my $ai = Bio::AlignIO->new(-file => $alignfilename);
43     my $bio_simplalign = $ai->next_aln;
44     ok my $tree2 = $factory->run($bio_simplalign);
45     $to->write_tree($tree2);
46     
47     # you can supply an initial tree as well, which can be a newick tree file,
48     # Bio::Tree::Tree object...
49     my $ti = Bio::TreeIO->new(-file => $treefilename);
50     my $tree_obj = $ti->next_tree;
51     ok my $tree3 = $factory->run($bio_simplalign, $tree_obj);
52     $to->write_tree($tree3);
53     
54     # ... or Bio::DB::Taxonomy object
55     my $expected_count = 3;
56     SKIP: {
57         test_skip(-tests => 2, -requires_networking => 1);
58         
59         use_ok('Bio::DB::Taxonomy');
60         my $bio_db_taxonomy = Bio::DB::Taxonomy->new(-source => 'entrez');
61         ok my $tree4 = $factory->run($bio_simplalign, $bio_db_taxonomy);
62         $to->write_tree($tree4);
63         $expected_count++;
64     }
65     
66     $to->close;
67     
68     my $expected_result = '(Cow:0.280119,((Baboon:0.035422,Human:0.080635):0.000213,(Rat:0.198658,Horse:0.642019):0.120910):0.074791,Semnopithecus_entellus:0.016396);';
69     
70     open(my $res_fh, $tree_out_file);
71     my $count = 0;
72     while (<$res_fh>) {
73         chomp;
74         /\S/ || last;
75         $count++;
76         is $_, $expected_result;
77     }
78     close($res_fh);
79     
80     is $count, $expected_count;
81     if ($expected_count == 3) {
82         ok 1;
83     }