Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
*.pyc
Binary file modified __pycache__/app.cpython-39.pyc
Binary file not shown.
40 changes: 31 additions & 9 deletions server/anno_vs_anno_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ def anno_vs_anno_server(input, output, session, shared):
@reactive.event(input.go_sk1, ignore_none=True)
def spac_Sankey():
adata = ad.AnnData(
X=shared['X_data'].get(),
obs=pd.DataFrame(shared['obs_data'].get()),
layers=shared['layers_data'].get(),
X=shared['X_data'].get(),
obs=pd.DataFrame(shared['obs_data'].get()),
layers=shared['layers_data'].get(),
dtype=shared['X_data'].get().dtype
)
if adata is not None:
fig = spac.visualization.sankey_plot(
adata,
source_annotation=input.sk1_anno1(),
adata,
source_annotation=input.sk1_anno1(),
target_annotation=input.sk1_anno2()
)

font_size = input.sankey_font_size()

# Modified...
# Applying font size directly to the Sankey trace for node and
# label text, as the global layout font can sometimes be ignored.
fig.update_layout(font=dict(size=font_size))
fig.update_traces(textfont=dict(size=font_size), selector=dict(type='sankey'))

return fig
return None

Expand All @@ -30,16 +39,29 @@ def spac_Sankey():
@reactive.event(input.go_rhm1, ignore_none=True)
def spac_Relational():
adata = ad.AnnData(
X=shared['X_data'].get(),
X=shared['X_data'].get(),
obs=pd.DataFrame(shared['obs_data'].get())
)
if adata is not None:
result = spac.visualization.relational_heatmap(
adata,
source_annotation=input.rhm_anno1(),
adata,
source_annotation=input.rhm_anno1(),
target_annotation=input.rhm_anno2()
)
shared['df_relational'].set(result['data'])

font_size = input.heatmap_font_size()

# Modified...
# Applying font size directly to the heatmap axes and color bar,
# as these elements often have their own font settings.
result['figure'].update_layout(
font=dict(size=font_size),
xaxis=dict(tickfont=dict(size=font_size)),
yaxis=dict(tickfont=dict(size=font_size))
)
result['figure'].update_coloraxes(colorbar_tickfont_size=font_size)

return result['figure']
return None

Expand All @@ -57,4 +79,4 @@ def download_df_1():
def download_button_ui_1():
if shared['df_relational'].get() is not None:
return ui.download_button("download_df_1", "Download Data", class_="btn-warning")
return None
return None
62 changes: 37 additions & 25 deletions server/annotations_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from shiny import ui, render, reactive
import numpy as np
import spac.visualization
# Added...
import matplotlib.pyplot as plt

def annotations_server(input, output, session, shared):
@output
Expand All @@ -11,30 +13,38 @@ def spac_Histogram_2():
if adata is None:
return None

# Added...
# Note: This assumes your UI file has a slider with the id 'annotations_font_size'.
# Please ensure this ID matches the one in your annotations_ui.py file.
font_size = input.annotations_font_size()
plt.rcParams.update({'font.size': font_size})
rotation = input.anno_slider()

# 1) If "Group By" is UNCHECKED, show a simple annotation histogram
if not input.h2_group_by_check():
fig, ax, df = spac.visualization.histogram(
adata,
annotation=input.h2_anno()
).values()
shared['df_histogram2'].set(df)
ax.tick_params(axis='x', rotation=input.anno_slider(), labelsize=10)
shared['df_histogram2'].set(df)
# Modified...
ax.tick_params(axis='x', rotation=rotation, labelsize=font_size)
return fig

# 2) If "Group By" is CHECKED, we must always supply a
# 2) If "Group By" is CHECKED, we must always supply a
# valid multiple parameter
else:
# If user also checked "Plot Together", use their selected
# If user also checked "Plot Together", use their selected
# stack type
if input.h2_together_check():
# e.g. 'stack', 'dodge', etc.
multiple_param = input.h2_together_drop()
multiple_param = input.h2_together_drop()

together_flag = True
else:
# If grouping by but not "plot together", pick a default layout
# or 'dodge' or any valid string
multiple_param = "layer"
multiple_param = "layer"
together_flag = False

