From 1cc58b6953ae80d2ab6d1650ffe0ecb1e212646d Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Thu, 5 Sep 2024 16:47:32 +0200 Subject: [PATCH] handle no calibration in the pipeline --- .../calibration/perform_calibration.py | 2 - src/depiction/tools/calibrate.py | 50 ++++++++----------- .../app/config_presets/no_calibration.yml | 23 +++++++++ 3 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 src/depiction_targeted_preproc/app/config_presets/no_calibration.yml diff --git a/src/depiction/calibration/perform_calibration.py b/src/depiction/calibration/perform_calibration.py index a4328eb..7881bf0 100644 --- a/src/depiction/calibration/perform_calibration.py +++ b/src/depiction/calibration/perform_calibration.py @@ -21,12 +21,10 @@ def __init__( self, calibration: CalibrationMethod, parallel_config: ParallelConfig, - output_store: h5py.Group | None = None, coefficient_output_file: Path | None = None, ) -> None: self._calibration = calibration self._parallel_config = parallel_config - self._output_store = output_store self._coefficient_output_file = coefficient_output_file # def _reshape(self, pattern: str, data: DataArray, coordinates) -> DataArray: diff --git a/src/depiction/tools/calibrate.py b/src/depiction/tools/calibrate.py index 2c1404f..5a7432a 100644 --- a/src/depiction/tools/calibrate.py +++ b/src/depiction/tools/calibrate.py @@ -3,22 +3,21 @@ from pathlib import Path from typing import Literal, Annotated -import h5py import numpy as np import polars as pl -from loguru import logger -from numpy.typing import NDArray -from pydantic import BaseModel, Field - from depiction.calibration.perform_calibration import PerformCalibration from depiction.calibration.spectrum.calibration_method_chemical_peptide_noise import ( CalibrationMethodChemicalPeptideNoise, ) +from depiction.calibration.spectrum.calibration_method_dummy import CalibrationMethodDummy from depiction.calibration.spectrum.calibration_method_global_constant_shift import CalibrationMethodGlobalConstantShift from depiction.calibration.spectrum.calibration_method_mcc import CalibrationMethodMassClusterCenterModel from depiction.calibration.spectrum.calibration_method_regress_shift import CalibrationMethodRegressShift from depiction.parallel_ops import ParallelConfig from depiction.persistence import ImzmlReadFile, ImzmlWriteFile +from loguru import logger +from numpy.typing import NDArray +from pydantic import BaseModel, Field class CalibrationRegressShiftConfig(BaseModel): @@ -114,6 +113,8 @@ def get_calibration_instance(config: CalibrationConfig, mass_list: Path | None): model_smoothing_kernel_size=config.method.coef_smoothing_kernel_size, model_smoothing_kernel_std=config.method.coef_smoothing_kernel_std, ) + case None: + return CalibrationMethodDummy() case _: raise NotImplementedError("should be unreachable") @@ -125,27 +126,18 @@ def calibrate( mass_list: Path | None = None, coefficient_output_path: Path | None = None, ) -> None: - if config.method is None: - logger.info("No calibration requested") - input_file.copy_to(output_file.imzml_file) - if coefficient_output_path: - # TODO not sure if this is the correct action here - h5py.File(coefficient_output_path, "w").close() - else: - calibration = get_calibration_instance(config=config, mass_list=mass_list) - parallel_config = ParallelConfig(n_jobs=config.n_jobs) - logger.info("Using calibration method: {calibration}", calibration=calibration) - - # TODO is output_store still used - perform_calibration = PerformCalibration( - calibration=calibration, - parallel_config=parallel_config, - output_store=None, - coefficient_output_file=coefficient_output_path, - ) - perform_calibration.calibrate_image( - read_peaks=input_file, - write_file=output_file, - # TODO:make it possible to customize this - read_full=None, - ) + calibration = get_calibration_instance(config=config, mass_list=mass_list) + parallel_config = ParallelConfig(n_jobs=config.n_jobs) + logger.info("Using calibration method: {calibration}", calibration=calibration) + + perform_calibration = PerformCalibration( + calibration=calibration, + parallel_config=parallel_config, + coefficient_output_file=coefficient_output_path, + ) + perform_calibration.calibrate_image( + read_peaks=input_file, + write_file=output_file, + # TODO:make it possible to customize this + read_full=None, + ) diff --git a/src/depiction_targeted_preproc/app/config_presets/no_calibration.yml b/src/depiction_targeted_preproc/app/config_presets/no_calibration.yml new file mode 100644 index 0000000..2fb3854 --- /dev/null +++ b/src/depiction_targeted_preproc/app/config_presets/no_calibration.yml @@ -0,0 +1,23 @@ +baseline_correction: + baseline_type: TopHat + window_size: 3000 + window_unit: ppm +pick_peaks: + peak_picker: + peak_picker_type: FindMFPy + int_threshold: 0.0 + force_peak_picker: no + peak_filtering: + filters: + - method: FilterNHighestIntensityPartitioned + max_count: 300 + n_partitions: 8 + n_jobs: 10 +filter_peaks: + filters: + - method: FilterNHighestIntensityPartitioned + max_count: 300 + n_partitions: 8 +calibration: + method: null + n_jobs: 10