Thursday, December 10, 2009

PyCogent 13: Tree with colored edges

I'm exploring PyCogent (docs, download page)---first post here.

Continuing from the last post, we use PyCogent to plot the tree. By looking at the source code, I figured out how to color the edges, but I haven't seen how to color the tip labels. It would also be useful to be able to edit the labels.

from cogent import LoadTree
from cogent.draw import dendrogram

fn = 'temp.tree'
t = LoadTree(fn)

def f(node):
L = ['DQ450530','AJ278451','AF411020']
if node.isTip():
name = node.getTipNames()[0]
for e in L:
if e in name: return 'blue'
return 'red'
return 'black'

height, width = 500,500
np = dendrogram.ContemporaneousDendrogram(t)

No comments: