Skip to content

Commit 8c6e299

Browse files
committed
update alignment width, midgroup
1 parent 8a46b23 commit 8c6e299

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

treeprofiler/layouts/seq_layouts.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def get_colormap():
2121

2222
class LayoutAlignment(TreeLayout):
2323
def __init__(self, name="Alignment",
24-
alignment=None, alignment_prop=None, format='seq', width=700, height=15,
24+
alignment=None, alignment_prop=None, format='seq', width=800, height=15,
2525
column=0, scale_range=None, window=[], summarize_inner_nodes=True,
2626
aligned_faces=True):
2727
super().__init__(name, aligned_faces=aligned_faces)
2828
#self.alignment = SeqGroup(alignment) if alignment else None
2929
self.alignment_prop = alignment_prop
30-
self.width = width
30+
self.width = int(width)
3131
self.height = height
3232
self.column = column
3333
self.aligned_faces = True
@@ -81,20 +81,30 @@ def layout_fn(node):
8181
class LayoutDomain(TreeLayout):
8282
def __init__(self, prop, name,
8383
column=10, colormap={},
84-
min_fsize=4, max_fsize=15,
85-
padding_x=5, padding_y=0):
84+
min_fsize=4, max_fsize=15,
85+
padding_x=5, padding_y=0, width=800):
8686
super().__init__(name or "Domains layout")
8787
self.prop = prop
8888
self.column = column
8989
self.aligned_faces = True
9090
self.min_fsize = min_fsize
9191
self.max_fsize = max_fsize
9292
self.padding = draw_helpers.Padding(padding_x, padding_y)
93+
self.width = int(width)
9394
if not colormap:
9495
self.colormap = get_colormap()
9596
else:
9697
self.colormap = colormap
9798

99+
def set_tree_style(self, tree, tree_style):
100+
super().set_tree_style(tree, tree_style)
101+
if self.legend:
102+
if self.colormap:
103+
tree_style.add_legend(title=self.name,
104+
variable='discrete',
105+
colormap=self.colormap,
106+
)
107+
98108
def get_doms(self, node):
99109
pair_delimiter = "@"
100110
item_seperator = "||"
@@ -118,7 +128,7 @@ def parse_doms(self, dom_list):
118128
color = self.colormap.get(name, "lightgray")
119129
dom = [int(start), int(end), "()",
120130
None, None, color, color,
121-
"arial|30|black|%s" %(name)]
131+
f"arial|30|black|{name}"]
122132
doms.append(dom)
123133
return doms
124134

@@ -129,13 +139,13 @@ def set_node_style(self, node):
129139
fake_seq = '-' * int(node.props.get("len_alg", 0))
130140

131141
if doms or fake_seq:
132-
seqFace = SeqMotifFace(seq=fake_seq, motifs=doms, width=400,
142+
seqFace = SeqMotifFace(seq=fake_seq, motifs=doms, width=self.width,
133143
height=30)
134144
node.add_face(seqFace, column=self.column,
135145
position="aligned",
136146
collapsed_only=(not node.is_leaf))
137-
else:
138-
print("no domain found for node %s" % node.name)
147+
# else:
148+
# print("no domain found for node %s" % node.name)
139149

140150
class ScaleFace(Face):
141151
def __init__(self, name='', width=None, color='black',

treeprofiler/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def populate_main_args(main_args_p):
4848
action='store_true',
4949
required=False,
5050
help="Preprocess tree by changing polytomies into series of dicotomies.")
51+
group.add_argument('--midgroup',
52+
default=False,
53+
action='store_true',
54+
required=False,
55+
help="Set midgroup for the tree, which is used to determine the root of the tree. ")
5156
group = main_args_p.add_argument_group(title='Pruning parameters',
5257
description="Auto pruning parameters")
5358
group.add_argument('--rank-limit',

treeprofiler/tree_annotate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,9 @@ def run(args):
775775
if args.resolve_polytomy:
776776
tree.resolve_polytomy()
777777

778+
if args.midgroup:
779+
tree.set_outgroup(tree.get_midpoint_outgroup())
780+
778781
# set logger level
779782
if args.quiet:
780783
logger.setLevel(logging.CRITICAL) # Mute all log levels below CRITICA
@@ -1400,8 +1403,9 @@ def process_node(node_data):
14001403
if alignment and name2seq is not None: # Check alignment and name2seq together
14011404
aln_sum = column2method.get('alignment')
14021405
if aln_sum is None or aln_sum != 'none' or consensus_cutoff is not None:
1403-
matrix_string = build_matrix_string(node, name2seq) # Assuming 'name2seq' is accessible here
1404-
consensus_seq = utils.get_consensus_seq(matrix_string, threshold=consensus_cutoff)
1406+
if consensus_cutoff != 0:
1407+
matrix_string = build_matrix_string(node, name2seq) # Assuming 'name2seq' is accessible here
1408+
consensus_seq = utils.get_consensus_seq(matrix_string, threshold=consensus_cutoff)
14051409

14061410
return internal_props, consensus_seq
14071411

treeprofiler/tree_plot.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ def poplulate_plot_args(plot_args_p):
302302
default=None,
303303
required=False,
304304
help="Set the window of alignment layout. Such as: 3-200, from position 3 to 200.")
305+
group.add_argument('--alignment-width',
306+
default=800,
307+
required=False,
308+
help="Set the width of alignment/domain layout, default is 800px.")
305309
group.add_argument('--profiling-layout',
306310
nargs='+',
307311
required=False,
@@ -394,6 +398,9 @@ def run(args):
394398
if args.resolve_polytomy:
395399
tree.resolve_polytomy()
396400

401+
if args.midgroup:
402+
tree.set_outgroup(tree.get_midpoint_outgroup())
403+
397404
#rest_prop = []
398405
if args.prop2type:
399406
if eteformat_flag:
@@ -715,13 +722,15 @@ def run(args):
715722
else:
716723
window = []
717724

725+
width = args.alignment_width
718726
aln_layout = seq_layouts.LayoutAlignment(name='Alignment',
719727
alignment_prop='alignment', column=level, scale_range=lengh,
720-
window=window, summarize_inner_nodes=True)
728+
window=window, width=width, summarize_inner_nodes=True)
721729
layouts.append(aln_layout)
722730

723731
if layout == 'domain-layout':
724-
domain_layout = seq_layouts.LayoutDomain(name="Domain", prop='dom_arq')
732+
width = args.alignment_width
733+
domain_layout = seq_layouts.LayoutDomain(name="Domain", prop='dom_arq', width=width)
725734
layouts.append(domain_layout)
726735

727736
# presence-absence profiling based on categorical data

0 commit comments

Comments
 (0)