From a8c341a0e58539c17a9e98b70538e1f0e89c59ab Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Fri, 5 Jul 2024 12:34:01 +0200 Subject: [PATCH] move imzml code into a dedicated package --- src/depiction/persistence/__init__.py | 10 +++++----- src/depiction/persistence/imzml/__init__.py | 0 .../persistence/{ => imzml}/extract_metadata.py | 0 .../persistence/{ => imzml}/imzml_alignment_tracker.py | 0 .../persistence/{ => imzml}/imzml_mode_enum.py | 0 .../persistence/{ => imzml}/imzml_read_file.py | 4 ++-- src/depiction/persistence/{ => imzml}/imzml_reader.py | 2 +- .../persistence/{ => imzml}/imzml_write_file.py | 4 ++-- src/depiction/persistence/{ => imzml}/imzml_writer.py | 6 +++--- .../workflow/proc/export_raw_metadata.py | 2 +- .../workflow/vis/images_ome_tiff.py | 2 +- tests/unit/persistence/imzml/__init__.py | 0 .../persistence/{ => imzml}/test_imzml_read_file.py | 2 +- .../unit/persistence/{ => imzml}/test_imzml_reader.py | 2 +- .../unit/persistence/{ => imzml}/test_imzml_writer.py | 0 15 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 src/depiction/persistence/imzml/__init__.py rename src/depiction/persistence/{ => imzml}/extract_metadata.py (100%) rename src/depiction/persistence/{ => imzml}/imzml_alignment_tracker.py (100%) rename src/depiction/persistence/{ => imzml}/imzml_mode_enum.py (100%) rename src/depiction/persistence/{ => imzml}/imzml_read_file.py (98%) rename src/depiction/persistence/{ => imzml}/imzml_reader.py (99%) rename src/depiction/persistence/{ => imzml}/imzml_write_file.py (94%) rename src/depiction/persistence/{ => imzml}/imzml_writer.py (94%) create mode 100644 tests/unit/persistence/imzml/__init__.py rename tests/unit/persistence/{ => imzml}/test_imzml_read_file.py (99%) rename tests/unit/persistence/{ => imzml}/test_imzml_reader.py (99%) rename tests/unit/persistence/{ => imzml}/test_imzml_writer.py (100%) diff --git a/src/depiction/persistence/__init__.py b/src/depiction/persistence/__init__.py index d243e06..b471dc2 100644 --- a/src/depiction/persistence/__init__.py +++ b/src/depiction/persistence/__init__.py @@ -1,8 +1,8 @@ -from .imzml_mode_enum import ImzmlModeEnum -from .imzml_read_file import ImzmlReadFile -from .imzml_reader import ImzmlReader -from .imzml_write_file import ImzmlWriteFile -from .imzml_writer import ImzmlWriter +from depiction.persistence.imzml.imzml_mode_enum import ImzmlModeEnum +from depiction.persistence.imzml.imzml_read_file import ImzmlReadFile +from depiction.persistence.imzml.imzml_reader import ImzmlReader +from depiction.persistence.imzml.imzml_write_file import ImzmlWriteFile +from depiction.persistence.imzml.imzml_writer import ImzmlWriter from .ram_read_file import RamReadFile from .ram_reader import RamReader diff --git a/src/depiction/persistence/imzml/__init__.py b/src/depiction/persistence/imzml/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/depiction/persistence/extract_metadata.py b/src/depiction/persistence/imzml/extract_metadata.py similarity index 100% rename from src/depiction/persistence/extract_metadata.py rename to src/depiction/persistence/imzml/extract_metadata.py diff --git a/src/depiction/persistence/imzml_alignment_tracker.py b/src/depiction/persistence/imzml/imzml_alignment_tracker.py similarity index 100% rename from src/depiction/persistence/imzml_alignment_tracker.py rename to src/depiction/persistence/imzml/imzml_alignment_tracker.py diff --git a/src/depiction/persistence/imzml_mode_enum.py b/src/depiction/persistence/imzml/imzml_mode_enum.py similarity index 100% rename from src/depiction/persistence/imzml_mode_enum.py rename to src/depiction/persistence/imzml/imzml_mode_enum.py diff --git a/src/depiction/persistence/imzml_read_file.py b/src/depiction/persistence/imzml/imzml_read_file.py similarity index 98% rename from src/depiction/persistence/imzml_read_file.py rename to src/depiction/persistence/imzml/imzml_read_file.py index 650cf7f..4205d10 100644 --- a/src/depiction/persistence/imzml_read_file.py +++ b/src/depiction/persistence/imzml/imzml_read_file.py @@ -10,8 +10,8 @@ from numpy.typing import NDArray from depiction.persistence.file_checksums import FileChecksums -from depiction.persistence.imzml_mode_enum import ImzmlModeEnum -from depiction.persistence.imzml_reader import ImzmlReader +from depiction.persistence.imzml.imzml_mode_enum import ImzmlModeEnum +from depiction.persistence.imzml.imzml_reader import ImzmlReader from depiction.persistence.pixel_size import PixelSize diff --git a/src/depiction/persistence/imzml_reader.py b/src/depiction/persistence/imzml/imzml_reader.py similarity index 99% rename from src/depiction/persistence/imzml_reader.py rename to src/depiction/persistence/imzml/imzml_reader.py index 8543c15..34ce06c 100644 --- a/src/depiction/persistence/imzml_reader.py +++ b/src/depiction/persistence/imzml/imzml_reader.py @@ -7,7 +7,7 @@ import numpy as np import pyimzml.ImzMLParser -from depiction.persistence.imzml_mode_enum import ImzmlModeEnum +from depiction.persistence.imzml.imzml_mode_enum import ImzmlModeEnum if TYPE_CHECKING: from types import TracebackType diff --git a/src/depiction/persistence/imzml_write_file.py b/src/depiction/persistence/imzml/imzml_write_file.py similarity index 94% rename from src/depiction/persistence/imzml_write_file.py rename to src/depiction/persistence/imzml/imzml_write_file.py index 78c21ea..eb3fdcf 100644 --- a/src/depiction/persistence/imzml_write_file.py +++ b/src/depiction/persistence/imzml/imzml_write_file.py @@ -3,10 +3,10 @@ from pathlib import Path from typing import TYPE_CHECKING -from depiction.persistence.imzml_writer import ImzmlWriter +from depiction.persistence.imzml.imzml_writer import ImzmlWriter if TYPE_CHECKING: - from depiction.persistence.imzml_mode_enum import ImzmlModeEnum + from depiction.persistence.imzml.imzml_mode_enum import ImzmlModeEnum class ImzmlWriteFile: diff --git a/src/depiction/persistence/imzml_writer.py b/src/depiction/persistence/imzml/imzml_writer.py similarity index 94% rename from src/depiction/persistence/imzml_writer.py rename to src/depiction/persistence/imzml/imzml_writer.py index bb493aa..cbb9515 100644 --- a/src/depiction/persistence/imzml_writer.py +++ b/src/depiction/persistence/imzml/imzml_writer.py @@ -6,13 +6,13 @@ import pyimzml.ImzMLWriter from tqdm import tqdm -from depiction.persistence.imzml_alignment_tracker import ImzmlAlignmentTracker -from depiction.persistence.imzml_mode_enum import ImzmlModeEnum +from depiction.persistence.imzml.imzml_alignment_tracker import ImzmlAlignmentTracker +from depiction.persistence.imzml.imzml_mode_enum import ImzmlModeEnum if TYPE_CHECKING: from collections.abc import Sequence import numpy as np - from depiction.persistence.imzml_reader import ImzmlReader + from depiction.persistence.imzml.imzml_reader import ImzmlReader class ImzmlWriter: diff --git a/src/depiction_targeted_preproc/workflow/proc/export_raw_metadata.py b/src/depiction_targeted_preproc/workflow/proc/export_raw_metadata.py index 2d9f39c..89e8b35 100644 --- a/src/depiction_targeted_preproc/workflow/proc/export_raw_metadata.py +++ b/src/depiction_targeted_preproc/workflow/proc/export_raw_metadata.py @@ -5,7 +5,7 @@ from loguru import logger from pydantic import ValidationError -from depiction.persistence.extract_metadata import ExtractMetadata, Metadata +from depiction.persistence.imzml.extract_metadata import ExtractMetadata, Metadata from depiction.persistence.pixel_size import PixelSize diff --git a/src/depiction_targeted_preproc/workflow/vis/images_ome_tiff.py b/src/depiction_targeted_preproc/workflow/vis/images_ome_tiff.py index a3f9a5f..c31c1f0 100644 --- a/src/depiction_targeted_preproc/workflow/vis/images_ome_tiff.py +++ b/src/depiction_targeted_preproc/workflow/vis/images_ome_tiff.py @@ -4,7 +4,7 @@ import typer import xarray -from depiction.persistence.extract_metadata import Metadata +from depiction.persistence.imzml.extract_metadata import Metadata from depiction.persistence.format_ome_tiff import OmeTiff diff --git a/tests/unit/persistence/imzml/__init__.py b/tests/unit/persistence/imzml/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/persistence/test_imzml_read_file.py b/tests/unit/persistence/imzml/test_imzml_read_file.py similarity index 99% rename from tests/unit/persistence/test_imzml_read_file.py rename to tests/unit/persistence/imzml/test_imzml_read_file.py index 3476c45..d31b90c 100644 --- a/tests/unit/persistence/test_imzml_read_file.py +++ b/tests/unit/persistence/imzml/test_imzml_read_file.py @@ -158,7 +158,7 @@ def test_metadata_checksums_when_both_checksums_available(mocker: MockerFixture, def test_ibd_checksums(mocker: MockerFixture, mock_read_file: ImzmlReadFile) -> None: - mock_file_checksums = mocker.patch("depiction.persistence.imzml_read_file.FileChecksums") + mock_file_checksums = mocker.patch("depiction.persistence.imzml.imzml_read_file.FileChecksums") assert mock_file_checksums.return_value == mock_read_file.ibd_checksums mock_file_checksums.assert_called_once_with(file_path=mock_read_file.ibd_file) diff --git a/tests/unit/persistence/test_imzml_reader.py b/tests/unit/persistence/imzml/test_imzml_reader.py similarity index 99% rename from tests/unit/persistence/test_imzml_reader.py rename to tests/unit/persistence/imzml/test_imzml_reader.py index ac5bf15..91da5cd 100644 --- a/tests/unit/persistence/test_imzml_reader.py +++ b/tests/unit/persistence/imzml/test_imzml_reader.py @@ -239,7 +239,7 @@ def test_get_spectra_mz_range_when_none(self, mock_get_spectrum_mz) -> None: self.assertTupleEqual((0.5, 6), mz_range) self.assertListEqual([call(0), call(1), call(2)], mock_get_spectrum_mz.mock_calls) - @patch("depiction.persistence.imzml_reader.pyimzml.ImzMLParser.ImzMLParser") + @patch("depiction.persistence.imzml.imzml_reader.pyimzml.ImzMLParser.ImzMLParser") def test_parse_imzml(self, module_imzml_parser) -> None: mock_path = MagicMock(name="mock_path", spec=[]) mock_portable_spectrum_reader = MagicMock(name="mock_portable_spectrum_reader") diff --git a/tests/unit/persistence/test_imzml_writer.py b/tests/unit/persistence/imzml/test_imzml_writer.py similarity index 100% rename from tests/unit/persistence/test_imzml_writer.py rename to tests/unit/persistence/imzml/test_imzml_writer.py