From b7069b5d65d0a60bf35e38a1621f87a837dd4a1a Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Tue, 18 Jun 2024 16:26:47 +0200 Subject: [PATCH] (optional) vertical orientation for marker presence plots --- src/depiction_targeted_preproc/workflow/experimental.smk | 1 + .../workflow/qc/plot_marker_presence.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/depiction_targeted_preproc/workflow/experimental.smk b/src/depiction_targeted_preproc/workflow/experimental.smk index 3bfc44b..1f7a7b3 100644 --- a/src/depiction_targeted_preproc/workflow/experimental.smk +++ b/src/depiction_targeted_preproc/workflow/experimental.smk @@ -64,6 +64,7 @@ rule qc_plot_marker_presence_mini: "python -m depiction_targeted_preproc.workflow.qc.plot_marker_presence" " --table-marker-distances-baseline {input.table_marker_distances_baseline}" " --table-marker-distances-calib {input.table_marker_distances_calib}" + " --layout-vertical" " --output-pdf {output.pdf}" variants_with_map = ["mass_cluster", "reg_shift"] diff --git a/src/depiction_targeted_preproc/workflow/qc/plot_marker_presence.py b/src/depiction_targeted_preproc/workflow/qc/plot_marker_presence.py index 3d06480..3f08828 100644 --- a/src/depiction_targeted_preproc/workflow/qc/plot_marker_presence.py +++ b/src/depiction_targeted_preproc/workflow/qc/plot_marker_presence.py @@ -8,7 +8,7 @@ from typer import Option -def plot_marker_presence(df_peak_dist: pl.DataFrame, n_spectra: int, out_path: Path) -> None: +def plot_marker_presence(df_peak_dist: pl.DataFrame, n_spectra: int, out_path: Path, layout_vertical:bool) -> None: # Add a `max_dist` column to the dataframe, that indicates the first bin a particular item falls into df = df_peak_dist.with_columns(abs_dist=pl.col("dist").abs()).sort("abs_dist") df_cutoffs = pl.DataFrame({"max_dist": [0.05, 0.1, 0.2, 0.3, 0.4, np.inf]}).sort("max_dist") @@ -28,6 +28,7 @@ def plot_marker_presence(df_peak_dist: pl.DataFrame, n_spectra: int, out_path: P "fraction", descending=True )["label"] + layout_config = {"column": "variant:N"} if not layout_vertical else {"row": "variant:N"} c = ( alt.Chart(df) .mark_bar() @@ -35,7 +36,7 @@ def plot_marker_presence(df_peak_dist: pl.DataFrame, n_spectra: int, out_path: P x=alt.X("sum(fraction):Q", scale=alt.Scale(domain=[0, 1])), y=alt.Y("label:N", sort=list(sorted_labels)), color=alt.Color("detection_dist:N"), - column="variant:N", + **layout_config ) .properties( title="Fraction of spectra with peaks detected per marker at different max distance cutoffs", width=600 @@ -48,6 +49,7 @@ def qc_plot_marker_presence( table_marker_distances_baseline: Annotated[Path, Option()], table_marker_distances_calib: Annotated[Path, Option()], output_pdf: Annotated[Path, Option()], + layout_vertical: Annotated[bool, Option(is_flag=True)] = False, ) -> None: table_calib = pl.read_parquet(table_marker_distances_calib) table_baseline = pl.read_parquet(table_marker_distances_baseline) @@ -57,7 +59,7 @@ def qc_plot_marker_presence( table_baseline.with_columns(variant=pl.lit("baseline_adj")), ] ) - plot_marker_presence(df_peak_dist=table, n_spectra=table["i_spectrum"].n_unique(), out_path=output_pdf) + plot_marker_presence(df_peak_dist=table, n_spectra=table["i_spectrum"].n_unique(), out_path=output_pdf, layout_vertical=layout_vertical) if __name__ == "__main__":