-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
26 implement plotting function (#43)
* Add skeleton for plotting function * Add plotting of QC variables; closes #26. * Remove debug print statement. * Add plotting of QC variables; closes #26. * Run black * Make quality control work inplace; closes #49. * Move plotting of QC covariates to quality_control function. * Create parent folders of figure directory if not present. --------- Co-authored-by: Sebastian Bischoff <sebastian@salzreute.de>
- Loading branch information
1 parent
55b5c98
commit 315c46b
Showing
6 changed files
with
192 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from pathlib import Path | ||
import scanpy as sc | ||
from anndata import AnnData | ||
from matplotlib import pyplot as plt | ||
import seaborn as sns | ||
|
||
|
||
def plot_qc_vars(adata: AnnData, pre_qc: bool, out_dir: Path) -> None: | ||
# Plot cell level QC metrics | ||
qc_vars_cells = [ | ||
"n_genes_by_counts", | ||
"total_counts", | ||
"pct_counts_mt", | ||
"pct_counts_rb", | ||
"pct_counts_hb", | ||
] | ||
fig, axs = plt.subplots(nrows=2, ncols=3, figsize=(9, 6)) | ||
sc.pl.scatter( | ||
adata, x="total_counts", y="n_genes_by_counts", ax=axs.flat[0], show=False | ||
) | ||
for qc_var, ax in zip(qc_vars_cells, axs.flat[1:]): | ||
sns.violinplot(adata.obs[qc_var], ax=ax, cut=0) | ||
sns.stripplot(adata.obs[qc_var], jitter=0.4, s=1, color="black", ax=ax) | ||
fig.tight_layout() | ||
fig.savefig(Path(out_dir, f"qc_vars_cells_{'pre' if pre_qc else 'post'}_qc.png")) | ||
plt.close() | ||
|
||
# Plot gene level QC metrics | ||
qc_vars_genes = ["n_cells_by_counts", "pct_dropout_by_counts"] | ||
fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(6, 3)) | ||
for qc_var, ax in zip(qc_vars_genes, axs.flat): | ||
sns.violinplot(adata.var[qc_var], ax=ax, cut=0) | ||
sns.stripplot(adata.var[qc_var], jitter=0.4, s=1, color="black", ax=ax) | ||
fig.tight_layout() | ||
fig.savefig(Path(out_dir, f"qc_vars_genes_{'pre' if pre_qc else 'post'}_qc.png")) | ||
plt.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.