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