Hi There,
I am wondering if i can extract tree for a given list of species using bioperl from NCBI taxonnomy database.
I hope some of you can help me figure this out.
Many thanks in advance.
Kind Regards,
Lhl
Hi There,
I am wondering if i can extract tree for a given list of species using bioperl from NCBI taxonnomy database.
I hope some of you can help me figure this out.
Many thanks in advance.
Kind Regards,
Lhl
from ete3 import NCBITaxa
ncbi = NCBITaxa()
tree = ncbi.get_topology([9606, 9598, 10090, 7707, 9782])
print(tree.write(format=9, features=["sci_name", "rank"]))
from ete3 import NCBITaxa
ncbi = NCBITaxa()
tree = ncbi.get_topology([9606, 9598, 10090, 7707, 8782])
tree.write(features=["sci_name", "rank"], outfile="tree.nw")
gives you an output tree.nw
:
(7707:1[&&NHX:sci_name=Dendrochirotida:rank=order],(((9606:1[&&NHX:sci_name=Homo sapiens:rank=species],9598:1[&&NHX:sci_name=Pan troglodytes:rank=species])1:1[&&NHX:sci_name=Homininae:rank=subfamily],10090:1[&&NHX:sci_name=Mus musculus:rank=species])1:1[&&NHX:sci_name=Euarchontoglires:rank=superorder],8782:1[&&NHX:sci_name=Aves:rank=class])1:1[&&NHX:sci_name=Amniota:rank=no rank]);
Thanks SMK. I tried this but it does not work.
tree.write(features=["sci_name", "rank"], outfile="tree.nw")
t_file = Tree("tree.nw")
for node in t_file.traverse():
node.name = node.sci_name
tree.write(features=["node.name"], outfile="labeled_tree.nw")
AttributeError: 'TreeNode' object has no attribute 'sci_name'
Hi peterlageweg603,
You have to traverse the one that you got from ncbi.get_topology()
:
from ete3 import NCBITaxa
ncbi = NCBITaxa()
tree = ncbi.get_topology([9606, 9598, 10090, 7707, 8782])
for node in tree.traverse():
node.name = node.sci_name
print(tree.write())
This gives you:
(Dendrochirotida:1,(((Homo sapiens:1,Pan troglodytes:1)1:1,Mus musculus:1)1:1,Aves:1)1:1);
Lhl,
The Bioperl Bio::Tree::TreeFunctionsI module has a get_lca method. Is this what you're looking for?
Brian O.
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Not a BioPerl solution, but this python script will do the job: https://github.com/jhcepas/ncbi_taxonomy . I wrote some more info at http://jhcepas.cgenomics.org/?p=216
something like Last Common Ancestor From Ncbi Taxonomy Using Java ?
Not exactly, but i think it is useful.I might use it in the future. Thanks a lot.
Lhl
Yes. This is exactly what i want.
Many thanks.
Lhl
I'm trying this method as well.
Can someone tell me how I can convert the output to a Newick file?