Skip to content

Commit

Permalink
handle no calibration in the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Sep 5, 2024
1 parent a65e29d commit 1cc58b6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
2 changes: 0 additions & 2 deletions src/depiction/calibration/perform_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
50 changes: 21 additions & 29 deletions src/depiction/tools/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")

Expand All @@ -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,
)
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1cc58b6

Please sign in to comment.