Skip to content

Commit 7be75c7

Browse files
committed
Adds NEXSS builduip feature.
1 parent ffd8ab3 commit 7be75c7

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

examples/opentree-nexss/opentree-nexss.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def write_to_path(self, path):
2828
for style in self.styles:
2929
nexss_file.write(style[1] + '\n\n')
3030

31-
def annotate_node(self, node, tag, content, style):
31+
def annotate_node(self, node, tag, content, style, mode='overwrite'):
3232

3333
node.annotations.drop(name=tag)
3434

@@ -47,7 +47,14 @@ def annotate_node(self, node, tag, content, style):
4747

4848
sid_idx = self.style_id_index(style_id)
4949
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()
5158

5259
style_str_left = style_id + ' {\n'
5360
style_str_right = '}'
@@ -58,7 +65,10 @@ def annotate_node(self, node, tag, content, style):
5865

5966
style_str = style_str + style_str_right
6067

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
6272

6373
# Utility functions ------------------------------------------------------------
6474

@@ -367,6 +377,33 @@ def tol_mrca(ott_ids):
367377
content=node.taxon.label,
368378
style=style)
369379

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+
370407
tol_subtree.ladderize(ascending=True)
371408

372409
nexss.write_to_path('/Users/karolis/Desktop/' + clade + '.nexss')

0 commit comments

Comments
 (0)