Skip to content

Commit

Permalink
Merge pull request #109 from compgenomicslab/dev-repo
Browse files Browse the repository at this point in the history
Dev repo
  • Loading branch information
dengzq1234 authored Jan 14, 2025
2 parents 7f593bc + 75ba902 commit 221b335
Show file tree
Hide file tree
Showing 6 changed files with 1,016 additions and 201 deletions.
753 changes: 638 additions & 115 deletions treeprofiler/app.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions treeprofiler/layouts/staple_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def __init__(self, name=None, prop=None, width=200, size_prop=None,
self.size_prop = size_prop
self.color_prop = color_prop
self.size_range = size_range
self.size_range = size_range

self.color = color
self.colors = colors
Expand Down Expand Up @@ -145,6 +144,7 @@ def get_size(self, node, prop):
if not self.size_prop:
return self.width
minval, maxval = self.size_range

return float(node.props.get(prop, 0)) / maxval * self.width

def get_color(self, node):
Expand Down Expand Up @@ -571,7 +571,7 @@ def __init__(self, name=None, prop=None, position="aligned",
bubble_range=[], color_range=[], internal_rep='avg',
scale=True, legend=True, active=True):

name = name or f'Bubble_{prop}'
name = name or f'NumericalBubble_{prop}'
super().__init__(name)

self.aligned_faces = True
Expand Down
4 changes: 2 additions & 2 deletions treeprofiler/layouts/text_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def __init__(self, name=None, prop=None, position="branch_right",
max_radius=1, padding_x=2, padding_y=0,
scale=True, legend=True, active=True):

name = name or f'Bubble_{prop}'
name = name or f'CategoricalBubble_{prop}'
super().__init__(name)

self.aligned_faces = True
Expand Down Expand Up @@ -537,7 +537,7 @@ def set_node_style(self, node):
# node.sm_style["fgopacity"] = self.fgopacity
prop_face = CircleFace(radius=bubble_size, color=bubble_color,
padding_x=self.padding_x, padding_y=self.padding_y)
node.add_face(prop_face, column=0,
node.add_face(prop_face, column=self.column,
position="branch_right", collapsed_only=False)


24 changes: 15 additions & 9 deletions treeprofiler/tree_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,21 +480,30 @@ def run(args):
# layouts.extend(heatmap_layouts)

if layout == 'heatmap-layout':
heatmap_layouts, level = get_heatmap_layouts(tree, args.heatmap_layout, level, column_width=args.column_width, padding_x=args.padding_x, padding_y=args.padding_y, internal_rep=internal_num_rep, color_config=color_config, norm_method='min-max')
heatmap_layouts, level = get_heatmap_layouts(tree,
args.heatmap_layout, level, column_width=args.column_width,
padding_x=args.padding_x, padding_y=args.padding_y,
internal_rep=internal_num_rep, color_config=color_config, norm_method='min-max')
layouts.extend(heatmap_layouts)
for prop in args.heatmap_layout:
visualized_props.append(prop)
visualized_props.append(utils.add_suffix(prop, internal_num_rep))

if layout == 'heatmap-mean-layout':
heatmap_mean_layouts, level = get_heatmap_layouts(tree, args.heatmap_mean_layout, level, column_width=args.column_width, padding_x=args.padding_x, padding_y=args.padding_y, internal_rep=internal_num_rep, color_config=color_config, norm_method='mean')
heatmap_mean_layouts, level = get_heatmap_layouts(tree,
args.heatmap_mean_layout, level, column_width=args.column_width,
padding_x=args.padding_x, padding_y=args.padding_y,
internal_rep=internal_num_rep, color_config=color_config, norm_method='mean')
layouts.extend(heatmap_mean_layouts)
for prop in args.heatmap_mean_layout:
visualized_props.append(prop)
visualized_props.append(utils.add_suffix(prop, internal_num_rep))

if layout == 'heatmap-zscore-layout':
heatmap_zscore_layouts, level = get_heatmap_layouts(tree, args.heatmap_zscore_layout, level, column_width=args.column_width, padding_x=args.padding_x, padding_y=args.padding_y, internal_rep=internal_num_rep, color_config=color_config, norm_method='zscore')
heatmap_zscore_layouts, level = get_heatmap_layouts(tree,
args.heatmap_zscore_layout, level, column_width=args.column_width,
padding_x=args.padding_x, padding_y=args.padding_y,
internal_rep=internal_num_rep, color_config=color_config, norm_method='zscore')
layouts.extend(heatmap_zscore_layouts)
for prop in args.heatmap_zscore_layout:
visualized_props.append(prop)
Expand Down Expand Up @@ -1499,6 +1508,7 @@ def get_categorical_bubble_layouts(tree, props, level, prop2type, column_width=7
prop_color_dict = {}
layouts = []
max_radius = 15
level = level + 1 # add one more level for bubble layout because 0 is leaf name
for prop in props:
color_dict = {} # key = value, value = color id
if color_config and color_config.get(prop):
Expand All @@ -1518,11 +1528,7 @@ def get_categorical_bubble_layouts(tree, props, level, prop2type, column_width=7
# normal text prop
color_dict = utils.assign_color_to_values(prop_values, paired_color)

# layout = text_layouts.LayoutRect(name='Rectangular_'+prop, column=level,
# color_dict=color_dict, prop=prop,
# width=column_width, padding_x=padding_x, padding_y=padding_y)
# Configure and add layout
layout = text_layouts.LayoutBubbleCategorical(name=f'Bubble_{prop}', column=level,
layout = text_layouts.LayoutBubbleCategorical(name=f'Categorical-Bubble_{prop}', column=level,
prop=prop, color_dict=color_dict,
max_radius=max_radius, padding_x=padding_x, padding_y=padding_y)

Expand Down Expand Up @@ -1606,7 +1612,7 @@ def process_prop_values(tree, prop):
value2color[val] = gradientscolor[color_index+1]

# Configure and add layout
layout = staple_layouts.LayoutBubbleNumerical(name=f'Bubble_{prop}',
layout = staple_layouts.LayoutBubbleNumerical(name=f'Numerical-Bubble_{prop}',
column=level, prop=prop, max_radius=max_radius, abs_maxval=abs_maxval,
padding_x=padding_x, padding_y=padding_y, value2color=value2color,
bubble_range=bubble_range,
Expand Down
Loading

0 comments on commit 221b335

Please sign in to comment.