<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Parse the NCBI taxonomy database with Perl !]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/42892/parse-the-ncbi-taxonomy-database-with-perl?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/42892/parse-the-ncbi-taxonomy-database-with-perl?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/42892/parse-the-ncbi-taxonomy-database-with-perl</guid>
	<pubDate>Wed, 17 Feb 2021 21:17:15 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/42892/parse-the-ncbi-taxonomy-database-with-perl</link>
	<title><![CDATA[Parse the NCBI taxonomy database with Perl !]]></title>
	<description><![CDATA[<code>use Bio::DB::Taxonomy;
use warnings;

my $sps=&quot;human&quot;;
# Get one from a NCBI taxonomy database
my $dbh = Bio::DB::Taxonomy-&gt;new(-source   =&gt; &#039;flatfile&#039;,
                                 -directory=&gt; &quot;taxdump&quot;,
                                 -nodesfile=&gt; &quot;taxdump/nodes.dmp&quot;,
                                 -namesfile=&gt; &quot;taxdump/names.dmp&quot;);
#to check
#parseTax(&#039;homo_sapiens&#039;, &#039;metazoa&#039;);
#exit;
#my $nam = $dbh-&gt;get_taxon(-name =&gt; $sps);
$nam = $dbh-&gt;get_taxon(-taxonid =&gt; 9606);
if(!$nam) { print &quot;Try again with correct scientific name\n&quot;; exit;}
print &quot;Eureka we found $sps, id is &quot;, $nam-&gt;id, &quot;\n&quot;; # 9606

#$abc = $names{$speciesId};

my @taxa = $dbh-&gt;each_Descendent($nam);

#foreach (@taxa) {print $_-&gt;scientific_name ; print &quot;--&quot;;}

my @taxa2 = $dbh-&gt;get_all_Descendents($nam);

#foreach (@taxa2) {print $_-&gt;scientific_name; print &quot;**&quot;;}

#my $ancestor_taxon = $dbh-&gt;ancestor($nam); print &quot;$ancestor_taxon-&gt;id ****&quot;;

#my $tree = $dbh-&gt;get_tree(&#039;human&#039;); print $tree-&gt;name;
#print $nam-&gt;ancestor;
my $ancestor_taxon = $dbh-&gt;ancestor($nam);
#print $ancestor_taxon;

use Bio::Tree::Tree;
my $tree_functions = Bio::Tree::Tree-&gt;new();
my @lineage = $tree_functions-&gt;get_lineage_nodes($nam);
my $lineage = $tree_functions-&gt;get_lineage_string($nam);

#print $lineage;
foreach (@lineage) {print $_-&gt;scientific_name; print &quot;\n&quot;;}

my $decision =recheck_class (1974465, &quot;metazoa&quot;);
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-&gt;new();
my $nam = $dbh-&gt;get_taxon(-taxonid =&gt; $lineageId);
my @lineage = $tree_functions-&gt;get_lineage_nodes($nam);
return 1 if ( grep { lc ($_-&gt;scientific_name) eq lc ($classNode)} @lineage )
}</code>]]></description>
	<dc:creator>LEGE</dc:creator>
</item>

</channel>
</rss>