Skip to content

Commit

Permalink
fix(tasks): reorganize summarize in preparation for integration of re…
Browse files Browse the repository at this point in the history
…porting module

Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>
  • Loading branch information
cameronraysmith committed Sep 5, 2024
1 parent c5a284d commit 21543d5
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions src/pyrovelocity/tasks/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ def summarize_dataset(
phase_portraits_exist = (
len(os.listdir(posterior_phase_portraits_path)) > 0
)
if (
all(os.path.isfile(f) for f in output_filenames)
and phase_portraits_exist
):
if all(os.path.isfile(f) for f in output_filenames):
logger.info(
"\n\t"
+ "\n\t".join(str(f) for f in output_filenames)
Expand Down Expand Up @@ -187,7 +184,7 @@ def summarize_dataset(
logger.info(f"Generating figure: {violin_clusters_log}")
for fig_name in [violin_clusters_lin, violin_clusters_log]:
cluster_violin_plots(
data_model,
data_model=data_model,
adata=adata,
posterior_samples=posterior_samples,
cluster_key=cell_state,
Expand All @@ -197,6 +194,24 @@ def summarize_dataset(
fig_name=fig_name,
)

# phase portraint predictive plots
if phase_portraits_exist:
logger.info(
f"\nFiles exist in posterior phase portraits path:\n"
f"{posterior_phase_portraits_path}\n"
f"Remove this directory or all its files if you want to regenerate them.\n\n"
)
else:
logger.info("Generating posterior predictive phase portrait plots")
posterior_curve(
adata=adata,
posterior_samples=posterior_samples,
gene_set=putative_marker_genes,
data_model=data_model,
model_path=model_path,
output_directory=posterior_phase_portraits_path,
)

# ##################
# save dataframes
# ##################
Expand Down Expand Up @@ -248,38 +263,21 @@ def summarize_dataset(
shared_time_plot=shared_time_plot,
)

# extract putative marker genes
logger.info(f"Searching for marker genes")
putative_marker_genes = top_mae_genes(
volcano_data=volcano_data,
mae_top_percentile=3,
min_genes_per_bin=3,
)

# phase portraint predictive plots
if phase_portraits_exist:
logger.info(
f"\nFiles exist in posterior phase portraits path:\n"
f"{posterior_phase_portraits_path}\n"
f"Remove this directory or all its files if you want to regenerate them.\n\n"
)
else:
logger.info("Generating posterior predictive phase portrait plots")
posterior_curve(
adata=adata,
posterior_samples=posterior_samples,
gene_set=putative_marker_genes,
data_model=data_model,
model_path=model_path,
output_directory=posterior_phase_portraits_path,
)

# volcano plot
if os.path.isfile(volcano_plot):
logger.info(f"{volcano_plot} exists")
else:
logger.info(f"Generating figure: {volcano_plot}")

volcano_data, fig = plot_gene_ranking(
plot_gene_ranking(
posterior_samples=posterior_samples,
adata=adata,
selected_genes=putative_marker_genes,
Expand All @@ -289,21 +287,6 @@ def summarize_dataset(
volcano_plot_path=volcano_plot,
)

# gene selection summary plot
if os.path.isfile(gene_selection_summary_plot):
logger.info(f"{gene_selection_summary_plot} exists")
else:
logger.info(f"Generating figure: {gene_selection_summary_plot}")
plot_gene_selection_summary(
adata=adata,
posterior_samples=posterior_samples,
basis=vector_field_basis,
cell_state=cell_state,
plot_name=gene_selection_summary_plot,
selected_genes=putative_marker_genes,
show_marginal_histograms=False,
)

# parameter uncertainty plot
if os.path.isfile(parameter_uncertainty_plot):
logger.info(f"{parameter_uncertainty_plot} exists")
Expand Down Expand Up @@ -333,6 +316,21 @@ def summarize_dataset(
rainbow_plot_path=gene_selection_rainbow_plot,
)

# gene selection summary plot
if os.path.isfile(gene_selection_summary_plot):
logger.info(f"{gene_selection_summary_plot} exists")
else:
logger.info(f"Generating figure: {gene_selection_summary_plot}")
plot_gene_selection_summary(
adata=adata,
posterior_samples=posterior_samples,
basis=vector_field_basis,
cell_state=cell_state,
plot_name=gene_selection_summary_plot,
selected_genes=putative_marker_genes,
show_marginal_histograms=False,
)

# mean vector field plot
if os.path.isfile(vector_field_plot):
logger.info(f"{vector_field_plot} exists")
Expand Down

0 comments on commit 21543d5

Please sign in to comment.