Skip to content

Commit

Permalink
Merge pull request #134 from savitakartik/edge_span_and_area_plots
Browse files Browse the repository at this point in the history
add edge area histograms
  • Loading branch information
jeromekelleher authored Mar 28, 2024
2 parents 26d3ee9 + 844d8ae commit 948e93b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
33 changes: 32 additions & 1 deletion tsqc/pages/edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .. import config
from ..plot_helpers import filter_points
from ..plot_helpers import hover_points
from ..plot_helpers import make_hist


def make_edges_panel(log_y, node_type, tsm):
Expand Down Expand Up @@ -54,7 +55,37 @@ def make_edges_panel(log_y, node_type, tsm):
ylabel=y_label,
)
)
return pn.Column(main)

edges_df["time_span"] = edges_df["parent_time"] - edges_df["child_time"]
gspan_hist = make_hist(
edges_df["span"],
"Genomic span",
"auto",
log_y=log_y,
xlabel="genomic span",
ylabel="number of edges",
)
tspan_hist = make_hist(
edges_df["time_span"],
"Time span",
"auto",
log_y=log_y,
xlabel="time span",
ylabel="number of edges",
)
area_hist = make_hist(
edges_df["span"] * edges_df["time_span"],
"Edge area",
"auto",
log_y=log_y,
xlabel="time span * genomic span",
ylabel="number of edges",
)
area_hist.opts(hv.opts.Histogram(xrotation=90))
gspan_hist.opts(hv.opts.Histogram(xrotation=90))
tspan_hist.opts(hv.opts.Histogram(xrotation=90))

return pn.Column(main, pn.Row(gspan_hist, tspan_hist, area_hist))


def page(tsm):
Expand Down
2 changes: 2 additions & 0 deletions tsqc/pages/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def make_node_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="ancestor span",
ylabel="number of nodes",
)

return pn.Column(pn.Row(nodes_hist))
Expand Down
12 changes: 12 additions & 0 deletions tsqc/pages/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="number of sites",
ylabel="number of trees",
)

spans_hist = make_hist(
Expand All @@ -35,6 +37,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="genomic span",
ylabel="number of trees",
)

muts_hist = make_hist(
Expand All @@ -43,6 +47,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="number of mutations",
ylabel="number of trees",
)

tbl_hist = make_hist(
Expand All @@ -51,6 +57,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="total branch length",
ylabel="number of trees",
)

mean_arity_hist = make_hist(
Expand All @@ -59,6 +67,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="mean arity",
ylabel="number of trees",
)

max_arity_hist = make_hist(
Expand All @@ -67,6 +77,8 @@ def make_tree_hist_panel(tsm, log_y):
bins,
log_y=log_y,
plot_width=config.PLOT_WIDTH,
xlabel="max arity",
ylabel="number of trees",
)
return pn.Column(
pn.Row(
Expand Down
27 changes: 21 additions & 6 deletions tsqc/plot_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,36 @@ def compute_hist(x_range, y_range):
return compute_hist


def make_hist(data, title, bins_range, log_y=True, plot_width=800):
def make_hist(
data,
title,
bins_range,
xlabel,
ylabel="count",
log_y=True,
plot_width=400,
plot_height=400,
):
"""
Make histogram from given count data
"""
count, bins = np.histogram(data, bins=bins_range)
ylabel = "log(Count)" if log_y else "Count"
np.seterr(divide="ignore")
if log_y:
count = np.log10(count)
count[count == -np.inf] = 0
ylabel = f"log({ylabel})"

histogram = hv.Histogram((count, bins)).opts(
title=title, ylabel=ylabel, tools=["hover"]
)
histogram = histogram.opts(
shared_axes=False, width=round(plot_width / 2), toolbar=None, default_tools=[]
tools=["hover"],
shared_axes=False,
width=plot_width,
height=plot_height,
toolbar=None,
default_tools=[],
title=title,
xlabel=xlabel,
ylabel=ylabel,
)
return histogram

Expand Down

0 comments on commit 948e93b

Please sign in to comment.