# HG changeset patch # User boris # Date 1374270298 14400 # Node ID dd39849c2ff1fe71750d42175e87de9ca81d08c8 # Parent 369f0b641498bc8e55d99581c315693d6a36dbd1 plot now highlights minor allele sequences in tree diff -r 369f0b641498 -r dd39849c2ff1 phylorelatives.py --- a/phylorelatives.py Tue Jun 25 00:41:54 2013 -0400 +++ b/phylorelatives.py Fri Jul 19 17:44:58 2013 -0400 @@ -97,45 +97,27 @@ return ascii_tree -def ape_plot_tree(outfile, tree1, tree2=None, root=False): +def ape_plot_tree(outfile, tree1, root=False): """Plot tree to png file""" ape = importr('ape') graphics = importr('graphics') grdevices = importr('grDevices') - if tree2 is None: - grdevices.png(file=outfile, width=1024, height=768) - if root: - ape.plot_phylo(ape.root(tree1,root),use_edge_length=0, - show_node_label=1,edge_width=2, font=2, - cex=1,underscore=0, no_margin=1) - else: - ape.plot_phylo(tree1,use_edge_length=0, - show_node_label=1,edge_width=2, font=2, - cex=1,underscore=0, no_margin=1) - #graphics.title(main='Neighbor Joining') - grdevices.dev_off() - elif tree2 is not None: - grdevices.png(file=outfile, width=1024, height=768) - graphics.par(mfcol=array.array('i',[1,2])) - if root: - ape.plot_phylo(ape.root(tree1,root),use_edge_length=0, - show_node_label=1,edge_width=2, font=2, - cex=1,underscore=0, no_margin=1) - else: - ape.plot_phylo(tree1,use_edge_length=0, - show_node_label=1,edge_width=2, font=2, - cex=1,underscore=0, no_margin=1) - graphics.title(main='Neighbor Joining', cex=1.5, font=2) - if root: - ape.plot_phylo(ape.root(tree2,root),use_edge_length=0, - show_node_label=1,edge_width=2, font=2, - cex=1,underscore=0, no_margin=1) - else: - ape.plot_phylo(tree2,use_edge_length=0, - show_node_label=1,edge_width=2, font=2, - cex=1,underscore=0, no_margin=1) - graphics.title(main='Maximum Parsimony',cex=1.5, font=2) - grdevices.dev_off() + grdevices.png(file=outfile, width=1024, height=768) + if root: + tree = ape.root(tree1,root) + labels = list(tree.rx("tip.label")[0]) + colors = robjects.StrVector(["red" if tip.endswith("_minor") else "black" for tip in labels]) + ape.plot_phylo(tree,tip_color=colors,use_edge_length=0, + show_node_label=1,edge_width=2, font=2, + cex=1,underscore=0, no_margin=1) + else: + tree = tree1 + labels = list(tree.rx("tip.label")[0]) + colors = robjects.StrVector(["red" if tip.endswith("_minor") else "black" for tip in labels]) + ape.plot_phylo(tree,tip_color=colors,use_edge_length=0, + show_node_label=1,edge_width=2, font=2, + cex=1,underscore=0, no_margin=1) + #graphics.title(main='Neighbor Joining') return