fig, ax, df = spac.visualization.histogram(
Expand All @@ -44,13 +54,15 @@ def spac_Histogram_2():
together=together_flag,
multiple=multiple_param
).values()
shared['df_histogram2'].set(df)
shared['df_histogram2'].set(df)
axes = ax if isinstance(ax, (list, np.ndarray)) else [ax]
for ax in axes:
ax.tick_params(
axis='x',
rotation=input.anno_slider(),
labelsize=10
# Modified... (renamed loop variable to avoid shadowing)
for current_ax in axes:
# Modified...
current_ax.tick_params(
axis='x',
rotation=rotation,
labelsize=font_size
)
return fig
return None
Expand All @@ -61,16 +73,16 @@ def spac_Histogram_2():
def download_histogram_button_ui():
if shared['df_histogram2'].get() is not None:
return ui.download_button(
"download_histogram2_df",
"Download Data",
"download_histogram2_df",
"Download Data",
class_="btn-warning"
)
return None


@render.download(filename="annotation_histogram_data.csv")
def download_histogram2_df():
df = shared['df_histogram2'].get()
df = shared['df_human_histogram2'].get()
if df is not None:
csv_string = df.to_csv(index=False)
csv_bytes = csv_string.encode("utf-8")
Expand All @@ -86,8 +98,8 @@ def histogram_reactivity_2():

if btn and not ui_initialized:
dropdown = ui.input_select(
"h2_anno_1",
"Select an Annotation",
"h2_anno_1",
"Select an Annotation",
choices=shared['obs_names'].get()
)
ui.insert_ui(
Expand All @@ -97,8 +109,8 @@ def histogram_reactivity_2():
)

together_check = ui.input_checkbox(
"h2_together_check",
"Plot Together",
"h2_together_check",
"Plot Together",
value=True
)
ui.insert_ui(
Expand All @@ -120,18 +132,18 @@ def histogram_reactivity_2():
def update_stack_type_dropdown():
if input.h2_together_check():
dropdown_together = ui.input_select(
"h2_together_drop",
"Select Stack Type",
choices=['stack', 'layer', 'dodge', 'fill'],
"h2_together_drop",
"Select Stack Type",
choices=['stack', 'layer', 'dodge', 'fill'],
selected='stack'
)
ui.insert_ui(
ui.div({
"id": "inserted-dropdown_together-1"},
"id": "inserted-dropdown_together-1"},
dropdown_together
),
selector="#main-h2_together_drop",
where="beforeEnd"
)
)
else:
ui.remove_ui("#inserted-dropdown_together-1")
ui.remove_ui("#inserted-dropdown_together-1")
60 changes: 34 additions & 26 deletions server/boxplot_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import anndata as ad
import pandas as pd
import spac.visualization
# Added...
import matplotlib.pyplot as plt


def boxplot_server(input, output, session, shared):
Expand Down Expand Up @@ -32,34 +34,38 @@ def spac_Boxplot():

if not input.bp_output_type():
return None
else:
else:

adata = ad.AnnData(
X=shared['X_data'].get(),
obs=pd.DataFrame(shared['obs_data'].get()),
var=pd.DataFrame(shared['var_data'].get()),
layers=shared['layers_data'].get(),
X=shared['X_data'].get(),
obs=pd.DataFrame(shared['obs_data'].get()),
var=pd.DataFrame(shared['var_data'].get()),
layers=shared['layers_data'].get(),
dtype=shared['X_data'].get().dtype
)
# Added...
font_size = input.bp_font_size()

# Proceed only if adata is valid
if adata is not None and adata.var is not None:

fig, df = spac.visualization.boxplot_interactive(
adata,
annotation=on_anno_check(),
layer=on_layer_check(),
adata,
annotation=on_anno_check(),
layer=on_layer_check(),
features=list(input.bp_features()),
showfliers=on_outlier_check(),
log_scale=input.bp_log_scale(),
orient=on_orient_check(),
figure_height=3,
figure_width=4.8,
figure_height=3,
figure_width=4.8,
figure_type="interactive"
).values()

# Return the interactive Plotly figure object
shared['df_boxplot'].set(df)
# Added...
fig.update_layout(font=dict(size=font_size))
print(type(fig))
return fig

Expand All @@ -81,8 +87,8 @@ def download_boxplot():
def download_button_ui1():
if shared['df_boxplot'].get() is not None:
return ui.download_button(
"download_boxplot",
"Download Data",
"download_boxplot",
"Download Data",
class_="btn-warning"
)
return None
Expand All @@ -101,33 +107,35 @@ def boxplot_static():
if input.bp_output_type():
return None

else:
else:

adata = ad.AnnData(
X=shared['X_data'].get(),
obs=pd.DataFrame(shared['obs_data'].get()),
var=pd.DataFrame(shared['var_data'].get()),
layers=shared['layers_data'].get(),
X=shared['X_data'].get(),
obs=pd.DataFrame(shared['obs_data'].get()),
var=pd.DataFrame(shared['var_data'].get()),
layers=shared['layers_data'].get(),
dtype=shared['X_data'].get().dtype
)
# Added...
font_size = input.bp_font_size()

# Proceed only if adata is valid
if adata is not None and adata.var is not None:

fig, df = spac.visualization.boxplot_interactive(
adata,
annotation=on_anno_check(),
layer=on_layer_check(),
adata,
annotation=on_anno_check(),
layer=on_layer_check(),
features=list(input.bp_features()),
showfliers=on_outlier_check(),
log_scale=input.bp_log_scale(),
orient=on_orient_check(),
figure_height=3,
figure_width=4.8,
figure_height=3,
figure_width=4.8,
figure_type="static"
).values()

# Added...
fig.update_layout(font=dict(size=font_size))
return fig

return None

return None
Loading