diff --git a/src/depiction/tools/cli/cli.py b/src/depiction/tools/cli/cli.py index 78db23c..055b324 100644 --- a/src/depiction/tools/cli/cli.py +++ b/src/depiction/tools/cli/cli.py @@ -1,10 +1,10 @@ from cyclopts import App from depiction.tools.calibrate.__main__ import app as calibrate -from depiction.tools.cli.cli_correct_baseline import app as correct_baseline from depiction.tools.cli.cli_filter_peaks import app as filter_peaks from depiction.tools.cli.cli_generate_ion_images import app as generate_ion_images from depiction.tools.cli.cli_pick_peaks import app as pick_peaks +from depiction.tools.correct_baseline.__main__ import app as correct_baseline app = App() app.command(calibrate, name="calibrate") diff --git a/tests/unit/tools/cli/__init__.py b/src/depiction/tools/correct_baseline/__init__.py similarity index 100% rename from tests/unit/tools/cli/__init__.py rename to src/depiction/tools/correct_baseline/__init__.py diff --git a/src/depiction/tools/cli/cli_correct_baseline.py b/src/depiction/tools/correct_baseline/__main__.py similarity index 87% rename from src/depiction/tools/cli/cli_correct_baseline.py rename to src/depiction/tools/correct_baseline/__main__.py index 614a97e..d1852d4 100644 --- a/src/depiction/tools/cli/cli_correct_baseline.py +++ b/src/depiction/tools/correct_baseline/__main__.py @@ -8,7 +8,8 @@ from loguru import logger from depiction.persistence import ImzmlReadFile -from depiction.tools.correct_baseline import BaselineVariants, BaselineCorrectionConfig, correct_baseline +from depiction.tools.correct_baseline.correct_baseline import correct_baseline +from depiction.tools.correct_baseline.config import BaselineVariants, BaselineCorrectionConfig app = cyclopts.App() diff --git a/src/depiction/tools/correct_baseline/config.py b/src/depiction/tools/correct_baseline/config.py new file mode 100644 index 0000000..90988d6 --- /dev/null +++ b/src/depiction/tools/correct_baseline/config.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +import enum +from typing import Literal + +from pydantic import BaseModel, PositiveInt, PositiveFloat + + +class BaselineVariants(str, enum.Enum): + TopHat = "TopHat" + LocMedians = "LocMedians" + + +class BaselineCorrectionConfig(BaseModel, use_enum_values=True, validate_default=True): + n_jobs: PositiveInt | None = None + baseline_variant: BaselineVariants = BaselineVariants.TopHat + window_size: PositiveInt | PositiveFloat = 5000.0 + window_unit: Literal["ppm", "index"] = "ppm" diff --git a/src/depiction/tools/correct_baseline.py b/src/depiction/tools/correct_baseline/correct_baseline.py similarity index 90% rename from src/depiction/tools/correct_baseline.py rename to src/depiction/tools/correct_baseline/correct_baseline.py index 6efbacb..a23bebb 100644 --- a/src/depiction/tools/correct_baseline.py +++ b/src/depiction/tools/correct_baseline/correct_baseline.py @@ -1,35 +1,22 @@ from __future__ import annotations -import enum from pathlib import Path from typing import TYPE_CHECKING, Literal import numpy as np -from pydantic import BaseModel, PositiveInt, PositiveFloat from depiction.parallel_ops.parallel_config import ParallelConfig from depiction.parallel_ops.write_spectra_parallel import WriteSpectraParallel from depiction.persistence import ImzmlWriteFile, ImzmlWriter, ImzmlReader, ImzmlReadFile from depiction.spectrum.baseline.local_medians_baseline import LocalMediansBaseline from depiction.spectrum.baseline.tophat_baseline import TophatBaseline +from depiction.tools.correct_baseline.config import BaselineVariants, BaselineCorrectionConfig if TYPE_CHECKING: from numpy.typing import NDArray from depiction.spectrum.baseline.baseline import Baseline -class BaselineVariants(str, enum.Enum): - TopHat = "TopHat" - LocMedians = "LocMedians" - - -class BaselineCorrectionConfig(BaseModel, use_enum_values=True, validate_default=True): - n_jobs: PositiveInt | None = None - baseline_variant: BaselineVariants = BaselineVariants.TopHat - window_size: PositiveInt | PositiveFloat = 5000.0 - window_unit: Literal["ppm", "index"] = "ppm" - - class CorrectBaseline: """Implements baseline correction for imzml files.""" diff --git a/src/depiction_targeted_preproc/pipeline_config/model.py b/src/depiction_targeted_preproc/pipeline_config/model.py index 271489a..fd1b43c 100644 --- a/src/depiction_targeted_preproc/pipeline_config/model.py +++ b/src/depiction_targeted_preproc/pipeline_config/model.py @@ -8,7 +8,7 @@ from pydantic import BaseModel, ConfigDict from depiction.tools.calibrate.config import CalibrationConfig -from depiction.tools.correct_baseline import BaselineCorrectionConfig +from depiction.tools.correct_baseline.config import BaselineCorrectionConfig from depiction.tools.filter_peaks import FilterPeaksConfig from depiction.tools.pick_peaks import PickPeaksConfig diff --git a/src/depiction_targeted_preproc/workflow/rules/rules_proc.smk b/src/depiction_targeted_preproc/workflow/rules/rules_proc.smk index 6de7570..d380862 100644 --- a/src/depiction_targeted_preproc/workflow/rules/rules_proc.smk +++ b/src/depiction_targeted_preproc/workflow/rules/rules_proc.smk @@ -17,7 +17,7 @@ rule proc_correct_baseline_run: output: imzml=temp(multiext("{sample}/corrected.original", ".imzML", ".ibd")), shell: - "python -m depiction.tools.cli.cli_correct_baseline run-config" + "python -m depiction.tools.correct_baseline run-config" " --config {input.config}" " --input-imzml {input.imzml[0]} --output-imzml {output.imzml[0]}" diff --git a/tests/unit/tools/correct_baseline/__init__.py b/tests/unit/tools/correct_baseline/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/tools/cli/test_correct_baseline.py b/tests/unit/tools/correct_baseline/test_correct_baseline.py similarity index 78% rename from tests/unit/tools/cli/test_correct_baseline.py rename to tests/unit/tools/correct_baseline/test_correct_baseline.py index 5c29118..3372dbc 100644 --- a/tests/unit/tools/cli/test_correct_baseline.py +++ b/tests/unit/tools/correct_baseline/test_correct_baseline.py @@ -3,16 +3,18 @@ import pytest from pytest_mock import MockerFixture -from depiction.tools.cli.cli_correct_baseline import run -from depiction.tools.correct_baseline import BaselineVariants +from depiction.tools.correct_baseline.__main__ import run +from depiction.tools.correct_baseline.config import BaselineVariants def test_run_when_other_variant(mocker: MockerFixture) -> None: mock_imzml_mode = mocker.MagicMock(name="mock_imzml_mode", spec=[]) - construct_imzml_read_file = mocker.patch("depiction.tools.correct_baseline.ImzmlReadFile") + construct_imzml_read_file = mocker.patch("depiction.tools.correct_baseline.correct_baseline.ImzmlReadFile") construct_imzml_read_file.return_value.imzml_mode = mock_imzml_mode - construct_imzml_write_file = mocker.patch("depiction.tools.correct_baseline.ImzmlWriteFile") - construct_correct_baseline = mocker.patch("depiction.tools.correct_baseline.CorrectBaseline.from_variant") + construct_imzml_write_file = mocker.patch("depiction.tools.correct_baseline.correct_baseline.ImzmlWriteFile") + construct_correct_baseline = mocker.patch( + "depiction.tools.correct_baseline.correct_baseline.CorrectBaseline.from_variant" + ) mock_input_imzml = Path("/dev/null/hello.imzML") mock_output_imzml = mocker.MagicMock(name="mock_output_imzml")