Thank you for suggestion! I'll try it!
• 0 views
•
link
Hello, everyone!
Does anybody has or know a python library/clasess/functions to parse files of figtree format file? I need to rename a bunch of tip labels.
Thank you in advance!
Use ETE module its very easy to use and pretty cool.
I have a CSV with the original names inn one col and new names in the next col. I put this into a dict and rename by traaversing over the tree with ETE.
import csv
from ete3 import Tree, PhyloTree
#read a csv file with species names and abbreviations and replace
with open('speciesNames.csv', mode='rU') as infile:
reader = csv.reader(infile)
mydict = {rows[1]:rows[0] for rows in reader}
for n in leafTree:
leaf=str(n).replace('\n--','')
if leaf in mydict.keys():
newLeafName=mydict[leaf]
n.name=(newLeafName)
else:
print leaf + '\t' + "not in Dict"
leafTree.write(format=9,'abbNamesMetazoanTree.nw')
Thank you for suggestion! I'll try it!
Log in to answer this question.