6 test_begin( -tests => 42 );
7 use_ok('Bio::DB::Taxonomy');
8 use_ok('Bio::Tree::Tree');
12 my ($db, $id, @ids, $node, $node2, $ancestor, @children, %common_names, $tree, @descs);
15 # Test Bio::DB::Taxonomy::silva
17 ok $db = Bio::DB::Taxonomy->new( -source => 'silva' );
19 isa_ok $db, 'Bio::DB::Taxonomy::silva';
20 isa_ok $db, 'Bio::DB::Taxonomy::list';
21 isa_ok $db, 'Bio::DB::Taxonomy';
23 ok $db = Bio::DB::Taxonomy->new(
25 -taxofile => test_input_file('taxonomy', 'silva_SSURef_108_tax_silva_trunc.fasta'),
28 @ids = $db->get_taxonid('Homo sapiens');
31 @ids = $db->get_taxonid('Rattus norvegicus');
35 ok $node = $db->get_taxon($id);
37 is $node->object_id, $node->id;
38 is $node->ncbi_taxid, undef;
39 is $node->rank, undef;
40 is $node->parent_id, 'sv72';
41 is $node->node_name, 'Rattus norvegicus';
42 is $node->scientific_name, $node->node_name;
44 is ${$node->name('scientific')}[0], $node->node_name;
46 # it has a common name in Silva, but Bio::DB::Taxonomy::silva does not record it
47 %common_names = map { $_ => 1 } $node->common_names;
48 is scalar keys %common_names, 0;
50 is $node->division, undef;
51 is $node->genetic_code, undef;
52 is $node->mitochondrial_genetic_code, undef;
54 # briefly test some Bio::Tree::NodeI methods
55 ok $ancestor = $node->ancestor;
56 is $ancestor->scientific_name, '';
57 ok $ancestor = $ancestor->ancestor;
58 is $ancestor->scientific_name, 'Rattus';
59 ok $ancestor = $ancestor->ancestor;
60 is $ancestor->scientific_name, 'Murinae';
62 # unless set explicitly, Bio::Taxon doesn't return anything for
63 # each_Descendent; must ask the database directly
64 @ids = $db->get_taxonid('Metazoa');
67 ok $node = $db->get_taxon($id);
68 ok @children = $node->db_handle->each_Descendent($node);
69 is scalar @children, 3; # Chordata, Platyhelminthes, Metazoa
71 # do some trickier things...
72 ok $node2 = $db->get_taxon('sv112');
73 is $node2->scientific_name, 'Mucoromycotina';
75 # briefly check that we can use some Tree methods
76 $tree = Bio::Tree::Tree->new();
77 is $tree->get_lca($node, $node2)->scientific_name, 'Eukaryota';
79 # can we actually form a Tree and use other Tree methods?
80 ok $tree = Bio::Tree::Tree->new(-node => $node2);
81 is $tree->number_nodes, 5;
82 is $tree->get_nodes, 5;
84 # check that getting the ancestor still works now we have explitly set the
85 # ancestor by making a Tree
86 is $node2->ancestor->scientific_name, 'Basal fungal lineages';
88 # we can recursively fetch all descendents of a taxon
89 my $lca = $db->get_taxon( -name => 'Liliopsida' );
90 ok @descs = $db->each_Descendent($lca);
92 @descs = $db->get_all_Descendents($lca);