How To Replace Tree Name By Dot
4
1
Entering edit mode
14.1 years ago
Pavid ▴ 160

Hi guys!

In my tree I would like to represent each sequence by a dot, instead of the sequence name. I've been looking around but didn't find what I wanted.

I'm working on phylip drawtree but I don't mind changing.
I would like some software that do that automatically. I known that I can change manually in most softwares, but I looking for something that it's able to deal with this automatically.

This is kind of new to me.
If anyone knowns how to do this I would appreciate.

Thanks!!

tree phylogenetics • 5.4k views
ADD COMMENT
1
Entering edit mode

This is not very clear. Do you mean that you want to alter the output of the drawtree program? And if so, what input format are you using?

ADD REPLY
0
Entering edit mode

I added an image showing what I pretend. Yes I what to alter the output, instead of the name, dots. like the image. I'm using an .dnd file to build the tree

ADD REPLY
3
Entering edit mode
14.1 years ago
Maik ▴ 30

Hi Patricia,

I use ETE to manipulate and visualize trees. It does not have unrooted tree visualization support yet, but you can render custom tree images with very simple scripts.

There are some examples in its web site: http://ete.cgenomics.org/node/27, http://ete.cgenomics.org/node/30

ETE is a library rather than a standalone program, so your problem could be addressed in many different ways.This would be a simple example addressing your question:

from ete2 import Tree, faces

def my_layout(node):
   if node.is_leaf():
      F = faces.ImgFace("/path/to/image.png") # This could be any icon
      faces.add_face_to_node(F, node, 0)
      node.img_style["size"]=20 # Draws a sphere
      node.img_style["fgcolor"] = "#ff0000" # sphere color

tree = Tree("((A, B), C);")
tree.show(my_layout)
# or
tree.render("image.pdf", my_layout)

You can add many faces (graphical items) to any node (internal or leaf).

ADD COMMENT
2
Entering edit mode
14.1 years ago
Paulo Nuin ★ 3.7k

You can use something like Dendroscope to modify the labels on your leaves or even manually change the labels by editing the tree file as it's in ASCII format.

Edit: If you want to it automatically, there are many options to do that. One would be to use a simple command line awk script that would replace the labels such as

awk '{ gsub(/<label>/, "...."); print }'

If you want to replace more than one label at a time you can wrap this on a loop that feeds the labels you want changed.

But this would work for Linux/Mac maybe not on Windows.

ADD COMMENT
0
Entering edit mode

I'm trying to do that automatically, at least that's what I wanted but I not sure is anything is avalaible. I edit my post with a picture to represent

ADD REPLY
0
Entering edit mode

Easier than putting the tree image would be to put the original tree file.

ADD REPLY
0
Entering edit mode

the tree image is from a paper, wasn't built by me. the thing is that I need to display it on a django interface and most of the programs don't work, I manage to create a tree with biopython. Perhaps with a python script it will work.. Not sure

ADD REPLY
0
Entering edit mode

I guess we would need more information before assessing your question.

ADD REPLY
1
Entering edit mode
14.1 years ago
Dave Lunt ★ 2.0k

Patricia, I think you can replicate your picture in ScripTree. You can easily add any graphic at the tips (circles). I believe you can also prevent it from displaying names, although I'm on the road at the moment and can't test that. Check the documentation, it implies the same. Once you have your script it is all easy to replicate automatically.

ADD COMMENT
1
Entering edit mode
14.1 years ago
Pavid ▴ 160

well here's another way to do this, with BioPython:

#basically a stripped down rewrite of Phylo.draw_graphviz
import networkx, pylab
from Bio import Phylo

#taken from draw_graphviz
def get_label_mapping(G, selection): 
    for node in G.nodes(): 
        if (selection is None) or (node in selection): 
            try: 
                label = str(node) 
                if label not in (None, node.__class__.__name__): 
                    yield (node, label) 
            except (LookupError, AttributeError, ValueError): 
                pass

kwargs={}
tree = Phylo.read('tree.dnd', 'newick')
G = Phylo.to_networkx(tree)
Gi = networkx.convert_node_labels_to_integers(G, discard_old_labels=False)

node_sizes = []
labels = dict(get_label_mapping(G, None))
kwargs['nodelist'] = labels.keys()

#create our node sizes based on our labels because the labels are used for the node_list this way they should be correct
for label in labels.keys():
    if str(label) != "Clade":
        num = label.name.split('-')
        size = int(num[-1]) * 50
        node_sizes.append(size)

kwargs['node_size'] = node_sizes
posi = networkx.pygraphviz_layout(Gi, 'neato', args='') 
posn = dict((n, posi[Gi.node_labels[n]]) for n in G)

networkx.draw(G, posn, labels=labels, node_color='#c0deff', **kwargs)

pylab.show()
ADD COMMENT

Login before adding your answer.

Traffic: 2524 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