Skip to content

Commit

Permalink
(optional) vertical orientation for marker presence plots
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Jun 18, 2024
1 parent 5934a91 commit b7069b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/depiction_targeted_preproc/workflow/experimental.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -28,14 +28,15 @@ 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()
.encode(
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
Expand All @@ -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)
Expand All @@ -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__":
Expand Down

0 comments on commit b7069b5

Please sign in to comment.