Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / t / Gumby.t
blob60726c480665768cefe640ecbf0c39f73d97a9b4
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     test_begin(-tests => 124);
9     
10     use_ok('Bio::Tools::Run::Phylo::Gumby');
11     use_ok('Bio::AlignIO');
12     use_ok('Bio::TreeIO');
13     use_ok('Bio::DB::Taxonomy');
14     use_ok('Bio::Tools::GFF');
17 # setup input files etc
18 my $alignfilename = test_input_file('gumby', 'hmrd.mfa');
19 my $treefilename = test_input_file('gumby', 'hmrd.tree');
20 my $gfffilename = test_input_file('gumby', 'human.gff');
21 ok (-e $alignfilename, 'Found input alignment file');
22 ok (-e $treefilename, 'Found input tree file');
23 ok (-e $gfffilename, 'Found input gff file');
25 my $factory = Bio::Tools::Run::Phylo::Gumby->new(-verbose => -1,
26                                                  -quiet => 1);
27 isa_ok($factory, 'Bio::Tools::Run::Phylo::Gumby');
28 ok $factory->can('ratio'), 'has a created method not in args';
29 is $factory->quiet, 1, 'quiet was set';
31 # test default factory values
32 is ($factory->program_dir, $ENV{'GUMBYDIR'}, 'program_dir returned correct default');
33 is ($factory->program_name(), 'gumby', 'Correct exe default name');
35 # test the program itself
36 SKIP: {
37     test_skip(-requires_executable => $factory, -tests => 111);
38     
39     # using filename input
40     ok my @result1 = $factory->run($alignfilename, $treefilename), 'got results using filename input';
41     is @result1, 80, 'correct number of results';
42     
43     # using SimpleAlign and Bio::Tree::Tree input
44     my $alignio = Bio::AlignIO->new(-file => $alignfilename);
45     my $aln = $alignio->next_aln;
46     my $treeio = Bio::TreeIO->new(-verbose => -1, -file => $treefilename);
47     my $tree = $treeio->next_tree;
48     ok my @result2 = $factory->run($aln, $tree), 'got results using object input';
49     
50     # using database to generate species tree
51     my $tdb = Bio::DB::Taxonomy->new(-source => 'flatfile',
52         -directory => test_output_dir(),
53         -nodesfile => test_input_file('taxdump','nodes.dmp'),
54         -namesfile => test_input_file('taxdump','names.dmp'));
55     
56     ok my @result3 = $factory->run($aln, $tdb), 'got results using db input';
57     
58     is_deeply \@result1, \@result2, 'results same for file and object input';
59     is_deeply \@result1, \@result3, 'results same for file and db input';
60     
61     # spot-test the results
62     my @spot_results = ($result1[0], $result1[1], $result1[2], $result1[3], $result1[-4], $result1[-3], $result1[-2], $result1[-1]);
63     foreach my $expected (['human', 5993, 6134, 7098, 1.6e-05], ['mouse', 4201, 4341], ['rat', 3563, 3702], ['dog', 4026, 4165],
64                           ['human', 59767, 59825, 2486, 0.42], ['mouse', 46010, 46068], ['rat', 44848, 44906], ['dog', 48054, 48096]) {
65         my $feat = shift(@spot_results);
66         isa_ok $feat, 'Bio::SeqFeature::Annotated';
67         is $feat->seq_id, shift(@{$expected}), 'correct seq_id';
68         is $feat->source_tag, 'gumby', 'correct source';
69         is $feat->start, shift(@{$expected}), 'correct feature start';
70         is $feat->end, shift(@{$expected}), 'correct feature end';
71         if (@{$expected}) {
72             is $feat->score, shift(@{$expected}), 'correct feature score';
73             is ${[$feat->get_tag_values('pvalue')]}[0], shift(@{$expected}), 'correct feature pvalue';
74         }
75         is ${[$feat->get_tag_values('kind')]}[0], 'all', 'correct feature kind';
76     }
77     
78     # with gff input and econs
79     $factory->annots($gfffilename);
80     $factory->econs(1);
81     ok my @result4 = $factory->run($alignfilename, $treefilename), 'got results using filename input with gff';
82     is @result4, 104, 'correct number of results';
83     
84     # using feature object input
85     my $gffin = Bio::Tools::GFF->new(-file => $gfffilename, -gff_version => 2);
86     my @features;
87     while(my $feature = $gffin->next_feature()) {
88         push(@features, $feature);
89     }
90     $gffin->close();
91     $factory->annots(@features);
92     
93     ok my @result5 = $factory->run($alignfilename, $treefilename), 'got results using filename input with feature objects';
94     is @result5, 104, 'correct number of results';
95     is_deeply \@result4, \@result5, 'results same for gff and object input';
96     
97     # spot-test the results
98     @spot_results = ($result4[0], $result4[1], $result4[2], $result4[3], $result4[-4], $result4[-3], $result4[-2], $result4[-1]);
99     foreach my $expected (['human', 20442, 20507, 'exon'], ['mouse', 16488, 16560, 'exon'], ['rat', 15927, 15999, 'exon'], ['dog', 17469, 17544, 'exon'],
100                           ['human', 59992, 60040, 'nonexon'], ['mouse', 46257, 46294, 'nonexon'], ['rat', 45096, 45134, 'nonexon'], ['dog', 48297, 48344, 'nonexon']) {
101         my $feat = shift(@spot_results);
102         isa_ok $feat, 'Bio::SeqFeature::Annotated';
103         is $feat->seq_id, shift(@{$expected}), 'correct seq_id';
104         is $feat->source_tag, 'gumby', 'correct source';
105         is $feat->start, shift(@{$expected}), 'correct feature start';
106         is $feat->end, shift(@{$expected}), 'correct feature end';
107         is ${[$feat->get_tag_values('kind')]}[0], shift(@{$expected}), 'correct feature kind';
108     }