Updating Mauricio's email
[bioperl-run.git] / t / PhastCons.t
blob4aab360fa054b4719a1e3696561ef93ada1bd8fd
1 # -*-Perl-*-
2 ## Bioperl Test Harness Script for Modules
4 use strict;
6 BEGIN {
7     use Bio::Root::Test;
8     test_begin(-tests => 181,
9                -requires_modules => [qw(Clone)]);
10     use_ok('Bio::AlignIO');
11     use_ok('Bio::TreeIO');
12     use_ok('Bio::DB::Taxonomy');
16 # setup input files etc
17 my $alignfilename = test_input_file("apes.multi_fasta");
18 my $treefilename = test_input_file("apes.newick");
19 ok (-e $alignfilename, 'Found input alignment file');
20 ok (-e $treefilename, 'Found input tree file');
22 SKIP: {
23     test_skip(-requires_module => 'Bio::FeatureIO',
24               -tests => 176);
25     use_ok('Bio::Tools::Run::Phylo::Phast::PhastCons');
26     my $factory = Bio::Tools::Run::Phylo::Phast::PhastCons->new(-verbose => -1,
27                                                                 -quiet => 1,
28                                                                 '-expected-length' => 3,
29                                                                 Target_coverage => 0.286,
30                                                                 '--rho' => 0.01);
31     isa_ok($factory, 'Bio::Tools::Run::Phylo::Phast::PhastCons');
32     ok $factory->can('ignore_missing'), 'has a created method not in args';
33     is $factory->expected_length, 3, 'dashed parameter with internal dash was set';
34     ok ! $factory->can('Target_coverage'), "wrong-case method wasn't created";
35     is $factory->target_coverage, 0.286, 'dashless wrong-case parameter was set';
36     is $factory->C, 0.286, 'synonym installed and accessed primary value';
37     is $factory->rho, 0.01, 'double-dashed parameter was set';
38     
39     # test default factory values
40     is ($factory->program_dir, $ENV{'PHASTDIR'}, 'program_dir returned correct default');
41     is ($factory->program_name(), 'phastCons', 'Correct exe default name');
43     # test the program itself
44     SKIP: {
45         test_skip(-requires_executable => $factory,
46                   -requires_module => 'Bio::FeatureIO',
47                   -tests => 166);
48         
49         # using filename input
50         ok my @result1 = $factory->run($alignfilename, $treefilename), 'got results using filename input';
51         
52         # using SimpleAlign and Bio::Tree::Tree input
53         my $alignio = Bio::AlignIO->new(-file => $alignfilename);
54         my $aln = $alignio->next_aln;
55         $aln->id('apes');
56         my $treeio = Bio::TreeIO->new(-verbose => -1, -file => $treefilename);
57         my $tree = $treeio->next_tree;
58         ok my @result2 = $factory->run($aln, $tree), 'got results using object input';
59         
60         # using database to generate species tree
61         my $tdb = Bio::DB::Taxonomy->new(-source => 'flatfile',
62             -directory => test_output_dir(),
63             -nodesfile => test_input_file('taxdump','nodes.dmp'),
64             -namesfile => test_input_file('taxdump','names.dmp'));
65         
66         ok my @result3 = $factory->run($aln, $tdb), 'got results using db input';
67         
68         is_deeply \@result1, \@result2, 'results same for file and object input';
69         is_deeply \@result1, \@result3, 'results same for file and db input';
70         
71         # test the results
72         my @apes = qw(human chimpanzee Cross_river_gorilla orangutan common_gibbon crested_gibbon siamang mountain_gorilla Hoolock_gibbon silvery_gibbon);
73         is @result1, 20, 'correct number of results';
74         foreach my $expected (['apes.1', 10, 14], ['apes.2', 26, 30]) {
75             foreach my $i (0..9) {
76                 my $feat = shift(@result1);
77                 isa_ok $feat, 'Bio::SeqFeature::Annotated';
78                 is $feat->seq_id, $apes[$i], 'correct seq_id';
79                 is $feat->source->value, 'phastCons', 'correct source';
80                 is ${[$feat->annotation->get_Annotations('Name')]}[0]->value, ${$expected}[0], 'correct feature name';
81                 is $feat->start, ${$expected}[1], 'correct feature start';
82                 is $feat->end, ${$expected}[2], 'correct feature end';
83                 is $feat->score, 6, 'correct feature score';
84                 is $feat->strand, 1, 'correct feature strand';
85             }
86         }
87     }