From bea8240ac99132fe11a04597b7e4f3c0b82cb544 Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Tue, 12 Nov 2024 09:38:16 +0100 Subject: [PATCH] generate a config with smoothing deactivated --- ...re_calibration_config_with_no_smoothing.py | 38 +++++++++++++++++++ .../workflow/experimental.smk | 10 +++++ 2 files changed, 48 insertions(+) create mode 100644 src/depiction_targeted_preproc/workflow/exp/prepare_calibration_config_with_no_smoothing.py diff --git a/src/depiction_targeted_preproc/workflow/exp/prepare_calibration_config_with_no_smoothing.py b/src/depiction_targeted_preproc/workflow/exp/prepare_calibration_config_with_no_smoothing.py new file mode 100644 index 0000000..71bbbbd --- /dev/null +++ b/src/depiction_targeted_preproc/workflow/exp/prepare_calibration_config_with_no_smoothing.py @@ -0,0 +1,38 @@ +import cyclopts +import yaml +from pathlib import Path + +from depiction.tools.calibrate.config import ( + CalibrationConfig, + CalibrationRegressShiftConfig, + CalibrationChemicalPeptideNoiseConfig, + CalibrationMCCConfig, + CalibrationConstantGlobalShiftConfig, +) + +app = cyclopts.App() + + +def remove_smoothing(config: CalibrationConfig) -> CalibrationConfig: + match config: + case CalibrationRegressShiftConfig(): + return config.model_copy(update={"spatial_smoothing": None}) + case CalibrationChemicalPeptideNoiseConfig(): + return config + case CalibrationMCCConfig(): + return config.model_copy(update={"coef_smoothing_activated": False}) + case CalibrationConstantGlobalShiftConfig(): + return config + case _: + raise NotImplementedError(f"Smoothing removal for {config.method.calibration_method} not implemented.") + + +@app.default +def prepare(input_config_path: Path, output_config_path: Path) -> None: + config = CalibrationConfig.model_validate(yaml.safe_load(input_config_path.read_text())) + config_new = remove_smoothing(config) + output_config_path.write_text(yaml.safe_dump(config_new.model_dump(mode="json"))) + + +if __name__ == "__main__": + app() diff --git a/src/depiction_targeted_preproc/workflow/experimental.smk b/src/depiction_targeted_preproc/workflow/experimental.smk index 540a42f..f0873e4 100644 --- a/src/depiction_targeted_preproc/workflow/experimental.smk +++ b/src/depiction_targeted_preproc/workflow/experimental.smk @@ -99,3 +99,13 @@ rule exp_plot_map_comparison: # " --input-mass-shift-path {input.mass_shift}" # " --output-pdf-path {output.pdf}" # + + +rule exp_prepare_calibration_config_with_no_smoothing: + input: + config="{sample}/config/proc_calibrate.yml", + output: + config="{sample}/config/proc_calibrate_no_smoothing.yml", + shell: + "python -m depiction_targeted_preproc.workflow.exp.prepare_calibration_config_with_no_smoothing" + " --input-config-path {input.config} --output-config-path {output.config}"