5 test_begin( -tests => 38 );
6 use_ok('Bio::DB::Taxonomy');
7 use_ok('Bio::Tree::Tree');
11 my ($db, $id, @ids, $node, $node2, $ancestor, @children, %common_names, $tree, @descs);
14 # Test Bio::DB::Taxonomy::greengenes
16 ok $db = Bio::DB::Taxonomy->new( -source => 'greengenes' );
18 isa_ok $db, 'Bio::DB::Taxonomy::greengenes';
19 isa_ok $db, 'Bio::DB::Taxonomy::list';
20 isa_ok $db, 'Bio::DB::Taxonomy';
22 ok $db = Bio::DB::Taxonomy->new(
23 -source => 'greengenes',
24 -taxofile => test_input_file('taxonomy', 'greengenes_taxonomy_16S_candiv_gg_2011_1.txt'),
27 @ids = $db->get_taxonid('Homo sapiens');
30 @ids = $db->get_taxonid('s__Bacteroides uniformis');
34 ok $node = $db->get_taxon($id);
36 is $node->object_id, $node->id;
37 is $node->ncbi_taxid, undef;
38 is $node->rank, 'species';
39 is $node->parent_id, 'gg6';
40 is $node->node_name, 's__Bacteroides uniformis';
41 is $node->scientific_name, $node->node_name;
43 is ${$node->name('scientific')}[0], $node->node_name;
45 %common_names = map { $_ => 1 } $node->common_names;
46 is scalar keys %common_names, 0;
48 is $node->division, undef;
49 is $node->genetic_code, undef;
50 is $node->mitochondrial_genetic_code, undef;
52 # briefly test some Bio::Tree::NodeI methods
53 ok $ancestor = $node->ancestor;
54 is $ancestor->scientific_name, 'g__Bacteroides';
56 # unless set explicitly, Bio::Taxon doesn't return anything for
57 # each_Descendent; must ask the database directly
58 ok @children = $ancestor->db_handle->each_Descendent($ancestor);
59 is scalar @children, 2;
61 # do some trickier things...
62 ok $node2 = $db->get_taxon('gg104');
63 is $node2->scientific_name, 'o__Synergistales';
65 # briefly check that we can use some Tree methods
66 $tree = Bio::Tree::Tree->new();
67 is $tree->get_lca($node, $node2)->scientific_name, 'k__Bacteria';
69 # can we actually form a Tree and use other Tree methods?
70 ok $tree = Bio::Tree::Tree->new(-node => $node);
71 is $tree->number_nodes, 7;
72 is $tree->get_nodes, 7;
73 is $tree->find_node(-rank => 'genus')->scientific_name, 'g__Bacteroides';
74 is $tree->find_node(-rank => 'class')->scientific_name, 'c__Bacteroidia';
76 # check that getting the ancestor still works now we have explitly set the
77 # ancestor by making a Tree
78 is $node->ancestor->scientific_name, 'g__Bacteroides';
80 # we can recursively fetch all descendents of a taxon
81 my $lca = $db->get_taxon( -name => 'f__Enterobacteriaceae' );
82 ok @descs = $db->each_Descendent($lca);
84 @descs = $db->get_all_Descendents($lca);