MaldiAMRKit 0.17.0__tar.gz → 0.18.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0/MaldiAMRKit.egg-info}/PKG-INFO +3 -3
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/MaldiAMRKit.egg-info/SOURCES.txt +0 -1
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/MaldiAMRKit.egg-info/requires.txt +2 -2
- {maldiamrkit-0.17.0/MaldiAMRKit.egg-info → maldiamrkit-0.18.0}/PKG-INFO +3 -3
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/__init__.py +1 -1
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/alignment/peak_align.py +2 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/alignment/raw_warping.py +2 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/alignment/strategies.py +1 -1
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/alignment/warping.py +2 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/cli.py +0 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/__init__.py +0 -4
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/dataset_layouts.py +2 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/site_info.py +13 -14
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/detection/peak_detector.py +9 -5
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/detection/peaklist.py +5 -5
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/drift/reference.py +1 -1
- maldiamrkit-0.18.0/maldiamrkit/evaluation/__init__.py +44 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/preprocessing/__init__.py +9 -1
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/preprocessing/binning.py +94 -12
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/preprocessing/preprocessing_pipeline.py +2 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/preprocessing/transformers.py +1 -1
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/similarity/__init__.py +1 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/similarity/metrics.py +10 -4
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/similarity/pairwise.py +3 -3
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/susceptibility/label_encoder.py +0 -4
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/visualization/_common.py +2 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/visualization/spectrum_plots.py +2 -2
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/requirements-dev.txt +1 -1
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/requirements-docs.txt +1 -1
- maldiamrkit-0.17.0/maldiamrkit/evaluation/__init__.py +0 -81
- maldiamrkit-0.17.0/maldiamrkit/evaluation/label_encoder.py +0 -42
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/LICENSE +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/MaldiAMRKit.egg-info/dependency_links.txt +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/MaldiAMRKit.egg-info/entry_points.txt +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/MaldiAMRKit.egg-info/top_level.txt +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/README.md +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/_compat.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/alignment/__init__.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/README.md +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v1.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v1.1.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v1.2.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v1.3.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v10.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v11.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v12.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v13.1.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v14.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v15.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v16.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v2.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v4.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v5.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v6.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v7.1.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v8.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v8.1.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v9.0.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/example.yaml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/builder.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/duplicates.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/input_layouts.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/loader.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/dataset.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/detection/__init__.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/differential/__init__.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/differential/analysis.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/differential/plots.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/differential/stats.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/drift/__init__.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/drift/monitor.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/drift/pca_drift.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/drift/peak_drift.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/drift/plots.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/evaluation/metrics.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/evaluation/mic_regression.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/evaluation/splitting.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/filters.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/io/__init__.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/io/mic.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/io/readers.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/preprocessing/merging.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/preprocessing/pipeline.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/preprocessing/quality.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/py.typed +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/similarity/clustering.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/similarity/plots.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/spectrum.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/susceptibility/__init__.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/susceptibility/breakpoint.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/susceptibility/mic_encoder.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/visualization/__init__.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/visualization/alignment_plots.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/visualization/exploratory_plots.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/visualization/peak_plots.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/pyproject.toml +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/requirements-batch.txt +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/requirements.txt +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/setup.cfg +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/tests/test_compat.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/tests/test_numerical_edge_cases.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/tests/test_peak_detector.py +0 -0
- {maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/tests/test_peaklist.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: MaldiAMRKit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.18.0
|
|
4
4
|
Summary: A comprehensive toolkit for MALDI-TOF mass spectrometry data preprocessing for antimicrobial resistance (AMR) prediction purposes
|
|
5
5
|
Author-email: Ettore Rocchi <ettore.rocchi3@unibo.it>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -41,14 +41,14 @@ Requires-Dist: sphinx>=7.0.0; extra == "docs"
|
|
|
41
41
|
Requires-Dist: pydata-sphinx-theme>=0.15.0; extra == "docs"
|
|
42
42
|
Requires-Dist: sphinx-autodoc-typehints>=2.0.0; extra == "docs"
|
|
43
43
|
Requires-Dist: sphinx-design>=0.6.0; extra == "docs"
|
|
44
|
-
Requires-Dist:
|
|
44
|
+
Requires-Dist: sphinxcontrib-typer>=0.5.0; extra == "docs"
|
|
45
45
|
Requires-Dist: nbsphinx>=0.9.0; extra == "docs"
|
|
46
46
|
Requires-Dist: ipykernel>=6.0.0; extra == "docs"
|
|
47
47
|
Provides-Extra: dev
|
|
48
48
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
49
49
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
50
50
|
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
51
|
-
Requires-Dist:
|
|
51
|
+
Requires-Dist: sphinxcontrib-typer>=0.5.0; extra == "dev"
|
|
52
52
|
Requires-Dist: hypothesis>=6.0.0; extra == "dev"
|
|
53
53
|
Provides-Extra: batch
|
|
54
54
|
Requires-Dist: umap-learn>=0.5; extra == "batch"
|
|
@@ -65,7 +65,6 @@ maldiamrkit/drift/peak_drift.py
|
|
|
65
65
|
maldiamrkit/drift/plots.py
|
|
66
66
|
maldiamrkit/drift/reference.py
|
|
67
67
|
maldiamrkit/evaluation/__init__.py
|
|
68
|
-
maldiamrkit/evaluation/label_encoder.py
|
|
69
68
|
maldiamrkit/evaluation/metrics.py
|
|
70
69
|
maldiamrkit/evaluation/mic_regression.py
|
|
71
70
|
maldiamrkit/evaluation/splitting.py
|
|
@@ -21,7 +21,7 @@ combatlearn>=1.3
|
|
|
21
21
|
pytest>=7.0.0
|
|
22
22
|
pytest-cov>=4.0.0
|
|
23
23
|
ruff>=0.1.0
|
|
24
|
-
|
|
24
|
+
sphinxcontrib-typer>=0.5.0
|
|
25
25
|
hypothesis>=6.0.0
|
|
26
26
|
|
|
27
27
|
[docs]
|
|
@@ -29,6 +29,6 @@ sphinx>=7.0.0
|
|
|
29
29
|
pydata-sphinx-theme>=0.15.0
|
|
30
30
|
sphinx-autodoc-typehints>=2.0.0
|
|
31
31
|
sphinx-design>=0.6.0
|
|
32
|
-
|
|
32
|
+
sphinxcontrib-typer>=0.5.0
|
|
33
33
|
nbsphinx>=0.9.0
|
|
34
34
|
ipykernel>=6.0.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: MaldiAMRKit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.18.0
|
|
4
4
|
Summary: A comprehensive toolkit for MALDI-TOF mass spectrometry data preprocessing for antimicrobial resistance (AMR) prediction purposes
|
|
5
5
|
Author-email: Ettore Rocchi <ettore.rocchi3@unibo.it>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -41,14 +41,14 @@ Requires-Dist: sphinx>=7.0.0; extra == "docs"
|
|
|
41
41
|
Requires-Dist: pydata-sphinx-theme>=0.15.0; extra == "docs"
|
|
42
42
|
Requires-Dist: sphinx-autodoc-typehints>=2.0.0; extra == "docs"
|
|
43
43
|
Requires-Dist: sphinx-design>=0.6.0; extra == "docs"
|
|
44
|
-
Requires-Dist:
|
|
44
|
+
Requires-Dist: sphinxcontrib-typer>=0.5.0; extra == "docs"
|
|
45
45
|
Requires-Dist: nbsphinx>=0.9.0; extra == "docs"
|
|
46
46
|
Requires-Dist: ipykernel>=6.0.0; extra == "docs"
|
|
47
47
|
Provides-Extra: dev
|
|
48
48
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
49
49
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
50
50
|
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
51
|
-
Requires-Dist:
|
|
51
|
+
Requires-Dist: sphinxcontrib-typer>=0.5.0; extra == "dev"
|
|
52
52
|
Requires-Dist: hypothesis>=6.0.0; extra == "dev"
|
|
53
53
|
Provides-Extra: batch
|
|
54
54
|
Requires-Dist: umap-learn>=0.5; extra == "batch"
|
|
@@ -12,7 +12,7 @@ from __future__ import annotations
|
|
|
12
12
|
import numpy as np
|
|
13
13
|
|
|
14
14
|
from ..detection.peaklist import PeakSet
|
|
15
|
-
from .strategies import
|
|
15
|
+
from .strategies import _ALIGNMENT_REGISTRY, AlignmentMethod, AlignmentStrategy
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def _build_strategy(
|
|
@@ -24,7 +24,7 @@ def _build_strategy(
|
|
|
24
24
|
lowess_it: int,
|
|
25
25
|
) -> AlignmentStrategy:
|
|
26
26
|
"""Instantiate the requested alignment strategy with its parameters."""
|
|
27
|
-
cls =
|
|
27
|
+
cls = _ALIGNMENT_REGISTRY[method]
|
|
28
28
|
if method in (AlignmentMethod.shift, AlignmentMethod.linear):
|
|
29
29
|
return cls(max_shift=max_shift_da)
|
|
30
30
|
if method == AlignmentMethod.piecewise:
|
|
@@ -16,7 +16,7 @@ from ..io.readers import read_spectrum
|
|
|
16
16
|
from ..preprocessing.binning import BinningMethod, bin_spectrum
|
|
17
17
|
from ..preprocessing.pipeline import preprocess
|
|
18
18
|
from ..preprocessing.preprocessing_pipeline import PreprocessingPipeline
|
|
19
|
-
from .strategies import
|
|
19
|
+
from .strategies import _ALIGNMENT_REGISTRY, AlignmentMethod
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def create_raw_input(
|
|
@@ -393,7 +393,7 @@ class RawWarping(BaseEstimator, TransformerMixin):
|
|
|
393
393
|
|
|
394
394
|
def _get_strategy(self):
|
|
395
395
|
"""Build strategy instance from current parameters."""
|
|
396
|
-
cls =
|
|
396
|
+
cls = _ALIGNMENT_REGISTRY[self.method]
|
|
397
397
|
if self.method == "shift":
|
|
398
398
|
return cls(max_shift=self.max_shift_da)
|
|
399
399
|
elif self.method == "linear":
|
|
@@ -689,7 +689,7 @@ class LOWESSStrategy(AlignmentStrategy):
|
|
|
689
689
|
return new_mz, intensity
|
|
690
690
|
|
|
691
691
|
|
|
692
|
-
|
|
692
|
+
_ALIGNMENT_REGISTRY: dict[str, type[AlignmentStrategy]] = {
|
|
693
693
|
"shift": ShiftStrategy,
|
|
694
694
|
"linear": LinearStrategy,
|
|
695
695
|
"piecewise": PiecewiseStrategy,
|
|
@@ -10,7 +10,7 @@ from joblib import Parallel, delayed
|
|
|
10
10
|
from sklearn.base import BaseEstimator, TransformerMixin
|
|
11
11
|
|
|
12
12
|
from ..detection.peak_detector import MaldiPeakDetector
|
|
13
|
-
from .strategies import
|
|
13
|
+
from .strategies import _ALIGNMENT_REGISTRY, AlignmentMethod, DTWStrategy
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class Warping(BaseEstimator, TransformerMixin):
|
|
@@ -177,7 +177,7 @@ class Warping(BaseEstimator, TransformerMixin):
|
|
|
177
177
|
|
|
178
178
|
def _get_strategy(self):
|
|
179
179
|
"""Build strategy instance from current parameters."""
|
|
180
|
-
cls =
|
|
180
|
+
cls = _ALIGNMENT_REGISTRY[self.method]
|
|
181
181
|
if self.method == "shift":
|
|
182
182
|
return cls(max_shift=self.max_shift)
|
|
183
183
|
elif self.method == "linear":
|
|
@@ -22,8 +22,6 @@ from .duplicates import DuplicateStrategy
|
|
|
22
22
|
from .input_layouts import BrukerTreeLayout, FlatLayout, InputLayout
|
|
23
23
|
from .loader import DatasetLoader
|
|
24
24
|
from .site_info import (
|
|
25
|
-
CURRENT_FORMAT_VERSION,
|
|
26
|
-
MANIFEST_FILENAME,
|
|
27
25
|
BuildInfo,
|
|
28
26
|
SiteInfo,
|
|
29
27
|
read_site_info,
|
|
@@ -53,6 +51,4 @@ __all__ = [
|
|
|
53
51
|
"BuildInfo",
|
|
54
52
|
"read_site_info",
|
|
55
53
|
"write_site_info",
|
|
56
|
-
"MANIFEST_FILENAME",
|
|
57
|
-
"CURRENT_FORMAT_VERSION",
|
|
58
54
|
]
|
|
@@ -30,7 +30,7 @@ logger = logging.getLogger(__name__)
|
|
|
30
30
|
class _Sentinel:
|
|
31
31
|
"""Sentinel for ``DRIAMSLayout`` kwargs.
|
|
32
32
|
|
|
33
|
-
A kwarg defaulted to
|
|
33
|
+
A kwarg defaulted to ``_AUTO`` means: "fill from ``site_info.json``
|
|
34
34
|
if present, otherwise use the library default". Explicit kwargs
|
|
35
35
|
always win.
|
|
36
36
|
"""
|
|
@@ -255,7 +255,7 @@ class DRIAMSLayout(DatasetLayout):
|
|
|
255
255
|
) -> None:
|
|
256
256
|
"""Initialise the layout.
|
|
257
257
|
|
|
258
|
-
Several kwargs accept the sentinel
|
|
258
|
+
Several kwargs accept the sentinel ``_AUTO`` as their default.
|
|
259
259
|
When ``_AUTO``, the value is filled from ``site_info.json`` at the
|
|
260
260
|
dataset root (if present) and otherwise falls back to the
|
|
261
261
|
library-level default. Explicit kwargs always win. Fields with
|
|
@@ -45,10 +45,10 @@ from datetime import datetime, timezone
|
|
|
45
45
|
from pathlib import Path
|
|
46
46
|
from typing import Any
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
_MANIFEST_FILENAME = "site_info.json"
|
|
49
49
|
"""On-disk filename for the manifest, written at the dataset root."""
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
_CURRENT_FORMAT_VERSION = 1
|
|
52
52
|
"""Manifest schema version produced by *this* MaldiAMRKit release."""
|
|
53
53
|
|
|
54
54
|
_REQUIRED_V1_KEYS: tuple[str, ...] = (
|
|
@@ -65,7 +65,7 @@ _REQUIRED_V1_KEYS: tuple[str, ...] = (
|
|
|
65
65
|
|
|
66
66
|
@dataclass
|
|
67
67
|
class BuildInfo:
|
|
68
|
-
"""Optional provenance block nested under :attr
|
|
68
|
+
"""Optional provenance block nested under :attr:`~maldiamrkit.data.SiteInfo.build_info`.
|
|
69
69
|
|
|
70
70
|
Informational only; readers may inspect it but are not required to
|
|
71
71
|
interpret any field. All fields are optional.
|
|
@@ -102,8 +102,9 @@ class SiteInfo:
|
|
|
102
102
|
Bin width in Daltons used at build time.
|
|
103
103
|
build_info : BuildInfo, optional
|
|
104
104
|
Optional provenance block.
|
|
105
|
-
format_version : int,
|
|
106
|
-
Manifest schema version
|
|
105
|
+
format_version : int, optional
|
|
106
|
+
Manifest schema version; defaults to the current release's schema
|
|
107
|
+
version.
|
|
107
108
|
"""
|
|
108
109
|
|
|
109
110
|
id_column: str
|
|
@@ -114,7 +115,7 @@ class SiteInfo:
|
|
|
114
115
|
mz_range: tuple[float, float]
|
|
115
116
|
bin_width: float
|
|
116
117
|
build_info: BuildInfo | None = None
|
|
117
|
-
format_version: int =
|
|
118
|
+
format_version: int = _CURRENT_FORMAT_VERSION
|
|
118
119
|
|
|
119
120
|
def to_dict(self) -> dict[str, Any]:
|
|
120
121
|
"""Serialise as a plain dict, with ``format_version`` first."""
|
|
@@ -134,7 +135,7 @@ class SiteInfo:
|
|
|
134
135
|
|
|
135
136
|
|
|
136
137
|
def write_site_info(dataset_dir: str | Path, site_info: SiteInfo) -> Path:
|
|
137
|
-
"""Write a :class
|
|
138
|
+
"""Write a :class:`~maldiamrkit.data.SiteInfo` to ``<dataset_dir>/site_info.json``.
|
|
138
139
|
|
|
139
140
|
Parameters
|
|
140
141
|
----------
|
|
@@ -153,7 +154,7 @@ def write_site_info(dataset_dir: str | Path, site_info: SiteInfo) -> Path:
|
|
|
153
154
|
raise FileNotFoundError(
|
|
154
155
|
f"Cannot write manifest: dataset directory does not exist: {dataset_dir}"
|
|
155
156
|
)
|
|
156
|
-
path = dataset_dir /
|
|
157
|
+
path = dataset_dir / _MANIFEST_FILENAME
|
|
157
158
|
data = site_info.to_dict()
|
|
158
159
|
path.write_text(json.dumps(data, indent=2, sort_keys=False) + "\n")
|
|
159
160
|
return path
|
|
@@ -187,11 +188,11 @@ def read_site_info(
|
|
|
187
188
|
If the manifest is malformed, missing a required field, or has
|
|
188
189
|
a non-integer ``format_version``.
|
|
189
190
|
"""
|
|
190
|
-
path = Path(dataset_dir) /
|
|
191
|
+
path = Path(dataset_dir) / _MANIFEST_FILENAME
|
|
191
192
|
if not path.exists():
|
|
192
193
|
if missing_ok:
|
|
193
194
|
return None
|
|
194
|
-
raise FileNotFoundError(f"{
|
|
195
|
+
raise FileNotFoundError(f"{_MANIFEST_FILENAME} not found in {dataset_dir}")
|
|
195
196
|
|
|
196
197
|
try:
|
|
197
198
|
raw = json.loads(path.read_text())
|
|
@@ -218,10 +219,10 @@ def _site_info_from_dict(
|
|
|
218
219
|
if not isinstance(fv, int):
|
|
219
220
|
raise ValueError(f"site_info{where} has non-integer format_version={fv!r}.")
|
|
220
221
|
|
|
221
|
-
if fv >
|
|
222
|
+
if fv > _CURRENT_FORMAT_VERSION:
|
|
222
223
|
warnings.warn(
|
|
223
224
|
f"site_info{where} was written by a newer MaldiAMRKit "
|
|
224
|
-
f"(format_version={fv}; this reader knows v{
|
|
225
|
+
f"(format_version={fv}; this reader knows v{_CURRENT_FORMAT_VERSION}). "
|
|
225
226
|
"Reading what I can; unknown fields will be ignored. "
|
|
226
227
|
"Upgrade `maldiamrkit` if loading misbehaves.",
|
|
227
228
|
UserWarning,
|
|
@@ -282,8 +283,6 @@ def _current_iso_utc() -> str:
|
|
|
282
283
|
|
|
283
284
|
|
|
284
285
|
__all__ = [
|
|
285
|
-
"MANIFEST_FILENAME",
|
|
286
|
-
"CURRENT_FORMAT_VERSION",
|
|
287
286
|
"SiteInfo",
|
|
288
287
|
"BuildInfo",
|
|
289
288
|
"read_site_info",
|
|
@@ -14,7 +14,7 @@ from scipy.signal import find_peaks, peak_prominences
|
|
|
14
14
|
from sklearn.base import BaseEstimator, TransformerMixin
|
|
15
15
|
|
|
16
16
|
from .peaklist import (
|
|
17
|
-
|
|
17
|
+
_RANK_BY,
|
|
18
18
|
PeakList,
|
|
19
19
|
PeakSet,
|
|
20
20
|
_array_hash,
|
|
@@ -365,7 +365,7 @@ class MaldiPeakDetector(BaseEstimator, TransformerMixin):
|
|
|
365
365
|
def _detect_peaks_ph_scored(self, row: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
|
|
366
366
|
"""Detect persistent-homology peaks and their persistence values.
|
|
367
367
|
|
|
368
|
-
Like
|
|
368
|
+
Like ``_detect_peaks_ph`` but also returns the persistence
|
|
369
369
|
(death - birth) of each kept peak, index-ascending.
|
|
370
370
|
|
|
371
371
|
Parameters
|
|
@@ -451,7 +451,9 @@ class MaldiPeakDetector(BaseEstimator, TransformerMixin):
|
|
|
451
451
|
raise ValueError("rank_by='persistence' requires method='ph'.")
|
|
452
452
|
scores = persistences
|
|
453
453
|
else:
|
|
454
|
-
raise ValueError(
|
|
454
|
+
raise ValueError(
|
|
455
|
+
f"Unknown rank_by={rank_by!r}; expected one of {_RANK_BY}."
|
|
456
|
+
)
|
|
455
457
|
return indices, np.asarray(scores, dtype=float)
|
|
456
458
|
|
|
457
459
|
def detect_peakset(
|
|
@@ -560,8 +562,10 @@ class MaldiPeakDetector(BaseEstimator, TransformerMixin):
|
|
|
560
562
|
PeakList
|
|
561
563
|
One :class:`PeakSet` per spectrum.
|
|
562
564
|
"""
|
|
563
|
-
if rank_by not in
|
|
564
|
-
raise ValueError(
|
|
565
|
+
if rank_by not in _RANK_BY:
|
|
566
|
+
raise ValueError(
|
|
567
|
+
f"Unknown rank_by={rank_by!r}; expected one of {_RANK_BY}."
|
|
568
|
+
)
|
|
565
569
|
if isinstance(X, pd.Series):
|
|
566
570
|
X = X.to_frame().T
|
|
567
571
|
|
|
@@ -23,7 +23,7 @@ from typing import Any, Sequence
|
|
|
23
23
|
import numpy as np
|
|
24
24
|
import pandas as pd
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
_RANK_BY = ("intensity", "persistence", "prominence")
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def _config_hash(config: dict[str, Any]) -> str:
|
|
@@ -147,7 +147,7 @@ class PeakSet:
|
|
|
147
147
|
|
|
148
148
|
|
|
149
149
|
class PeakList:
|
|
150
|
-
"""A collection of per-spectrum :class
|
|
150
|
+
"""A collection of per-spectrum :class:`~maldiamrkit.detection.PeakSet` objects.
|
|
151
151
|
|
|
152
152
|
Parameters
|
|
153
153
|
----------
|
|
@@ -364,7 +364,7 @@ def create_peakset_input(
|
|
|
364
364
|
pipeline: Any | None = None,
|
|
365
365
|
cache_dir: str | Path | None = None,
|
|
366
366
|
) -> PeakList:
|
|
367
|
-
"""Build a :class
|
|
367
|
+
"""Build a :class:`~maldiamrkit.detection.PeakList` from a directory of raw spectrum files.
|
|
368
368
|
|
|
369
369
|
Analogue of :func:`maldiamrkit.alignment.create_raw_input`: discovers raw
|
|
370
370
|
spectrum files, preprocesses each one per-spectrum, detects peaks at full
|
|
@@ -410,8 +410,8 @@ def create_peakset_input(
|
|
|
410
410
|
from ..preprocessing.preprocessing_pipeline import PreprocessingPipeline
|
|
411
411
|
from .peak_detector import MaldiPeakDetector
|
|
412
412
|
|
|
413
|
-
if rank_by not in
|
|
414
|
-
raise ValueError(f"Unknown rank_by={rank_by!r}; expected one of {
|
|
413
|
+
if rank_by not in _RANK_BY:
|
|
414
|
+
raise ValueError(f"Unknown rank_by={rank_by!r}; expected one of {_RANK_BY}.")
|
|
415
415
|
if detector is None:
|
|
416
416
|
detector = MaldiPeakDetector()
|
|
417
417
|
pipe = pipeline or PreprocessingPipeline.default()
|
|
@@ -42,7 +42,7 @@ def _reference_similarity_timeseries(
|
|
|
42
42
|
timestamps : pd.Series
|
|
43
43
|
Parsed datetime Series aligned with ``X.index``.
|
|
44
44
|
reference : ndarray
|
|
45
|
-
Reference spectrum from
|
|
45
|
+
Reference spectrum from ``_compute_reference_spectrum``.
|
|
46
46
|
window : str or pd.Timedelta
|
|
47
47
|
Time window size forwarded to :class:`pandas.Grouper` (e.g.
|
|
48
48
|
``"30D"``).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Evaluation utilities for AMR prediction.
|
|
2
|
+
|
|
3
|
+
Binary AMR metrics, MIC-regression reporting, and CV splitting helpers.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from .metrics import (
|
|
9
|
+
amr_classification_report,
|
|
10
|
+
amr_multilabel_report,
|
|
11
|
+
categorical_agreement,
|
|
12
|
+
major_error_rate,
|
|
13
|
+
me_scorer,
|
|
14
|
+
sensitivity_score,
|
|
15
|
+
specificity_score,
|
|
16
|
+
very_major_error_rate,
|
|
17
|
+
vme_me_curve,
|
|
18
|
+
vme_scorer,
|
|
19
|
+
)
|
|
20
|
+
from .mic_regression import mic_regression_report
|
|
21
|
+
from .splitting import (
|
|
22
|
+
CaseGroupedKFold,
|
|
23
|
+
SpeciesDrugStratifiedKFold,
|
|
24
|
+
case_based_split,
|
|
25
|
+
stratified_species_drug_split,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"very_major_error_rate",
|
|
30
|
+
"major_error_rate",
|
|
31
|
+
"sensitivity_score",
|
|
32
|
+
"specificity_score",
|
|
33
|
+
"categorical_agreement",
|
|
34
|
+
"vme_me_curve",
|
|
35
|
+
"amr_classification_report",
|
|
36
|
+
"amr_multilabel_report",
|
|
37
|
+
"mic_regression_report",
|
|
38
|
+
"vme_scorer",
|
|
39
|
+
"me_scorer",
|
|
40
|
+
"stratified_species_drug_split",
|
|
41
|
+
"case_based_split",
|
|
42
|
+
"SpeciesDrugStratifiedKFold",
|
|
43
|
+
"CaseGroupedKFold",
|
|
44
|
+
]
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"""Preprocessing functions for MALDI-TOF spectra."""
|
|
2
2
|
|
|
3
|
-
from .binning import
|
|
3
|
+
from .binning import (
|
|
4
|
+
BinningMethod,
|
|
5
|
+
bin_spectrum,
|
|
6
|
+
get_bin_metadata,
|
|
7
|
+
register_binning_method,
|
|
8
|
+
unregister_binning_method,
|
|
9
|
+
)
|
|
4
10
|
from .merging import MergingMethod, detect_outlier_replicates, merge_replicates
|
|
5
11
|
from .pipeline import preprocess
|
|
6
12
|
from .preprocessing_pipeline import PreprocessingPipeline
|
|
@@ -30,6 +36,8 @@ __all__ = [
|
|
|
30
36
|
"BinningMethod",
|
|
31
37
|
"bin_spectrum",
|
|
32
38
|
"get_bin_metadata",
|
|
39
|
+
"register_binning_method",
|
|
40
|
+
"unregister_binning_method",
|
|
33
41
|
# Merging
|
|
34
42
|
"MergingMethod",
|
|
35
43
|
"merge_replicates",
|
|
@@ -377,23 +377,95 @@ def _custom_edge_fn(*, mz_min, mz_max, custom_edges=None, **_kwargs) -> np.ndarr
|
|
|
377
377
|
return _validate_custom_edges(custom_edges, mz_min, mz_max)
|
|
378
378
|
|
|
379
379
|
|
|
380
|
-
|
|
380
|
+
_BINNING_REGISTRY: dict[str, Callable[..., np.ndarray]] = {
|
|
381
381
|
"uniform": _uniform_edge_fn,
|
|
382
382
|
"proportional": _proportional_edge_fn,
|
|
383
383
|
"adaptive": _adaptive_edge_fn,
|
|
384
384
|
"custom": _custom_edge_fn,
|
|
385
385
|
}
|
|
386
|
-
"""
|
|
386
|
+
"""Internal registry mapping binning method names to edge-generator functions.
|
|
387
387
|
|
|
388
|
-
|
|
388
|
+
Register custom methods with :func:`register_binning_method` rather than
|
|
389
|
+
mutating this mapping directly.
|
|
390
|
+
"""
|
|
389
391
|
|
|
390
|
-
|
|
392
|
+
_DEFAULT_BINNING_METHODS: frozenset[str] = frozenset(_BINNING_REGISTRY)
|
|
393
|
+
"""Names of the built-in methods, which cannot be unregistered."""
|
|
391
394
|
|
|
392
|
-
def my_edges(*, mz_min, mz_max, **kwargs):
|
|
393
|
-
return np.array([mz_min, (mz_min + mz_max) / 2, mz_max])
|
|
394
395
|
|
|
395
|
-
|
|
396
|
-
"""
|
|
396
|
+
def register_binning_method(name: str, edge_fn: Callable[..., np.ndarray]) -> None:
|
|
397
|
+
"""Register a custom binning method for use with :func:`~maldiamrkit.preprocessing.bin_spectrum`.
|
|
398
|
+
|
|
399
|
+
After registration, pass ``method=name`` to :func:`bin_spectrum` to bin
|
|
400
|
+
with the custom edges.
|
|
401
|
+
|
|
402
|
+
Parameters
|
|
403
|
+
----------
|
|
404
|
+
name : str
|
|
405
|
+
Method name to expose. Overwrites any existing method of the same
|
|
406
|
+
name, including the built-ins.
|
|
407
|
+
edge_fn : callable
|
|
408
|
+
Edge-generator returning a 1-D array of monotonically increasing bin
|
|
409
|
+
edges. It is called with keyword arguments ``df``, ``mz_min``,
|
|
410
|
+
``mz_max``, ``bin_width``, ``custom_edges`` and the ``adaptive_*``
|
|
411
|
+
parameters forwarded from :func:`bin_spectrum`; accept ``**kwargs``
|
|
412
|
+
to ignore the ones it does not need.
|
|
413
|
+
|
|
414
|
+
Raises
|
|
415
|
+
------
|
|
416
|
+
TypeError
|
|
417
|
+
If ``edge_fn`` is not callable.
|
|
418
|
+
|
|
419
|
+
Examples
|
|
420
|
+
--------
|
|
421
|
+
>>> import numpy as np
|
|
422
|
+
>>> from maldiamrkit.preprocessing import register_binning_method, bin_spectrum
|
|
423
|
+
>>> def my_edges(*, mz_min, mz_max, **kwargs):
|
|
424
|
+
... return np.array([mz_min, (mz_min + mz_max) / 2, mz_max])
|
|
425
|
+
>>> register_binning_method("my_method", my_edges)
|
|
426
|
+
>>> # binned, meta = bin_spectrum(df, method="my_method")
|
|
427
|
+
"""
|
|
428
|
+
if not callable(edge_fn):
|
|
429
|
+
raise TypeError(f"edge_fn must be callable, got {type(edge_fn).__name__}.")
|
|
430
|
+
_BINNING_REGISTRY[name] = edge_fn
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def unregister_binning_method(name: str) -> None:
|
|
434
|
+
"""Remove a custom binning method added with :func:`register_binning_method`.
|
|
435
|
+
|
|
436
|
+
Parameters
|
|
437
|
+
----------
|
|
438
|
+
name : str
|
|
439
|
+
Method name to remove. Must have been registered with
|
|
440
|
+
:func:`register_binning_method`.
|
|
441
|
+
|
|
442
|
+
Raises
|
|
443
|
+
------
|
|
444
|
+
ValueError
|
|
445
|
+
If ``name`` is one of the built-in methods ('uniform',
|
|
446
|
+
'proportional', 'adaptive', 'custom'), which cannot be removed.
|
|
447
|
+
KeyError
|
|
448
|
+
If no method named ``name`` is registered.
|
|
449
|
+
|
|
450
|
+
Examples
|
|
451
|
+
--------
|
|
452
|
+
>>> import numpy as np
|
|
453
|
+
>>> from maldiamrkit.preprocessing import (
|
|
454
|
+
... register_binning_method,
|
|
455
|
+
... unregister_binning_method,
|
|
456
|
+
... )
|
|
457
|
+
>>> register_binning_method("my_method", lambda **kw: np.array([2000, 20000]))
|
|
458
|
+
>>> unregister_binning_method("my_method")
|
|
459
|
+
"""
|
|
460
|
+
if name in _DEFAULT_BINNING_METHODS:
|
|
461
|
+
raise ValueError(
|
|
462
|
+
f"Cannot unregister built-in binning method {name!r}. "
|
|
463
|
+
f"Built-in methods are {sorted(_DEFAULT_BINNING_METHODS)}."
|
|
464
|
+
)
|
|
465
|
+
try:
|
|
466
|
+
del _BINNING_REGISTRY[name]
|
|
467
|
+
except KeyError:
|
|
468
|
+
raise KeyError(f"No binning method named {name!r} is registered.") from None
|
|
397
469
|
|
|
398
470
|
|
|
399
471
|
def bin_spectrum(
|
|
@@ -428,8 +500,9 @@ def bin_spectrum(
|
|
|
428
500
|
For 'proportional', this is the reference width at mz_min.
|
|
429
501
|
Ignored for 'adaptive' and 'custom' methods.
|
|
430
502
|
method : str, default='uniform'
|
|
431
|
-
Binning method. One of 'uniform', 'proportional',
|
|
432
|
-
'custom'
|
|
503
|
+
Binning method. One of the built-ins 'uniform', 'proportional',
|
|
504
|
+
'adaptive', 'custom', or a custom name registered with
|
|
505
|
+
:func:`register_binning_method`.
|
|
433
506
|
custom_edges : array-like, optional
|
|
434
507
|
User-provided bin edges. Required if method='custom'.
|
|
435
508
|
adaptive_min_width : float, default=1.0
|
|
@@ -473,7 +546,16 @@ def bin_spectrum(
|
|
|
473
546
|
>>> edges = [2000, 5000, 10000, 15000, 20000]
|
|
474
547
|
>>> binned, metadata = bin_spectrum(df, method='custom', custom_edges=edges)
|
|
475
548
|
"""
|
|
476
|
-
|
|
549
|
+
try:
|
|
550
|
+
method = BinningMethod(method)
|
|
551
|
+
except ValueError:
|
|
552
|
+
# Allow custom methods registered via register_binning_method().
|
|
553
|
+
if method not in _BINNING_REGISTRY:
|
|
554
|
+
raise ValueError(
|
|
555
|
+
f"{method!r} is not a valid binning method. Use one of "
|
|
556
|
+
f"{sorted(_BINNING_REGISTRY)} or register a custom method "
|
|
557
|
+
"with register_binning_method()."
|
|
558
|
+
) from None
|
|
477
559
|
|
|
478
560
|
if mz_min >= mz_max:
|
|
479
561
|
raise ValueError(f"mz_min ({mz_min}) must be less than mz_max ({mz_max}).")
|
|
@@ -482,7 +564,7 @@ def bin_spectrum(
|
|
|
482
564
|
raise ValueError(f"mz_min must be > 0 for {method} binning, got {mz_min}")
|
|
483
565
|
|
|
484
566
|
# Generate bin edges via registry
|
|
485
|
-
edge_fn =
|
|
567
|
+
edge_fn = _BINNING_REGISTRY[method]
|
|
486
568
|
edges = edge_fn(
|
|
487
569
|
df=df,
|
|
488
570
|
mz_min=mz_min,
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/preprocessing/preprocessing_pipeline.py
RENAMED
|
@@ -33,7 +33,7 @@ from typing import Protocol, runtime_checkable
|
|
|
33
33
|
import pandas as pd
|
|
34
34
|
|
|
35
35
|
from .transformers import (
|
|
36
|
-
|
|
36
|
+
_TRANSFORMER_REGISTRY,
|
|
37
37
|
ClipNegatives,
|
|
38
38
|
MzTrimmer,
|
|
39
39
|
SavitzkyGolaySmooth,
|
|
@@ -190,7 +190,7 @@ class PreprocessingPipeline:
|
|
|
190
190
|
for step_dict in d["steps"]:
|
|
191
191
|
step_name = step_dict["step_name"]
|
|
192
192
|
transformer_name = step_dict["name"]
|
|
193
|
-
transformer_cls =
|
|
193
|
+
transformer_cls = _TRANSFORMER_REGISTRY[transformer_name]
|
|
194
194
|
|
|
195
195
|
# Extract constructor kwargs (everything except step_name and name)
|
|
196
196
|
kwargs = {
|
|
@@ -603,7 +603,7 @@ class MzMultiTrimmer:
|
|
|
603
603
|
|
|
604
604
|
|
|
605
605
|
# Registry mapping transformer names to classes (for deserialization)
|
|
606
|
-
|
|
606
|
+
_TRANSFORMER_REGISTRY: dict[str, type] = {
|
|
607
607
|
"ClipNegatives": ClipNegatives,
|
|
608
608
|
"SqrtTransform": SqrtTransform,
|
|
609
609
|
"LogTransform": LogTransform,
|
|
@@ -10,14 +10,13 @@ from .clustering import (
|
|
|
10
10
|
kmedoids_clustering,
|
|
11
11
|
silhouette_scores,
|
|
12
12
|
)
|
|
13
|
-
from .metrics import
|
|
13
|
+
from .metrics import SpectralMetric, spectral_distance
|
|
14
14
|
from .pairwise import pairwise_distances
|
|
15
15
|
from .plots import plot_dendrogram, plot_distance_heatmap
|
|
16
16
|
|
|
17
17
|
__all__ = [
|
|
18
18
|
"ClusteringMethod",
|
|
19
19
|
"KMedoidsInit",
|
|
20
|
-
"METRIC_REGISTRY",
|
|
21
20
|
"SpectralMetric",
|
|
22
21
|
"cluster_metadata_concordance",
|
|
23
22
|
"cluster_spectra",
|
|
@@ -175,13 +175,19 @@ class SpectralMetric(str, Enum):
|
|
|
175
175
|
pearson = "pearson"
|
|
176
176
|
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
_METRIC_REGISTRY: dict[str, Callable] = {
|
|
179
179
|
"wasserstein": _wasserstein_distance,
|
|
180
180
|
"dtw": _dtw_distance,
|
|
181
181
|
"cosine": _cosine_distance,
|
|
182
182
|
"spectral_contrast_angle": _spectral_contrast_angle,
|
|
183
183
|
"pearson": _pearson_correlation,
|
|
184
184
|
}
|
|
185
|
+
"""Mapping of metric name to its pairwise spectral-distance function.
|
|
186
|
+
|
|
187
|
+
Keys are the values of :class:`~maldiamrkit.similarity.SpectralMetric`
|
|
188
|
+
(``"wasserstein"``, ``"dtw"``, ``"cosine"``, ``"spectral_contrast_angle"``,
|
|
189
|
+
``"pearson"``).
|
|
190
|
+
"""
|
|
185
191
|
|
|
186
192
|
|
|
187
193
|
def spectral_distance(
|
|
@@ -200,7 +206,7 @@ def spectral_distance(
|
|
|
200
206
|
For binned metrics (``"cosine"``, ``"spectral_contrast_angle"``,
|
|
201
207
|
``"pearson"``): 1-D intensity arrays.
|
|
202
208
|
metric : str or SpectralMetric, default="wasserstein"
|
|
203
|
-
|
|
209
|
+
One of the values of :class:`~maldiamrkit.similarity.SpectralMetric`.
|
|
204
210
|
|
|
205
211
|
Returns
|
|
206
212
|
-------
|
|
@@ -210,7 +216,7 @@ def spectral_distance(
|
|
|
210
216
|
Raises
|
|
211
217
|
------
|
|
212
218
|
ValueError
|
|
213
|
-
If *metric* is not
|
|
219
|
+
If *metric* is not a recognised :class:`~maldiamrkit.similarity.SpectralMetric`.
|
|
214
220
|
"""
|
|
215
221
|
metric = SpectralMetric(metric)
|
|
216
|
-
return
|
|
222
|
+
return _METRIC_REGISTRY[metric](spec_a, spec_b)
|
|
@@ -8,7 +8,7 @@ import numpy as np
|
|
|
8
8
|
import pandas as pd
|
|
9
9
|
from joblib import Parallel, delayed
|
|
10
10
|
|
|
11
|
-
from .metrics import
|
|
11
|
+
from .metrics import _METRIC_REGISTRY, SpectralMetric, spectral_distance
|
|
12
12
|
|
|
13
13
|
if TYPE_CHECKING:
|
|
14
14
|
from maldiamrkit.spectrum import MaldiSpectrum
|
|
@@ -31,7 +31,7 @@ def pairwise_distances(
|
|
|
31
31
|
:class:`~maldiamrkit.spectrum.MaldiSpectrum`, raw/preprocessed data
|
|
32
32
|
is used.
|
|
33
33
|
metric : str or SpectralMetric, default="wasserstein"
|
|
34
|
-
|
|
34
|
+
One of the values of :class:`~maldiamrkit.similarity.SpectralMetric`.
|
|
35
35
|
n_jobs : int, default=1
|
|
36
36
|
Number of parallel jobs for pairwise computation.
|
|
37
37
|
|
|
@@ -61,7 +61,7 @@ def _pairwise_binned(X: pd.DataFrame, metric: str) -> np.ndarray:
|
|
|
61
61
|
"""Fast path using sklearn for binned feature matrices."""
|
|
62
62
|
from sklearn.metrics import pairwise_distances as sklearn_pd
|
|
63
63
|
|
|
64
|
-
metric_fn =
|
|
64
|
+
metric_fn = _METRIC_REGISTRY[metric]
|
|
65
65
|
arr = X.values
|
|
66
66
|
|
|
67
67
|
def _metric(a: np.ndarray, b: np.ndarray) -> float:
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"""Label encoding utilities for AMR classification.
|
|
2
2
|
|
|
3
3
|
Maps clinical resistance categories (R/I/S) to binary or numeric labels.
|
|
4
|
-
Previously lived under ``maldiamrkit.evaluation``; moved here in v0.15 to
|
|
5
|
-
group together with :class:`~maldiamrkit.susceptibility.MICEncoder` and
|
|
6
|
-
:class:`~maldiamrkit.susceptibility.BreakpointTable`. The old import path
|
|
7
|
-
still works for one release with a :class:`DeprecationWarning`.
|
|
8
4
|
|
|
9
5
|
Examples
|
|
10
6
|
--------
|
|
@@ -13,7 +13,7 @@ from typing import Any
|
|
|
13
13
|
|
|
14
14
|
_SUSCEPTIBILITY_ORDER: dict[str, int] = {"S": 0, "I": 1, "R": 2}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
_DEFAULT_LABEL_MAP: dict = {
|
|
17
17
|
0: "Susceptible (S)",
|
|
18
18
|
1: "Resistant (R)",
|
|
19
19
|
"S": "Susceptible (S)",
|
|
@@ -64,4 +64,4 @@ def resolve_display_label(label: Any, label_map: dict | None = None) -> str:
|
|
|
64
64
|
"""
|
|
65
65
|
if label_map and label in label_map:
|
|
66
66
|
return str(label_map[label])
|
|
67
|
-
return str(
|
|
67
|
+
return str(_DEFAULT_LABEL_MAP.get(label, label))
|
|
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Any, Literal
|
|
|
8
8
|
import numpy as np
|
|
9
9
|
import pandas as pd
|
|
10
10
|
|
|
11
|
-
from ._common import
|
|
11
|
+
from ._common import _DEFAULT_LABEL_MAP, order_labels, show_with_warning
|
|
12
12
|
|
|
13
13
|
if TYPE_CHECKING:
|
|
14
14
|
from matplotlib.axes import Axes
|
|
@@ -312,7 +312,7 @@ def plot_pseudogel(
|
|
|
312
312
|
display_vmin = np.log1p(vmin) if (log_scale and vmin is not None) else vmin
|
|
313
313
|
display_vmax = np.log1p(vmax) if (log_scale and vmax is not None) else vmax
|
|
314
314
|
|
|
315
|
-
merged_label_map: dict = dict(
|
|
315
|
+
merged_label_map: dict = dict(_DEFAULT_LABEL_MAP)
|
|
316
316
|
if label_map:
|
|
317
317
|
merged_label_map.update(label_map)
|
|
318
318
|
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"""Evaluation utilities for AMR prediction.
|
|
2
|
-
|
|
3
|
-
The label encoder previously lived here; in v0.15 it moved to
|
|
4
|
-
:mod:`maldiamrkit.susceptibility` along with the new MIC encoder and
|
|
5
|
-
breakpoint table. Access via ``from maldiamrkit.evaluation import LabelEncoder``
|
|
6
|
-
still works for one release with a :class:`DeprecationWarning`.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
|
|
11
|
-
import warnings
|
|
12
|
-
|
|
13
|
-
from .metrics import (
|
|
14
|
-
amr_classification_report,
|
|
15
|
-
amr_multilabel_report,
|
|
16
|
-
categorical_agreement,
|
|
17
|
-
major_error_rate,
|
|
18
|
-
me_scorer,
|
|
19
|
-
sensitivity_score,
|
|
20
|
-
specificity_score,
|
|
21
|
-
very_major_error_rate,
|
|
22
|
-
vme_me_curve,
|
|
23
|
-
vme_scorer,
|
|
24
|
-
)
|
|
25
|
-
from .mic_regression import mic_regression_report
|
|
26
|
-
from .splitting import (
|
|
27
|
-
CaseGroupedKFold,
|
|
28
|
-
SpeciesDrugStratifiedKFold,
|
|
29
|
-
case_based_split,
|
|
30
|
-
stratified_species_drug_split,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
_LAZY_DEPRECATED = {
|
|
34
|
-
"LabelEncoder": "maldiamrkit.susceptibility.LabelEncoder",
|
|
35
|
-
"IntermediateHandling": "maldiamrkit.susceptibility.IntermediateHandling",
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def __getattr__(name: str):
|
|
40
|
-
if name in _LAZY_DEPRECATED:
|
|
41
|
-
new_path = _LAZY_DEPRECATED[name]
|
|
42
|
-
warnings.warn(
|
|
43
|
-
f"{name} has moved to {new_path}; "
|
|
44
|
-
f"importing from maldiamrkit.evaluation is deprecated and "
|
|
45
|
-
f"will be removed in v0.17.",
|
|
46
|
-
DeprecationWarning,
|
|
47
|
-
stacklevel=2,
|
|
48
|
-
)
|
|
49
|
-
from ..susceptibility.label_encoder import (
|
|
50
|
-
IntermediateHandling,
|
|
51
|
-
LabelEncoder,
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
"LabelEncoder": LabelEncoder,
|
|
56
|
-
"IntermediateHandling": IntermediateHandling,
|
|
57
|
-
}[name]
|
|
58
|
-
raise AttributeError(f"module 'maldiamrkit.evaluation' has no attribute {name!r}")
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def __dir__() -> list[str]:
|
|
62
|
-
return sorted(list(__all__) + list(_LAZY_DEPRECATED.keys()))
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
__all__ = [
|
|
66
|
-
"very_major_error_rate",
|
|
67
|
-
"major_error_rate",
|
|
68
|
-
"sensitivity_score",
|
|
69
|
-
"specificity_score",
|
|
70
|
-
"categorical_agreement",
|
|
71
|
-
"vme_me_curve",
|
|
72
|
-
"amr_classification_report",
|
|
73
|
-
"amr_multilabel_report",
|
|
74
|
-
"mic_regression_report",
|
|
75
|
-
"vme_scorer",
|
|
76
|
-
"me_scorer",
|
|
77
|
-
"stratified_species_drug_split",
|
|
78
|
-
"case_based_split",
|
|
79
|
-
"SpeciesDrugStratifiedKFold",
|
|
80
|
-
"CaseGroupedKFold",
|
|
81
|
-
]
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"""Deprecated location for :class:`LabelEncoder`.
|
|
2
|
-
|
|
3
|
-
Moved to :mod:`maldiamrkit.susceptibility` in v0.15. Attribute access on
|
|
4
|
-
this module emits a :class:`DeprecationWarning` and forwards to the new
|
|
5
|
-
location; the shim will be removed in a future release.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from __future__ import annotations
|
|
9
|
-
|
|
10
|
-
import warnings
|
|
11
|
-
|
|
12
|
-
_DEPRECATED = ("LabelEncoder", "IntermediateHandling")
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def __getattr__(name: str):
|
|
16
|
-
if name in _DEPRECATED:
|
|
17
|
-
warnings.warn(
|
|
18
|
-
"maldiamrkit.evaluation.label_encoder is deprecated; "
|
|
19
|
-
"import from maldiamrkit.susceptibility instead. "
|
|
20
|
-
"Will be removed in v0.17.",
|
|
21
|
-
DeprecationWarning,
|
|
22
|
-
stacklevel=2,
|
|
23
|
-
)
|
|
24
|
-
from ..susceptibility.label_encoder import (
|
|
25
|
-
IntermediateHandling,
|
|
26
|
-
LabelEncoder,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
"LabelEncoder": LabelEncoder,
|
|
31
|
-
"IntermediateHandling": IntermediateHandling,
|
|
32
|
-
}[name]
|
|
33
|
-
raise AttributeError(
|
|
34
|
-
f"module 'maldiamrkit.evaluation.label_encoder' has no attribute {name!r}"
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def __dir__() -> list[str]:
|
|
39
|
-
return list(_DEPRECATED)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
__all__ = list(_DEPRECATED)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v1.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v1.1.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v1.2.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v1.3.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v10.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v11.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v12.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v13.1.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v14.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v15.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v16.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v2.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v4.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v5.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v6.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v7.1.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v8.0.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v8.1.yaml
RENAMED
|
File without changes
|
{maldiamrkit-0.17.0 → maldiamrkit-0.18.0}/maldiamrkit/data/breakpoints/eucast/eucast_v9.0.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|