2 ## Bioperl Test Harness Script for Modules
7 eval {require Test::More;};
15 use_ok('Bio::Tools::Run::Phylo::Phast::PhastCons');
16 use_ok('Bio::AlignIO');
17 use_ok('Bio::TreeIO');
18 use_ok('Bio::DB::Taxonomy');
22 for my $filename (qw(nodes parents id2names names2id)) {
23 unlink File::Spec->catfile('t','data','taxdump', $filename);
27 # setup input files etc
28 my $alignfilename = File::Spec->catfile("t", "data", "apes.multi_fasta");
29 my $treefilename = File::Spec->catfile("t", "data", "apes.newick");
30 ok (-e $alignfilename, 'Found input alignment file');
31 ok (-e $treefilename, 'Found input tree file');
33 my $factory = Bio::Tools::Run::Phylo::Phast::PhastCons->new(-verbose => -1,
35 '-expected-length' => 3,
36 Target_coverage => 0.286,
38 isa_ok($factory, 'Bio::Tools::Run::Phylo::Phast::PhastCons');
39 ok $factory->can('ignore_missing'), 'has a created method not in args';
40 is $factory->expected_length, 3, 'dashed parameter with internal dash was set';
41 ok ! $factory->can('Target_coverage'), "wrong-case method wasn't created";
42 is $factory->target_coverage, 0.286, 'dashless wrong-case parameter was set';
43 is $factory->C, 0.286, 'synonym installed and accessed primary value';
44 is $factory->rho, 0.01, 'double-dashed parameter was set';
46 # test default factory values
47 is ($factory->program_dir, $ENV{'PHASTDIR'}, 'program_dir returned correct default');
48 is ($factory->program_name(), 'phastCons', 'Correct exe default name');
50 # test the program itself
52 skip("Couldn't find the phastCons executable", 166) unless defined $factory->executable();
54 # using filename input
55 ok my @result1 = $factory->run($alignfilename, $treefilename), 'got results using filename input';
57 # using SimpleAlign and Bio::Tree::Tree input
58 my $alignio = Bio::AlignIO->new(-file => $alignfilename);
59 my $aln = $alignio->next_aln;
61 my $treeio = Bio::TreeIO->new(-verbose => -1, -file => $treefilename);
62 my $tree = $treeio->next_tree;
63 ok my @result2 = $factory->run($aln, $tree), 'got results using object input';
65 # using database to generate species tree
66 my $tdb = Bio::DB::Taxonomy->new(-source => 'flatfile',
67 -directory => File::Spec->catdir ('t','data','taxdump'),
68 -nodesfile => File::Spec->catfile('t','data','taxdump','nodes.dmp'),
69 -namesfile => File::Spec->catfile('t','data','taxdump','names.dmp'));
70 ok my @result3 = $factory->run($aln, $tdb), 'got results using db input';
72 is_deeply \@result1, \@result2, 'results same for file and object input';
73 is_deeply \@result1, \@result3, 'results same for file and db input';
76 my @apes = qw(human chimpanzee Cross_river_gorilla orangutan common_gibbon crested_gibbon siamang mountain_gorilla Hoolock_gibbon silvery_gibbon);
77 is @result1, 20, 'correct number of results';
78 foreach my $expected (['apes.1', 10, 14], ['apes.2', 26, 30]) {
79 foreach my $i (0..9) {
80 my $feat = shift(@result1);
81 isa_ok $feat, 'Bio::SeqFeature::Annotated';
82 is $feat->seq_id, $apes[$i], 'correct seq_id';
83 is $feat->source, 'phastCons', 'correct source';
84 is ${[$feat->annotation->get_Annotations('Name')]}[0], ${$expected}[0], 'correct feature name';
85 is $feat->start, ${$expected}[1], 'correct feature start';
86 is $feat->end, ${$expected}[2], 'correct feature end';
87 is $feat->score, 6, 'correct feature score';
88 is $feat->strand, 1, 'correct feature strand';