Skip to content

Commit

Permalink
added dpi parameter and minor fix for saving figures of motif enrichm…
Browse files Browse the repository at this point in the history
…ent plot
  • Loading branch information
HAL9032 committed May 1, 2024
1 parent 1a39ba4 commit a51ea2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions episcanpy/tools/_enrichment_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def motif_enrichment(adata, alpha=0.05):



def plot_enrichment(x, y, c, s, x_label, colorbar_label, legend_label, show_nonsignificant=True, highlight_significant=True, highlight_list=None, title=None, figsize=(6, 6), save=None):
def plot_enrichment(x, y, c, s, x_label, colorbar_label, legend_label, show_nonsignificant=True, highlight_significant=True, highlight_list=None, title=None, figsize=(6, 6), dpi=300, save=None):

if not show_nonsignificant:
x = x[highlight_list]
Expand Down Expand Up @@ -181,11 +181,11 @@ def plot_enrichment(x, y, c, s, x_label, colorbar_label, legend_label, show_nons
if save is None:
plt.show()
else:
plt.savefig(save, dpi=600, bbox_inches="tight")
plt.savefig(save, dpi=dpi, bbox_inches="tight")



def plot_motif_enrichment(adata, corr_method="benjamini-hochberg", top_n=10, show_nonsignificant=True, highlight_significant=True, pval_threshold=0.05, save=None):
def plot_motif_enrichment(adata, corr_method="benjamini-hochberg", top_n=10, show_nonsignificant=True, highlight_significant=True, pval_threshold=0.05, dpi=300, save=None):

if corr_method is None or corr_method.lower() in ["raw", "none"]:
pval_key = "pval"
Expand All @@ -201,7 +201,7 @@ def plot_motif_enrichment(adata, corr_method="benjamini-hochberg", top_n=10, sho

msgs = []

for group in adata.uns["motif_enrichment"]["results"]:
for i, group in enumerate(adata.uns["motif_enrichment"]["results"]):

data = adata.uns["motif_enrichment"]["results"][group]

Expand Down Expand Up @@ -231,8 +231,9 @@ def plot_motif_enrichment(adata, corr_method="benjamini-hochberg", top_n=10, sho
highlight_significant=highlight_significant,
highlight_list=highlight_list,
title=group,
figsize=(8, 6),
save=save
figsize=(8, 6),
dpi=dpi,
save=save.split(".")[0] + f"_{i+1}." + save.split(".")[1] if save is not None else None
)

for msg in msgs:
Expand Down
4 changes: 2 additions & 2 deletions episcanpy/tools/_footprinting.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def plot_footprints(adata, mtx="corr_norm", show_score=True, score_threshold=1.3



def plot_footprints_compact(adata, mtx="corr_norm", max_cols=5, width_adjust=1, figsize=None, save=None):
def plot_footprints_compact(adata, mtx="corr_norm", max_cols=5, width_adjust=1, figsize=None, dpi=300, save=None):

if mtx in ["raw", "norm", "corr", "corr_norm", "norm_smooth", "corr_norm_smooth"]:
mtx = f"mtx_{mtx}"
Expand Down Expand Up @@ -733,4 +733,4 @@ def plot_footprints_compact(adata, mtx="corr_norm", max_cols=5, width_adjust=1,
handle.set_linewidth(2.5)

if save is not None:
plt.savefig(save)
plt.savefig(save, dpi=dpi)

0 comments on commit a51ea2f

Please sign in to comment.