etetoolkit / ete

Python package for building, comparing, annotating, manipulating and visualising trees. It provides a comprehensive API and a collection of command line tools, including utilities to work with the NCBI taxonomy tree.
http://etetoolkit.org
GNU General Public License v3.0
786 stars 214 forks source link

Tree render/show method bronken afte edit SeqMotifFace #364

Closed acpguedes closed 6 years ago

acpguedes commented 6 years ago

I'm trying to draw a tree with SeqMotifFace to set build domains as face of each leaf.

Since I'm using Pandas, I have a dataframe like this:

ID domain start end evalue fg bg w h shape
seq1 AMM 6 396 1.500000e-118 #bf443f #bf433f None 10 ()
seq1 HisKA 469 534 4.000000e-21 #bf5f3f #bf433f None 10 ()
seq2 AMM 37 427 2.000000e-110 #bf443f #bf433f None 10 ()
seq2 PAS_9 506 600 2.100000e-05 #bf443f #bf413f None 10 ()

I also have a tree for theses sequences.

So, I'm using a for loop to set the face of the sequences this way

for i in ( list(set(dom.ID)) ):  
    motifs=dom[dom.ID == i][['start', 'end', 'shape', 'w', 'h', 'fg', 'bg', 'domain']].values.tolist()  
    print (i, motifs, "\n")  
    seqface = SeqMotifFace(None, motifs=motifs)  
    (t & i).add_face(seqface, 0, 'aligned')

The print above turns:

Seq4 [[14, 405, '()', None, 10, '#bf443f', '#bf433f', 'AMM'], [457, 555, '()', None, 10, '#bf453f', '#bf513f', 'PAS'], [581, 688, '()', None, 10, '#bf6a3f', '#bf433f', 'HisKa']]
Seq5 [[8, 387, '()', None, 10, '#bf443f', '#bf433f', 'AMM'], [358, 445, '()', None, 10, '#bf463f', '#bf433f', 'SMC_ScpA']]

Exactly as required for motifs.

No error is returned in this loop, but...
When I try something like t.render("%%inline") or t.show I get this error


ValueError Traceback (most recent call last)

in () ----> 1 t.show() ~/sbin/anaconda3/lib/python3.6/site-packages/ete3/coretype/tree.py in show(self, layout, tree_style, name) 1333 from ..treeview import drawer 1334 drawer.show_tree(self, layout=layout, -> 1335 tree_style=tree_style, win_name=name) 1336 1337 def render(self, file_name, layout=None, w=None, h=None, \ ~/sbin/anaconda3/lib/python3.6/site-packages/ete3/treeview/drawer.py in show_tree(t, layout, tree_style, win_name) 74 """ Interactively shows a tree.""" 75 scene, img = init_scene(t, layout, tree_style) ---> 76 tree_item, n2i, n2f = render(t, img) 77 scene.init_values(t, img, n2i, n2f) 78 ~/sbin/anaconda3/lib/python3.6/site-packages/ete3/treeview/qt4_render.py in render(root_node, img, hide_root) 266 virtual_leaves += 1 267 --> 268 update_node_faces(n, n2f, img) 269 270 rot_step = float(arc_span) / virtual_leaves ~/sbin/anaconda3/lib/python3.6/site-packages/ete3/treeview/qt4_face_render.py in update_node_faces(node, n2f, img) 387 as_grid = False 388 --> 389 faceblock[position] = _FaceGroupItem(all_faces, node, as_grid=as_grid) 390 391 # all temp and fixed faces are now referenced by the faceblock, so ~/sbin/anaconda3/lib/python3.6/site-packages/ete3/treeview/qt4_face_render.py in __init__(self, faces, node, as_grid) 99 self.h = 0 100 # updates the size of this grid --> 101 self.update_columns_size() 102 103 def set_min_column_widths(self, column_widths): ~/sbin/anaconda3/lib/python3.6/site-packages/ete3/treeview/qt4_face_render.py in update_columns_size(self, norender) 137 f.update_pixmap() 138 elif f.type == "item" and not norender: --> 139 f.update_items() 140 elif f.type == "text" and f.rotation: 141 f.tight_text = False ~/sbin/anaconda3/lib/python3.6/site-packages/ete3/treeview/faces.py in update_items(self) 1906 1907 if name and i: -> 1908 family, fsize, fcolor, text = name.split("|") 1909 #qfmetrics = QFontMetrics(qfont) 1910 #txth = qfmetrics.height() ValueError: not enough values to unpack (expected 4, got 1)

The tree is okay, if I just load the tree and try render or show it's been drawn nicely.I just got the error after insert motif face.

acpguedes commented 6 years ago

UPDATE:

add font size and color to motif name

Anyway didn't work

for i in t.get_leaf_names():
    motifs=dom[dom.ID == i][['start', 'end', 'shape', 'w', 'h', 'fg', 'bg', 'domain']].values.tolist()
    seq=str(f[i].seq)
    _ = []
    motifs2 = list()
    for m in motifs:
        _ = "arial|8|white|" + m[7]
        motifs2.append(m[0:7] +[_])
    print(motifs2)
    seqface = SeqMotifFace(seq, motifs=motifs2)
    (t & i).add_face(seqface, 0, 'aligned')
jhcepas commented 6 years ago

is it solved? otherwise leave the issue open so we can track all bugs for next code sprints...