Supply TEMPLATE and SUFFIX for temporary query sequence files.
[bioperl-run.git] / t / Gerp.t
blobc5a931af861f0cb42bd2b59e97ba5a8d626dd4d8
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     
9     test_begin(-tests => 33);
10     
11     use_ok('Bio::Tools::Run::Phylo::Gerp');
12     use_ok('Bio::AlignIO');
13     use_ok('Bio::TreeIO');
14     use_ok('Bio::Root::Utilities');
17 END {
18     unlink(test_input_file('gerp', 'ENr111.mfa'));
21 # setup input files etc
22 my $alignfilename = test_input_file('gerp', 'ENr111.mfa.gz');
23 my $treefilename  = test_input_file('gerp', 'ENr111.gerp.tree');
24 ok (-e $alignfilename, 'Found input alignment file');
25 ok (-e $treefilename, 'Found input tree file');
27 my $factory = Bio::Tools::Run::Phylo::Gerp->new(-verbose => -1,
28                                                 -quiet => 1);
29 isa_ok($factory, 'Bio::Tools::Run::Phylo::Gerp');
30 ok $factory->can('e'), 'has a created method not in args supplied to new';
31 is $factory->quiet, 1, 'quiet was set';
33 # test default factory values
34 is ($factory->program_dir, $ENV{'GERPDIR'}, 'program_dir returned correct default');
35 is ($factory->program_name(), 'gerpcol', 'Correct exe default name');
37 # test the program itself
38 SKIP: {
39     test_skip(-requires_executable => $factory, -tests => 22);
40     
41     my $util = Bio::Root::Utilities->new();
42     $alignfilename = $util->uncompress(-file => $alignfilename,
43                                        -tmp  => 1);
44     
45     skip("Couldn't uncompress the alingment input file", 22) unless $alignfilename;
46     
47     # using filename input
48     ok my $parser = $factory->run($alignfilename, $treefilename), 'got results using filename input';
49     my @result1;
50     while (my $result = $parser->next_result) {
51         push(@result1, $result);
52     }
53     ok close_enough(scalar(@result1), 121, 20), 'reasonable number of results using filename input';
54     
55     # using SimpleAlign and Bio::Tree::Tree input
56     my $alignio = Bio::AlignIO->new(-file => $alignfilename);
57     my $aln = $alignio->next_aln;
58     my $treeio = Bio::TreeIO->new(-verbose => -1, -file => $treefilename);
59     my $tree = $treeio->next_tree;
60     ok $parser = $factory->run($aln, $tree), 'got results using object input';
61     my @result2;
62     while (my $result = $parser->next_result) {
63         push(@result2, $result);
64     }
65     ok close_enough(scalar(@result2), 121, 20), 'reasonable number of results using object input';
66     
67     # spot-test the results
68     my @spot_results = ($result1[0], $result1[1], $result1[2]);
69     
70     foreach my $expected ([294576, 294688, 56.5, 1.76552e-57],
71                           [337735, 337898, 50.9, 3.19063e-57],
72                           [285430, 285608, 44.3, 1.41149e-54]) {
73         my $feat = shift(@spot_results);
74         isa_ok $feat, 'Bio::SeqFeature::Annotated';
75         is $feat->source->value, 'GERP', 'correct source';
76         ok close_enough($feat->start, shift(@{$expected}), 10), 'feature start close enough';
77         ok close_enough($feat->end, shift(@{$expected}), 10), 'feature end close enough';
78         ok close_enough($feat->score, shift(@{$expected}), 5), 'feature score close enough';
79         my ($p_value) = $feat->get_Annotations('pvalue');
80         ok close_enough(ref $p_value ? $p_value->value : $p_value, shift(@{$expected}), 100e-57), 'feature pvalue close enough';
81     }
84 sub close_enough {
85     my ($actual, $expected, $variance) = @_;
86     return 1 if $actual == $expected;
87     
88     if ($actual >= ($expected - $variance) &&
89         $actual <= ($expected + $variance)) {
90         return 1;
91     }
92     return 0;