@@ -28,7 +28,7 @@ def write_to_path(self, path):
28
28
for style in self .styles :
29
29
nexss_file .write (style [1 ] + '\n \n ' )
30
30
31
- def annotate_node (self , node , tag , content , style ):
31
+ def annotate_node (self , node , tag , content , style , mode = 'overwrite' ):
32
32
33
33
node .annotations .drop (name = tag )
34
34
@@ -47,7 +47,14 @@ def annotate_node(self, node, tag, content, style):
47
47
48
48
sid_idx = self .style_id_index (style_id )
49
49
if sid_idx >= 0 :
50
- self .styles .pop (sid_idx )
50
+ if mode == 'overwrite' :
51
+ self .styles .pop (sid_idx )
52
+ elif mode == 'append' :
53
+ for k in style :
54
+ self .styles [sid_idx ][2 ][k ] = style [k ]
55
+ style = self .styles [sid_idx ][2 ]
56
+ else :
57
+ raise NotImplementedError ()
51
58
52
59
style_str_left = style_id + ' {\n '
53
60
style_str_right = '}'
@@ -58,7 +65,10 @@ def annotate_node(self, node, tag, content, style):
58
65
59
66
style_str = style_str + style_str_right
60
67
61
- self .styles .append ([style_id , style_str ])
68
+ if mode == 'overwrite' :
69
+ self .styles .append ([style_id , style_str , style ])
70
+ elif mode == 'append' :
71
+ self .styles [sid_idx ][1 ] = style_str
62
72
63
73
# Utility functions ------------------------------------------------------------
64
74
@@ -367,6 +377,33 @@ def tol_mrca(ott_ids):
367
377
content = node .taxon .label ,
368
378
style = style )
369
379
380
+ node = tol_subtree .find_node (lambda x : (x .taxon is not None ) and (x .taxon .label == 'Pongo' ))
381
+ style = {'border' : '2px' }
382
+ nexss .annotate_node (
383
+ node = node ,
384
+ tag = 'clade' ,
385
+ content = node .taxon .label ,
386
+ style = style ,
387
+ mode = 'append' )
388
+
389
+ node = tol_subtree .find_node (lambda x : (x .taxon is not None ) and (x .taxon .label == 'Hoolock' ))
390
+ style = {'border' : '4px' }
391
+ nexss .annotate_node (
392
+ node = node ,
393
+ tag = 'clade' ,
394
+ content = node .taxon .label ,
395
+ style = style ,
396
+ mode = 'append' )
397
+
398
+ node = tol_subtree .find_node (lambda x : (x .taxon is not None ) and (x .taxon .label == 'Hylobates_lar' ))
399
+ style = {'border' : '6px' }
400
+ nexss .annotate_node (
401
+ node = node ,
402
+ tag = 'clade' ,
403
+ content = node .taxon .label ,
404
+ style = style ,
405
+ mode = 'append' )
406
+
370
407
tol_subtree .ladderize (ascending = True )
371
408
372
409
nexss .write_to_path ('/Users/karolis/Desktop/' + clade + '.nexss' )
0 commit comments