Skip to content

Commit

Permalink
Fix ply warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
emunozdc authored and emunozdc committed Jun 22, 2024
1 parent 3881687 commit 11cf94a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
9 changes: 9 additions & 0 deletions src/pyranges_plot/plot_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ def getvalue(key):
df_d[pr_ix], tot_ngenes = make_subset(df_item, ID_COL, max_shown)
tot_ngenes_l.append(tot_ngenes)

for tot_ngenes in tot_ngenes_l:
if tot_ngenes > max_shown:
subset_warn = 1
break
else:
subset_warn = 0

# concat subset dataframes and create new column with input list index
if not df_d:
raise Exception("The provided PyRanges object/s are empty.")
Expand Down Expand Up @@ -507,6 +514,7 @@ def getvalue(key):
# print("\n\n")
# print("data used for plotting")
# print(subdf)
print(tot_ngenes_l)

if engine in ["plt", "matplotlib"]:
if not missing_plt_flag:
Expand Down Expand Up @@ -564,6 +572,7 @@ def getvalue(key):
warnings=warnings,
tick_pos_d=tick_pos_d,
ori_tick_pos_d=ori_tick_pos_d,
subset_warn=subset_warn,
)
else:
raise Exception(
Expand Down
16 changes: 8 additions & 8 deletions src/pyranges_plot/plotly_base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ def initialize_dash_app(fig, max_shown):
def show_subs_warning(grfig):
if grfig["data"][0]["customdata"][0] == "no warnings":
return False
n_genes = int(grfig["data"][0]["customdata"][0])
if n_genes > max_shown:
warn = int(grfig["data"][0]["customdata"][0])
if warn:
return True

@app.callback(
Output("alert-uncolored", "is_open"),
Input("genes-plot", "figure"),
)
# def show_uncol_warning(grfig):
# if grfig["data"][0]["customdata"][0] == "no warnings":
# return False
# sign = int(grfig["data"][0]["customdata"][1])
# if sign == 91124:
# return True
def show_uncol_warning(grfig):
if grfig["data"][0]["customdata"][0] == "no warnings":
return False
sign = int(grfig["data"][0]["customdata"][1])
if sign == 91124:
return True

@app.callback(
Output("alert-iteration", "is_open"),
Expand Down
32 changes: 16 additions & 16 deletions src/pyranges_plot/plotly_base/plot_exons_ply.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def plot_exons_ply(
warnings=None,
tick_pos_d=None,
ori_tick_pos_d=None,
subset_warn=0,
):
"""Create Plotly plot."""

Expand Down Expand Up @@ -128,31 +129,30 @@ def plot_exons_ply(
# insert silent information for warnings
if warnings:
fig.data[0].customdata = np.array([0, 0, 0]) # [tot_ngenes_l, 0, 0])
if (
"_blackwarning!" in genesmd_df.columns
and "_iterwarning!" in genesmd_df.columns
):
if "_blackwarning!" in subdf.columns and "_iterwarning!" in subdf.columns:
fig.data[0].customdata = np.array(
[0, 91124, 91321]
) # [tot_ngenes_l, 91124, 91321])
elif (
"_blackwarning!" in genesmd_df.columns
and "_iterwarning!" not in genesmd_df.columns
):
[subset_warn, 91124, 91321]
) # [subset_warn, 91124, 91321])
elif "_blackwarning!" in subdf.columns and "_iterwarning!" not in subdf.columns:
fig.data[0].customdata = np.array(
[subset_warn, 91124, 0]
) # [subset_warn, 91124, 0])
elif "_blackwarning!" not in subdf.columns and "_iterwarning!" in subdf.columns:
fig.data[0].customdata = np.array(
[0, 91124, 0]
) # [tot_ngenes_l, 91124, 0])
[subset_warn, 0, 91321]
) # [subset_warn, 0, 91321])
elif (
"_blackwarning!" not in genesmd_df.columns
and "_iterwarning!" in genesmd_df.columns
"_blackwarning!" not in subdf.columns
and "_iterwarning!" not in subdf.columns
):
fig.data[0].customdata = np.array(
[0, 0, 91321]
) # [tot_ngenes_l, 0, 91321])
[subset_warn, 0, 0]
) # [subset_warn, 0, 91321])
else:
fig.data[0].customdata = np.array(["no warnings"])

if to_file is None:
print(fig["data"][0]["customdata"][0])
app_instance = initialize_dash_app(fig, max_shown)
app_instance.run(port=plotly_port)

Expand Down

0 comments on commit 11cf94a

Please sign in to comment.