-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from theislab/feature/display_qc_metrics
[FEATURE] Display QC metrics of var #239
- Loading branch information
Showing
11 changed files
with
92 additions
and
20 deletions.
There are no files selected for viewing
Submodule notebooks
updated
4 files
+1 −1 | ehrapy_introduction.ipynb | |
+1 −1 | mimic_2_fate.ipynb | |
+14 −12 | mimic_2_introduction.ipynb | |
+1 −1 | mimic_3_demo.ipynb |
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,12 @@ | ||
:github_url: ehrapy.plot.qc_metrics | ||
|
||
ehrapy.plot.qc\_metrics | ||
======================= | ||
|
||
.. autofunction:: ehrapy.plot.qc_metrics | ||
|
||
.. _sphx_glr_backref_ehrapy.plot.qc_metrics: | ||
|
||
.. minigallery:: ehrapy.plot.qc_metrics | ||
:add-heading: Gallery | ||
:heading-level: - |
12 changes: 0 additions & 12 deletions
12
docs/usage/preprocessing/ehrapy.preprocessing.calculate_qc_metrics.rst
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
docs/usage/preprocessing/ehrapy.preprocessing.qc_metrics.rst
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,12 @@ | ||
:github_url: ehrapy.preprocessing.qc_metrics | ||
|
||
ehrapy.preprocessing.qc\_metrics | ||
================================ | ||
|
||
.. autofunction:: ehrapy.preprocessing.qc_metrics | ||
|
||
.. _sphx_glr_backref_ehrapy.preprocessing.qc_metrics: | ||
|
||
.. minigallery:: ehrapy.preprocessing.qc_metrics | ||
:add-heading: Gallery | ||
:heading-level: - |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from ehrapy.plot._plot_util import * # noqa: E402,F403 | ||
from ehrapy.plot._scanpy_pl_api import * # noqa: E402,F403 | ||
from ehrapy.plot.ehrapy_plot.plot_qc import qc_metrics |
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,51 @@ | ||
from __future__ import annotations | ||
|
||
from anndata import AnnData | ||
from rich.console import Console | ||
from rich.table import Table | ||
|
||
|
||
def qc_metrics(adata: AnnData, extra_columns: list[str] | None = None) -> None: | ||
"""Plots the calculated quality control metrics for var of adata. Per default this will display the following features: | ||
``missing_values_abs``, ``missing_values_pct``, ``mean``, ``median``, ``standard_deviation``, ``max``, ``min``. | ||
Args: | ||
adata: Annotated data matrix. | ||
extra_columns: List of custom (qc) var columns to be displayed additionally. | ||
""" | ||
table = Table(title="[bold blue]Ehrapy qc metrics of var") | ||
# add special column header for the column name | ||
table.add_column("[bold blue]Column name", justify="right", style="bold green") | ||
var_names = list(adata.var_names) | ||
# default qc columns added to var | ||
fixed_qc_columns = [ | ||
"missing_values_abs", | ||
"missing_values_pct", | ||
"mean", | ||
"median", | ||
"standard_deviation", | ||
"min", | ||
"max", | ||
] | ||
# update columns to display with extra columns (if any) | ||
columns_to_display = fixed_qc_columns if not extra_columns else fixed_qc_columns + extra_columns | ||
# check whether all columns exist (qc has been executed before and extra columns are var columns) | ||
if (set(columns_to_display) & set(adata.var.columns)) != set(columns_to_display): | ||
raise QCDisplayError( | ||
"Cannot display QC metrics of current AnnData object. Either QC has not been executed before or " | ||
"some column(s) of the extra_columns parameter are not in var!" | ||
) | ||
vars_to_display = adata.var[columns_to_display] | ||
# add column headers | ||
for col in vars_to_display: | ||
table.add_column(f"[bold blue]{col}", justify="right", style="bold green") | ||
for var in range(len(vars_to_display)): | ||
table.add_row(var_names[var], *map(str, list(vars_to_display.iloc[var]))) | ||
|
||
console = Console() | ||
console.print(table) | ||
|
||
|
||
class QCDisplayError(Exception): | ||
pass |
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
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