Skip to content

Commit

Permalink
setup pipeline for multi-configuration runs
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Jun 7, 2024
1 parent 124f15b commit 114a30e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/depiction_targeted_preproc/example/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
"qc/plot_marker_presence.pdf",
"qc/plot_peak_density_combined.pdf",
"qc/plot_peak_density_grouped.pdf",
"qc/plot_calibration_map.pdf",
],
PipelineArtifact.CALIB_IMAGES: ["images_default.ome.tiff", "images_default_norm.ome.tiff"],
# PipelineArtifact.CALIB_HEATMAP: ["images_calib_heatmap.ome.tiff"],
# TODO
PipelineArtifact.CALIB_HEATMAP: [],
PipelineArtifact.CALIB_HEATMAP: [
"qc/plot_calibration_map.pdf",
],
PipelineArtifact.DEBUG: [
"qc/plot_marker_presence_cv.pdf",
"qc/plot_spectra_for_marker.pdf",
Expand Down Expand Up @@ -122,7 +123,7 @@ def snakemake_invoke(work_dir: Path, result_files: list[Path]) -> None:
"1",
"--snakefile",
str(snakefile_path),
*[str(file) for file in result_files],
*[str(file.relative_to(work_dir)) for file in result_files],
]
logger.info("Executing {command}", command=command)
subprocess.run(
Expand Down
27 changes: 20 additions & 7 deletions src/depiction_targeted_preproc/example_compare/run_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ def get_configs() -> dict[str, Path]:
return {path.stem: path for path in config_dir.glob("*.yml")}


def main() -> None:
data_raw_path = Path(__file__).parent / "data-raw"
input_imzml = data_raw_path / "menzha_20231208_s607923_tonsil-repro-sample-01.imzML"
input_mass_list = data_raw_path / "mass_list_vend.csv"
def prepare_tasks(input_imzml_path: Path, work_dir: Path) -> list[Path]:
input_mass_list = input_imzml_path.parent / "mass_list_vend.csv"
folders = set_up_work_dir(work_dir, input_imzml_path, input_mass_list)
requested_files = get_all_output_files(folders)

exp_files = [work_dir / input_imzml_path.stem / "exp_compare_cluster_stats.pdf"]
return requested_files + exp_files


def main() -> None:
work_dir = Path(__file__).parent / "data-work"
folders = set_up_work_dir(work_dir, input_imzml, input_mass_list)
requested_files = get_all_output_files(folders)
data_raw_dir = Path(__file__).parent / "data-raw"

requested_files = []
requested_files += prepare_tasks(
data_raw_dir / "menzha_20231208_s607923_tonsil-repro-sample-01.imzML", work_dir=work_dir
)
requested_files += prepare_tasks(
data_raw_dir / "menzha_20231208_s607930_64074-b20-30928-a.imzML", work_dir=work_dir
)

snakemake_invoke(work_dir=work_dir, result_files=requested_files)

Expand All @@ -37,8 +49,9 @@ def get_all_output_files(folders: list[Path]) -> list[Path]:
def set_up_work_dir(work_dir: Path, input_imzml: Path, input_mass_list: Path) -> list[Path]:
configs = get_configs()
folders = []
sample_name = input_imzml.stem
for config_name, config_path in configs.items():
dir = work_dir / config_name
dir = work_dir / sample_name / config_name
initial_setup(input_imzml=input_imzml, input_mass_list=input_mass_list, params_file=config_path, dir=dir)
folders.append(dir)
return folders
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pathlib import Path
from typing import Annotated

import polars as pl
import typer
from typer import Option


def load_data(csv_paths: list[Path]) -> pl.DataFrame:
collect = []
for csv_path in csv_paths:
df = pl.read_csv(csv_path)
collect.append(df.with_columns(label=pl.lit(csv_path.parent.name)))
return pl.concat(collect)


def compare_cluster_stats(input_csv_path: list[Path], output_pdf: Annotated[Path, Option()]) -> None:
data = load_data(input_csv_path)
print(data)


if __name__ == "__main__":
typer.run(compare_cluster_stats)

# print(sys.argv)
13 changes: 13 additions & 0 deletions src/depiction_targeted_preproc/workflow/experimental.smk
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ version: "3"
include: "rules/rules_proc.smk"
include: "rules/rules_vis.smk"
include: "rules/rules_qc.smk"


exp_variants = ["chem_noise", "mass_cluster", "reg_shift"]

rule exp_compare_cluster_stats:
input:
csv=expand("{{sample}}/{exp_variant}/cluster_default_stats_kmeans.csv", exp_variant=exp_variants)
output:
pdf="{sample}/exp_compare_cluster_stats.pdf"
shell:
"python -m depiction_targeted_preproc.workflow.exp.compare_cluster_stats"
" {input.csv}"
" --output-pdf {output}"
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def retain_strongest_signals(data: xarray.DataArray, n_features: int) -> xarray.
def cluster_kmeans(input_netcdf_path: Annotated[Path, Option()], output_netcdf_path: Annotated[Path, Option()]) -> None:
image = MultiChannelImage.read_hdf5(input_netcdf_path)
# TODO make configurable
n_clusters = 10
n_clusters = 6
n_features = 30

reduced_data = retain_strongest_signals(image.data_flat.transpose("i", "c"), n_features)
Expand Down

0 comments on commit 114a30e

Please sign in to comment.