Our Sponsors



Download BioinformaticsOnline(BOL) Apps in your chrome browser.




Parse the NCBI taxonomy database with Perl !

  • Public
By LEGE 1164 days ago
use Bio::DB::Taxonomy; use warnings; my $sps="human"; # Get one from a NCBI taxonomy database my $dbh = Bio::DB::Taxonomy->new(-source => 'flatfile', -directory=> "taxdump", -nodesfile=> "taxdump/nodes.dmp", -namesfile=> "taxdump/names.dmp"); #to check #parseTax('homo_sapiens', 'metazoa'); #exit; #my $nam = $dbh->get_taxon(-name => $sps); $nam = $dbh->get_taxon(-taxonid => 9606); if(!$nam) { print "Try again with correct scientific name\n"; exit;} print "Eureka we found $sps, id is ", $nam->id, "\n"; # 9606 #$abc = $names{$speciesId}; my @taxa = $dbh->each_Descendent($nam); #foreach (@taxa) {print $_->scientific_name ; print "--";} my @taxa2 = $dbh->get_all_Descendents($nam); #foreach (@taxa2) {print $_->scientific_name; print "**";} #my $ancestor_taxon = $dbh->ancestor($nam); print "$ancestor_taxon->id ****"; #my $tree = $dbh->get_tree('human'); print $tree->name; #print $nam->ancestor; my $ancestor_taxon = $dbh->ancestor($nam); #print $ancestor_taxon; use Bio::Tree::Tree; my $tree_functions = Bio::Tree::Tree->new(); my @lineage = $tree_functions->get_lineage_nodes($nam); my $lineage = $tree_functions->get_lineage_string($nam); #print $lineage; foreach (@lineage) {print $_->scientific_name; print "\n";} my $decision =recheck_class (1974465, "metazoa"); print $decision; #It return 1 of matches otherwise 0 #case-insesitive #Spelling mistake on classNode may leads to error sub recheck_class { my ($lineageId,$classNode)=@_; use Bio::Tree::Tree; my $tree_functions = Bio::Tree::Tree->new(); my $nam = $dbh->get_taxon(-taxonid => $lineageId); my @lineage = $tree_functions->get_lineage_nodes($nam); return 1 if ( grep { lc ($_->scientific_name) eq lc ($classNode)} @lineage ) }