|
I'd like to change the orientation of font faces on the output image that is produced by ETE Toolkit: http://etetoolkit.org For some reason rotation and orientation change does not affect to labels as seen on the picture below: Code to produce this example on the Jupiter notebook is following:
I would also like to know if it is possible to split the output to multiple rows instead of one line? Long sequences tend to take huge width space so it would be practical to get sequence split on several lines. |
--
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 post to this group, send email to eteto...@googlegroups.com.
Visit this group at https://groups.google.com/group/etetoolkit.
For more options, visit https://groups.google.com/d/optout.
2) If possible I'd like to get that rendered on a notebook. I suppose %%inline printer does not support this kind of multiple rendered images on a same cell behavior? Should I first save two independent images and then combine them as one with some image manipulation utility? I think you understood correctly what I'm looking for, but poorly could describe.
Thanks for all help! I got it all working pretty well:
from ete3 import Tree, TreeStyle, NodeStyle, TextFacefrom IPython.display import HTML
def tree_style(rotation): # define node/leaf modifier def rotate_labels(node): ns = NodeStyle() ns["size"] = 1 if node.is_leaf(): F = TextFace(node.name) F.rotation = rotation F.margin_right = F.margin_left = 2.0 node.add_face(F, 0, position="aligned") node.img_style = ns # init tree style ts = TreeStyle() # scale of the figure ts.scale = 10 # remove default labels ts.show_leaf_name = False # hide scale ts.show_scale = False # rotate 90 degress counterclockwise ts.rotation = rotation # orient tree from left to right ts.orientation = 1 # rotate labels ts.layout_fn = rotate_labels return ts
def get_tree(newick_str): # init tree return Tree(newick_str)
def branches(newick_str, rotation = -90): # get tree instance t = get_tree(newick_str) # length of the tree l = len(t.children) # create inline display object from each tree branch return [t.children[i].render("%%inline", tree_style=tree_style(rotation)) for i in range(l)]
def main(newick_str): # iterate over all branches on a tree and base64 encode image data for the img tag imagesList = ''.join(['<div style="height:100px;float:left;"><img src="data:image/png;base64,%s" /></div>' % base64.b64encode(branch.data).decode() for branch in branches(newick_str)]) # display on jupyter notebook cell return HTML(imagesList)
# init a newick stringnewick_str = """((p, e, a, s, ((e, _), p, o), r, r, i, d, g, (e, _)), (h, o, t), ((,, ↵), (p, e, a, s, ((e, _), p, o), r, r, i, d, g, (e, _))), (c, (o, l, d)), ((,, ↵), (p, e, a, s, ((e, _), p, o), r, r, i, d, g, (e, _))), ((i, n), _, t, h, ((e, _), p, o), t, (,, ↵), n, (i, n), (e, _), d, a, y, s, _, (o, l, d), .), ↵, ↵, (s, o, m, (e, _), l, i, k, (e, _), i, t, _), (h, o, t), ((,, ↵), (s, o, m, (e, _), l, i, k, (e, _), i, t, _)), (c, (o, l, d)), ((,, ↵), (s, o, m, (e, _), l, i, k, (e, _), i, t, _)), ((i, n), _, t, h, ((e, _), p, o), t, (,, ↵), n, (i, n), (e, _), d, a, y, s, _, (o, l, d), .));"""main(newick_str)--