Help marking branches, how to get node_ids ?

57 views
Skip to first unread message

sahais

unread,
May 6, 2020, 10:17:25 AM5/6/20
to The ETE toolkit

Hello,

I am trying to mark branches of my tree for positive selection analysis. I was following the online tutorial and did the following:

tree = EvolTree("(((Latimeria_chalumnae,(Lepisosteus_oculatus,Danio_rerio)),(Callorhinchus_milii,(Scyliorhinus_torazame,(Chiloscyllium_punctatum,Rhincodon_typus),Carcharodon_carcharias))));")

marks = ['4', '5', '6', '7', '8']
tree.mark_tree (marks, ['#1', '#1', '#1', '#1', '#1'])

I would like the following output:

tree = EvolTree("(((Latimeria_chalumnae,(Lepisosteus_oculatus,Danio_rerio)),(Callorhinchus_milii #1,(Scyliorhinus_torazame #1,(Chiloscyllium_punctatum #1,Rhincodon_typus #1),Carcharodon_carcharias #1))));")

However, the marks are not put in that order and appear to be assigned randomly between runs. I know I have to get the node_id of the species to assign the marks but I cannot find the function to get the node_id for a set of species in the tree. Can someone help me? I have also tried manually marking the tree but I got an error as well. 

ziqi deng

unread,
May 6, 2020, 11:06:04 AM5/6/20
to The ETE toolkit
Hi, add_feature() method can be helpful in your case, which allows you to add and customize your annotation to any node.

In your case here your species are the leaves, so

mark_list=[spec1, spec2, spec3] #set the marking species

# mark species which in the list
for leaf in tree.iter_leaves():
   
if leaf in mark_list:
        leaf
.add_feature("mark", "#1") # add_feature(label, value)
   
else:
        leaf
.add_feature("mark", "")

#display
print(tree.get_ascii(attributes='mark'))

#write to file
tree.write(features=['mark'])

For further reference, please check this documentation:
http://etetoolkit.org/docs/latest/tutorial/tutorial_trees.html#node-annotation



在 2020年5月6日星期三 UTC+2下午4:17:25,sahais写道:

Jaime Huerta Cepas

unread,
May 6, 2020, 11:44:47 AM5/6/20
to eteto...@googlegroups.com
ziqi's solution is right, but when added as node features the marks will be witten as extended newick when exported. 
To reproduce the output you mentioned in your question, you could use the same code, but modifying directly the name of the leaf nodes: 

...
if leaf in mark_list:
   leaf.name = leaf.name + " #1"
 ...


--
You received this message because you are subscribed to the Google Groups "The ETE toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to etetoolkit+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/etetoolkit/1997968b-bf4b-499b-8e8d-fe4b4230f6d3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages