Add tests for memory leaks and weaken for Issue #81
[bioperl-live.git] / t / LocalDB / Taxonomy / greengenes.t
blobf355d66b15dced3c7861138f3c2db430424e8150
1 use strict;
3 BEGIN { 
4     use lib '.';
5     use Bio::Root::Test;
6     test_begin( -tests => 38 );
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::greengenes
17 ok $db = Bio::DB::Taxonomy->new( -source => 'greengenes' );
19 isa_ok $db, 'Bio::DB::Taxonomy::greengenes';
20 isa_ok $db, 'Bio::DB::Taxonomy::list';
21 isa_ok $db, 'Bio::DB::Taxonomy';
23 ok $db = Bio::DB::Taxonomy->new(
24    -source   => 'greengenes',
25    -taxofile => test_input_file('taxonomy', 'greengenes_taxonomy_16S_candiv_gg_2011_1.txt'),
28 @ids = $db->get_taxonid('Homo sapiens');
29 is scalar @ids, 0;
31 @ids = $db->get_taxonid('s__Bacteroides uniformis');
32 is scalar @ids, 1;
33 $id = $ids[0];
35 ok $node = $db->get_taxon($id);
36 is $node->id, $id;
37 is $node->object_id, $node->id;
38 is $node->ncbi_taxid, undef;
39 is $node->rank, 'species';
40 is $node->parent_id, 'gg6';
41 is $node->node_name, 's__Bacteroides uniformis';
42 is $node->scientific_name, $node->node_name;
44 is ${$node->name('scientific')}[0], $node->node_name;
46 %common_names = map { $_ => 1 } $node->common_names;
47 is scalar keys %common_names, 0;
49 is $node->division, undef;
50 is $node->genetic_code, undef;
51 is $node->mitochondrial_genetic_code, undef;
53 # briefly test some Bio::Tree::NodeI methods
54 ok $ancestor = $node->ancestor;
55 is $ancestor->scientific_name, 'g__Bacteroides';
57 # unless set explicitly, Bio::Taxon doesn't return anything for
58 # each_Descendent; must ask the database directly
59 ok @children = $ancestor->db_handle->each_Descendent($ancestor);
60 is scalar @children, 2;
62 # do some trickier things...
63 ok $node2 = $db->get_taxon('gg104');
64 is $node2->scientific_name, 'o__Synergistales';
66 # briefly check that we can use some Tree methods
67 $tree = Bio::Tree::Tree->new();
68 is $tree->get_lca($node, $node2)->scientific_name, 'k__Bacteria';
70 # can we actually form a Tree and use other Tree methods?
71 ok $tree = Bio::Tree::Tree->new(-node => $node);
72 is $tree->number_nodes, 7;
73 is $tree->get_nodes, 7;
74 is $tree->find_node(-rank => 'genus')->scientific_name, 'g__Bacteroides';
75 is $tree->find_node(-rank => 'class')->scientific_name, 'c__Bacteroidia';
77 # check that getting the ancestor still works now we have explitly set the
78 # ancestor by making a Tree
79 is $node->ancestor->scientific_name, 'g__Bacteroides';
81 # we can recursively fetch all descendents of a taxon
82 my $lca = $db->get_taxon( -name => 'f__Enterobacteriaceae' );
83 ok @descs = $db->each_Descendent($lca);
84 is scalar @descs, 2;
85 @descs = $db->get_all_Descendents($lca);
86 is scalar @descs, 3;