Parse figtree file with Python
1
1
Entering edit mode
8.8 years ago
konstantinkul ▴ 110

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!

python figtree • 1.9k views
ADD COMMENT
1
Entering edit mode
8.8 years ago
moranr ▴ 290

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')
ADD COMMENT
0
Entering edit mode

Thank you for suggestion! I'll try it!

ADD REPLY

Login before adding your answer.

Traffic: 2190 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6