MaldiBatchKit 0.1.0__tar.gz → 0.2.1__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.
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1/MaldiBatchKit.egg-info}/PKG-INFO +104 -76
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/MaldiBatchKit.egg-info/SOURCES.txt +5 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/MaldiBatchKit.egg-info/requires.txt +2 -2
- {maldibatchkit-0.1.0/MaldiBatchKit.egg-info → maldibatchkit-0.2.1}/PKG-INFO +104 -76
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/README.md +101 -73
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/__init__.py +36 -4
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/_base.py +40 -6
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/_cli_io.py +93 -60
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/_utils.py +79 -5
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/cli.py +69 -11
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/corrections/__init__.py +5 -0
- maldibatchkit-0.2.1/maldibatchkit/corrections/auto.py +360 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/corrections/baselines.py +22 -13
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/corrections/combat.py +55 -12
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/corrections/harmony.py +58 -74
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/corrections/limma.py +4 -2
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/corrections/maldi.py +1 -1
- maldibatchkit-0.2.1/maldibatchkit/corrections/noop.py +59 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/corrections/quality_weighted.py +58 -19
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/diagnostics/__init__.py +2 -0
- maldibatchkit-0.2.1/maldibatchkit/diagnostics/benchmark.py +818 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/diagnostics/generic.py +5 -4
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/diagnostics/maldi.py +9 -5
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/diagnostics/report.py +41 -20
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/integrations/maldiset.py +76 -28
- maldibatchkit-0.2.1/maldibatchkit/metrics.py +584 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/viz/peaks.py +2 -2
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/viz/summary.py +0 -3
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/viz/umap.py +4 -2
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/requirements.txt +2 -2
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/tests/test_cli.py +178 -2
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/tests/test_cli_io.py +46 -9
- maldibatchkit-0.2.1/tests/test_metrics.py +378 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/tests/test_mz_axis_resolution.py +22 -15
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/tests/test_no_data_leakage.py +1 -20
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/tests/test_package.py +1 -1
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/LICENSE +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/MaldiBatchKit.egg-info/dependency_links.txt +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/MaldiBatchKit.egg-info/entry_points.txt +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/MaldiBatchKit.egg-info/top_level.txt +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/integrations/__init__.py +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/py.typed +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/maldibatchkit/viz/__init__.py +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/pyproject.toml +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/requirements-dev.txt +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/requirements-docs.txt +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/requirements-viz.txt +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/setup.cfg +0 -0
- {maldibatchkit-0.1.0 → maldibatchkit-0.2.1}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: MaldiBatchKit
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Batch-effect correction methods for MALDI-TOF spectra in clinical AMR prediction workflows
|
|
5
5
|
Author-email: Ettore Rocchi <ettore.rocchi3@unibo.it>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -27,9 +27,9 @@ Requires-Dist: pandas>=1.3.0
|
|
|
27
27
|
Requires-Dist: scipy>=1.13.0
|
|
28
28
|
Requires-Dist: scikit-learn>=1.6.0
|
|
29
29
|
Requires-Dist: matplotlib>=3.4.0
|
|
30
|
-
Requires-Dist: combatlearn>=2.
|
|
30
|
+
Requires-Dist: combatlearn>=2.4.0
|
|
31
31
|
Requires-Dist: harmonypy<2,>=0.2.0
|
|
32
|
-
Requires-Dist: maldiamrkit>=0.
|
|
32
|
+
Requires-Dist: maldiamrkit>=0.15.0
|
|
33
33
|
Requires-Dist: typer>=0.9.0
|
|
34
34
|
Provides-Extra: dev
|
|
35
35
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
@@ -55,8 +55,10 @@ Dynamic: license-file
|
|
|
55
55
|
|
|
56
56
|
[](https://github.com/EttoreRocchi/MaldiBatchKit/actions/workflows/ci.yml)
|
|
57
57
|
[](https://codecov.io/github/EttoreRocchi/MaldiBatchKit)
|
|
58
|
-
[](https://maldibatchkit.readthedocs.io/)
|
|
59
|
+
|
|
60
|
+
[](https://pypi.org/project/maldibatchkit/)
|
|
61
|
+
[](https://pypi.org/project/maldibatchkit/)
|
|
60
62
|
[](https://github.com/EttoreRocchi/MaldiBatchKit/blob/main/LICENSE)
|
|
61
63
|
|
|
62
64
|
<p align="center">
|
|
@@ -67,21 +69,21 @@ Dynamic: license-file
|
|
|
67
69
|
<strong>Batch-effect correction methods for MALDI-TOF spectra in clinical AMR prediction workflows</strong>
|
|
68
70
|
</p>
|
|
69
71
|
|
|
72
|
+
<p align="center">
|
|
73
|
+
<img src="docs/batch_correction.svg" alt="Animated scatter plot: before correction MALDI-TOF samples cluster by acquisition site; after MaldiBatchKit the site effect is removed and samples cluster by species" width="720"/>
|
|
74
|
+
</p>
|
|
75
|
+
|
|
70
76
|
<p align="center">
|
|
71
77
|
<a href="#installation">Installation</a> •
|
|
72
78
|
<a href="#features">Features</a> •
|
|
73
79
|
<a href="#quick-start">Quick Start</a> •
|
|
74
80
|
<a href="#algorithms">Algorithms</a> •
|
|
75
81
|
<a href="#diagnostics">Diagnostics</a> •
|
|
82
|
+
<a href="#maldisuite-ecosystem">MaldiSuite</a> •
|
|
76
83
|
<a href="#citation">Citation</a>
|
|
77
84
|
</p>
|
|
78
85
|
|
|
79
|
-
MaldiBatchKit is part of the **MaldiSuite** ecosystem and complements
|
|
80
|
-
[MaldiAMRKit](https://github.com/EttoreRocchi/MaldiAMRKit): where
|
|
81
|
-
MaldiAMRKit handles preprocessing, alignment and AMR-aware evaluation,
|
|
82
|
-
MaldiBatchKit focuses on the *harmonization* step, removing the
|
|
83
|
-
inter-batch / inter-site shifts that plague multi-centre MALDI-TOF
|
|
84
|
-
studies.
|
|
86
|
+
MaldiBatchKit is part of the **MaldiSuite** ecosystem and complements [MaldiAMRKit](https://github.com/EttoreRocchi/MaldiAMRKit): where MaldiAMRKit handles preprocessing, alignment and AMR-aware evaluation, MaldiBatchKit focuses on the *harmonization* step, removing the inter-batch / inter-site shifts that plague multi-centre MALDI-TOF studies.
|
|
85
87
|
|
|
86
88
|
## Installation
|
|
87
89
|
|
|
@@ -97,40 +99,34 @@ pip install maldibatchkit[dev] # testing + linting
|
|
|
97
99
|
pip install maldibatchkit[docs] # sphinx
|
|
98
100
|
```
|
|
99
101
|
|
|
100
|
-
`maldiamrkit` is a core dependency - installing MaldiBatchKit pulls
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
`maldiamrkit` is a core dependency - installing MaldiBatchKit pulls it in automatically. `BatchAwareWarping` reuses `maldiamrkit.alignment.Warping` under the hood, and the `MaldiSetAdapter` bridges to `maldiamrkit.MaldiSet` for end-to-end AMR workflows.
|
|
103
|
+
|
|
104
|
+
### Install the full MaldiSuite
|
|
105
|
+
|
|
106
|
+
To install MaldiBatchKit together with [MaldiAMRKit](https://github.com/EttoreRocchi/MaldiAMRKit) and [MaldiDeepKit](https://github.com/EttoreRocchi/MaldiDeepKit) at compatible versions, install the [`maldisuite`](https://pypi.org/project/maldisuite/) meta-package:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install maldisuite
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Visit the **MaldiSuite** landing page at <https://ettorerocchi.github.io/MaldiSuite/>.
|
|
105
113
|
|
|
106
114
|
## Features
|
|
107
115
|
|
|
108
|
-
- **Unified sklearn API** (`BaseEstimator` + `TransformerMixin`) for
|
|
109
|
-
|
|
110
|
-
construction time and aligned to `X.index` at `fit` / `transform`,
|
|
111
|
-
so the same object works inside `Pipeline` / cross-validation
|
|
112
|
-
without data leakage.
|
|
113
|
-
- **ComBat variants** (Johnson 2007, Fortin 2018, Chen 2022 CovBat)
|
|
114
|
-
re-exported from [combatlearn](https://github.com/EttoreRocchi/combatlearn).
|
|
116
|
+
- **Unified sklearn API** (`BaseEstimator` + `TransformerMixin`) for every correction method. `batch` and covariates are passed at construction time and aligned to `X.index` at `fit` / `transform`, so the same object works inside `Pipeline` / cross-validation without data leakage.
|
|
117
|
+
- **ComBat variants** (Johnson 2007, Fortin 2018, Chen 2022 CovBat) re-exported from [combatlearn](https://github.com/EttoreRocchi/combatlearn).
|
|
115
118
|
- **Limma `removeBatchEffect`** (Ritchie et al. 2015).
|
|
116
119
|
- **Harmony** (Korsunsky et al. 2019) via [harmonypy](https://github.com/slowkow/harmonypy), with a **mandatory, frozen PCA preprocessing stage** so it behaves sensibly on high-dimensional MALDI-TOF intensity matrices (tune with the `n_components=` argument).
|
|
117
|
-
- **Simple baselines**: median centering, z-score per batch,
|
|
118
|
-
reference scaling.
|
|
120
|
+
- **Simple baselines**: median centering, z-score per batch, reference scaling.
|
|
119
121
|
- **MALDI-specific corrections**:
|
|
120
|
-
- `BatchAwareWarping` - per-batch m/z warping sharing a global
|
|
121
|
-
|
|
122
|
-
- `
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
- **
|
|
128
|
-
drift, per-batch TIC coefficient of variation, per-batch spectrum
|
|
129
|
-
count, plus a combined `diagnostic_report` DataFrame summary.
|
|
130
|
-
- **Visualization**: UMAP before/after, per-batch peak-shape overlays,
|
|
131
|
-
before/after bar charts.
|
|
132
|
-
- **Integration adapter**: `MaldiSetAdapter` turns a
|
|
133
|
-
`maldiamrkit.MaldiSet` into a corrected `MaldiSet` in one call.
|
|
122
|
+
- `BatchAwareWarping` - per-batch m/z warping sharing a global reference (wraps `maldiamrkit.alignment.Warping`).
|
|
123
|
+
- `QualityWeightedComBat` - weighted empirical-Bayes ComBat variant where low-SNR spectra contribute less to the shrinkage prior.
|
|
124
|
+
- `SpeciesAwareComBat` - convenience preset for ComBat-Fortin with `species` as the protected biological covariate.
|
|
125
|
+
- **Diagnostics**: kBET, LISI, silhouette-by-batch, per-batch peak drift, per-batch TIC coefficient of variation, per-batch spectrum count, plus a combined `diagnostic_report` DataFrame summary.
|
|
126
|
+
- **Method selection**: `AutoCorrector` exposes `method` as a settable hyperparameter so `GridSearchCV` can sweep across corrector families and let the downstream classifier metric (AUROC) decide. Ships with a `NoOpCorrector` so "do nothing" can sit on the candidate list as an honest baseline.
|
|
127
|
+
- **Diagnostic benchmark**: `BatchCorrectionBenchmark` runs a fixed set of metrics across multiple correctors with stratified bootstrap CIs and a tidy `(method, metric, value, ci_lo, ci_hi)` summary, ready for paper-figure comparisons.
|
|
128
|
+
- **Visualization**: UMAP before/after, per-batch peak-shape overlays, before/after bar charts.
|
|
129
|
+
- **Integration adapter**: `MaldiSetAdapter` turns a `maldiamrkit.MaldiSet` into a corrected `MaldiSet` in one call.
|
|
134
130
|
- **CLI**: `maldibatchkit correct ...` and `maldibatchkit diagnose ...`.
|
|
135
131
|
|
|
136
132
|
## Quick start
|
|
@@ -160,8 +156,7 @@ X_train_c = corrector.transform(X_train)
|
|
|
160
156
|
X_test_c = corrector.transform(X_test) # same parameters applied to test
|
|
161
157
|
```
|
|
162
158
|
|
|
163
|
-
`batch` is indexed by the same sample IDs that X uses, so the
|
|
164
|
-
corrector picks the right subset on each call.
|
|
159
|
+
`batch` is indexed by the same sample IDs that X uses, so the corrector picks the right subset on each call.
|
|
165
160
|
|
|
166
161
|
### MaldiSet integration
|
|
167
162
|
|
|
@@ -183,9 +178,7 @@ corrected_ds.y # AMR labels, unchanged
|
|
|
183
178
|
|
|
184
179
|
### CLI
|
|
185
180
|
|
|
186
|
-
The CLI is organised as `maldibatchkit correct <method>` +
|
|
187
|
-
`maldibatchkit diagnose`. Every method has its own subcommand with
|
|
188
|
-
only the flags it actually uses:
|
|
181
|
+
The CLI is organised as `maldibatchkit correct <method>` + `maldibatchkit diagnose`. Every method has its own subcommand with only the flags it actually uses:
|
|
189
182
|
|
|
190
183
|
```bash
|
|
191
184
|
# Vanilla Johnson ComBat
|
|
@@ -214,8 +207,7 @@ maldibatchkit diagnose \
|
|
|
214
207
|
--batch-csv batch.csv --mz-csv mz.csv -o report.csv
|
|
215
208
|
```
|
|
216
209
|
|
|
217
|
-
NPZ inputs bundle X, index, columns, and batch labels in one file, so
|
|
218
|
-
the same commands work without sidecar CSVs:
|
|
210
|
+
NPZ inputs bundle X, index, columns, and batch labels in one file, so the same commands work without sidecar CSVs:
|
|
219
211
|
|
|
220
212
|
```bash
|
|
221
213
|
maldibatchkit correct combat-fortin \
|
|
@@ -224,11 +216,7 @@ maldibatchkit correct combat-fortin \
|
|
|
224
216
|
-o corrected.npz
|
|
225
217
|
```
|
|
226
218
|
|
|
227
|
-
Run `maldibatchkit correct <method> --help` for the full flag list of
|
|
228
|
-
any corrector. `combat-fortin` / `combat-chen` refuse to run without
|
|
229
|
-
covariates (they would silently reduce to Johnson ComBat);
|
|
230
|
-
`species-combat` / `quality-combat` require their dedicated
|
|
231
|
-
`--species-csv` / `--quality-csv` inputs.
|
|
219
|
+
Run `maldibatchkit correct <method> --help` for the full flag list of any corrector. `combat-fortin` refuses to run without covariates (it would silently reduce to Johnson ComBat); `combat-chen` without covariates is plain CovBat (Johnson ComBat plus the covariance correction); `species-combat` / `quality-combat` require their dedicated `--species-csv` / `--quality-csv` inputs.
|
|
232
220
|
|
|
233
221
|
## Algorithms
|
|
234
222
|
|
|
@@ -236,34 +224,72 @@ covariates (they would silently reduce to Johnson ComBat);
|
|
|
236
224
|
|--------------------------------|---------------------------|----------------------|------------------|
|
|
237
225
|
| ComBat (Johnson, Fortin, Chen) | `ComBat` | Fortin / Chen | yes |
|
|
238
226
|
| Limma | `Limma` | via `design=` | yes |
|
|
239
|
-
| Harmony | `Harmony` |
|
|
227
|
+
| Harmony | `Harmony` | no (removes them) | yes |
|
|
240
228
|
| Median centering | `MedianCentering` | no | yes |
|
|
241
229
|
| Z-score per batch | `ZScorePerBatch` | no | yes |
|
|
242
230
|
| Reference scaling | `ReferenceScaling` | no | yes |
|
|
243
231
|
| Batch-aware warping | `BatchAwareWarping` | no | yes |
|
|
244
232
|
| Quality-weighted ComBat | `QualityWeightedComBat` | no | yes |
|
|
245
233
|
| Species-aware ComBat | `SpeciesAwareComBat` | species | yes |
|
|
234
|
+
| Identity / no-op | `NoOpCorrector` | n/a | yes |
|
|
235
|
+
| Meta-corrector | `AutoCorrector` | inherits inner | yes |
|
|
236
|
+
|
|
237
|
+
See the `QualityWeightedComBat` docstring for the mathematical formulation of the weighted empirical-Bayes update.
|
|
238
|
+
|
|
239
|
+
### Choosing a corrector
|
|
240
|
+
|
|
241
|
+
Picking among the methods above usually means asking one of two
|
|
242
|
+
questions: *"which corrector gives the best AMR classifier?"* or
|
|
243
|
+
*"which corrector mixes batches best while keeping species apart?"*.
|
|
244
|
+
MaldiBatchKit ships one tool for each:
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
from sklearn.linear_model import LogisticRegression
|
|
248
|
+
from sklearn.model_selection import GridSearchCV
|
|
249
|
+
from sklearn.pipeline import Pipeline
|
|
250
|
+
from maldibatchkit import AutoCorrector
|
|
251
|
+
|
|
252
|
+
pipe = Pipeline([
|
|
253
|
+
("correct", AutoCorrector(batch=batch, discrete_covariates=species)),
|
|
254
|
+
("clf", LogisticRegression(max_iter=1000)),
|
|
255
|
+
])
|
|
256
|
+
grid = GridSearchCV(
|
|
257
|
+
pipe,
|
|
258
|
+
param_grid={"correct__method": ["noop", "combat-fortin", "harmony", "qw-combat"]},
|
|
259
|
+
scoring="roc_auc",
|
|
260
|
+
)
|
|
261
|
+
grid.fit(X, y)
|
|
262
|
+
```
|
|
246
263
|
|
|
247
|
-
|
|
248
|
-
|
|
264
|
+
```python
|
|
265
|
+
from maldibatchkit import ComBat, NoOpCorrector
|
|
266
|
+
from maldibatchkit.diagnostics import BatchCorrectionBenchmark
|
|
267
|
+
|
|
268
|
+
bench = BatchCorrectionBenchmark(
|
|
269
|
+
correctors={
|
|
270
|
+
"none": NoOpCorrector(batch=batch),
|
|
271
|
+
"fortin": ComBat(batch=batch, method="fortin", discrete_covariates=species),
|
|
272
|
+
},
|
|
273
|
+
metrics=("kbet", "lisi_normalized", "species_preservation"),
|
|
274
|
+
n_bootstrap=500,
|
|
275
|
+
random_state=0,
|
|
276
|
+
).fit(X, batch=batch, species=species)
|
|
277
|
+
bench.rank(by="species_preservation")
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
See [docs / Choosing a corrector](https://maldibatchkit.readthedocs.io/en/latest/choosing.html) for the full recipe.
|
|
249
281
|
|
|
250
282
|
## Extending MaldiBatchKit
|
|
251
283
|
|
|
252
|
-
Every corrector in this package inherits from `BaseBatchCorrector`,
|
|
253
|
-
which is re-exported at the top level. Subclass it, implement
|
|
254
|
-
`_fit_impl` and `_transform_impl`, and you get a scikit-learn compatible,
|
|
255
|
-
train/test-safe corrector for free - the base class handles index
|
|
256
|
-
alignment between `X` and the stored `batch` labels, NaN / finite
|
|
257
|
-
checks, DataFrame-vs-ndarray round-tripping, and the `feature_names_in_`
|
|
258
|
-
/ `n_features_in_` / `get_feature_names_out` sklearn bookkeeping.
|
|
284
|
+
Every corrector in this package inherits from `BaseBatchCorrector`, which is re-exported at the top level. Subclass it, implement `_fit_impl` and `_transform_impl`, and you get a scikit-learn compatible, train/test-safe corrector for free - the base class handles index alignment between `X` and the stored `batch` labels, NaN / finite checks, DataFrame-vs-ndarray round-tripping, and the `feature_names_in_` / `n_features_in_` / `get_feature_names_out` sklearn bookkeeping.
|
|
259
285
|
|
|
260
|
-
Minimal custom corrector:
|
|
286
|
+
Minimal custom corrector (toy example - not shipped with the package):
|
|
261
287
|
|
|
262
288
|
```python
|
|
263
289
|
import pandas as pd
|
|
264
290
|
from maldibatchkit import BaseBatchCorrector
|
|
265
291
|
|
|
266
|
-
class
|
|
292
|
+
class MyMeanCentering(BaseBatchCorrector):
|
|
267
293
|
"""Subtract per-batch means from each feature."""
|
|
268
294
|
|
|
269
295
|
def _fit_impl(self, X_df, batch):
|
|
@@ -294,7 +320,7 @@ from sklearn.preprocessing import StandardScaler
|
|
|
294
320
|
from sklearn.ensemble import RandomForestClassifier
|
|
295
321
|
|
|
296
322
|
pipe = Pipeline([
|
|
297
|
-
("mean",
|
|
323
|
+
("mean", MyMeanCentering(batch=batch)), # the class defined just above
|
|
298
324
|
("scaler", StandardScaler()),
|
|
299
325
|
("clf", RandomForestClassifier()),
|
|
300
326
|
])
|
|
@@ -307,14 +333,9 @@ Conventions (see `CONTRIBUTING.md`):
|
|
|
307
333
|
- NumPy-style docstring on every public class.
|
|
308
334
|
- Fitted attributes end in `_` (`self.batch_means_`, not `self.means`).
|
|
309
335
|
- `transform` must be idempotent - no side effects outside `fit`.
|
|
310
|
-
- Raise a clear `ImportError` (not a bare `ModuleNotFoundError`) when
|
|
311
|
-
an optional dependency is missing; see `Harmony._require_harmonypy`
|
|
312
|
-
for the reference pattern.
|
|
336
|
+
- Raise a clear `ImportError` (not a bare `ModuleNotFoundError`) when an optional dependency is missing; see `Harmony._require_harmonypy` for the reference pattern.
|
|
313
337
|
|
|
314
|
-
Look at `maldibatchkit/corrections/baselines.py` for the simplest
|
|
315
|
-
end-to-end references (`MedianCentering`, `ZScorePerBatch`,
|
|
316
|
-
`ReferenceScaling`), or at `quality_weighted.py` for a corrector with
|
|
317
|
-
an iterative fit.
|
|
338
|
+
Look at `maldibatchkit/corrections/baselines.py` for the simplest end-to-end references (`MedianCentering`, `ZScorePerBatch`, `ReferenceScaling`), or at `quality_weighted.py` for a corrector with an iterative fit.
|
|
318
339
|
|
|
319
340
|
## Diagnostics
|
|
320
341
|
|
|
@@ -326,9 +347,17 @@ from maldibatchkit.diagnostics import (
|
|
|
326
347
|
)
|
|
327
348
|
```
|
|
328
349
|
|
|
329
|
-
All metrics take the same `(X, batch)` signature. `diagnostic_report`
|
|
330
|
-
|
|
331
|
-
|
|
350
|
+
All metrics take the same `(X, batch)` signature. `diagnostic_report` composes them into a tidy DataFrame suitable for `plot_diagnostic_summary`.
|
|
351
|
+
|
|
352
|
+
## MaldiSuite Ecosystem
|
|
353
|
+
|
|
354
|
+
MaldiBatchKit is the harmonisation package of the **MaldiSuite** ecosystem:
|
|
355
|
+
|
|
356
|
+
- **[MaldiAMRKit](https://github.com/EttoreRocchi/MaldiAMRKit)** - data model (`MaldiSpectrum`, `MaldiSet`), preprocessing, alignment, peak detection, differential analysis, and AMR-aware evaluation.
|
|
357
|
+
- **MaldiBatchKit** (this package) - batch-effect correction and harmonisation for multi-centre / multi-instrument MALDI-TOF spectra.
|
|
358
|
+
- **[MaldiDeepKit](https://github.com/EttoreRocchi/MaldiDeepKit)** - sklearn-compatible deep learning classifiers (MLP, CNN, ResNet, Transformer).
|
|
359
|
+
|
|
360
|
+
The three packages share the `MaldiSet` / `MaldiSpectrum` data model and are designed to compose in a single end-to-end pipeline. Install the full suite with `pip install maldisuite`. Landing page: [MaldiSuite](<https://ettorerocchi.github.io/MaldiSuite/>).
|
|
332
361
|
|
|
333
362
|
## Citation
|
|
334
363
|
|
|
@@ -336,8 +365,7 @@ If you use MaldiBatchKit in academic work please cite:
|
|
|
336
365
|
|
|
337
366
|
> _Citation will be available soon._
|
|
338
367
|
|
|
339
|
-
along with the upstream references for whichever methods you apply
|
|
340
|
-
(Johnson 2007, Fortin 2018, Chen 2022, Ritchie 2015, Korsunsky 2019).
|
|
368
|
+
along with the upstream references for whichever methods you apply (Johnson 2007, Fortin 2018, Chen 2022, Ritchie 2015, Korsunsky 2019).
|
|
341
369
|
|
|
342
370
|
## License
|
|
343
371
|
|
|
@@ -16,15 +16,19 @@ maldibatchkit/_base.py
|
|
|
16
16
|
maldibatchkit/_cli_io.py
|
|
17
17
|
maldibatchkit/_utils.py
|
|
18
18
|
maldibatchkit/cli.py
|
|
19
|
+
maldibatchkit/metrics.py
|
|
19
20
|
maldibatchkit/py.typed
|
|
20
21
|
maldibatchkit/corrections/__init__.py
|
|
22
|
+
maldibatchkit/corrections/auto.py
|
|
21
23
|
maldibatchkit/corrections/baselines.py
|
|
22
24
|
maldibatchkit/corrections/combat.py
|
|
23
25
|
maldibatchkit/corrections/harmony.py
|
|
24
26
|
maldibatchkit/corrections/limma.py
|
|
25
27
|
maldibatchkit/corrections/maldi.py
|
|
28
|
+
maldibatchkit/corrections/noop.py
|
|
26
29
|
maldibatchkit/corrections/quality_weighted.py
|
|
27
30
|
maldibatchkit/diagnostics/__init__.py
|
|
31
|
+
maldibatchkit/diagnostics/benchmark.py
|
|
28
32
|
maldibatchkit/diagnostics/generic.py
|
|
29
33
|
maldibatchkit/diagnostics/maldi.py
|
|
30
34
|
maldibatchkit/diagnostics/report.py
|
|
@@ -36,6 +40,7 @@ maldibatchkit/viz/summary.py
|
|
|
36
40
|
maldibatchkit/viz/umap.py
|
|
37
41
|
tests/test_cli.py
|
|
38
42
|
tests/test_cli_io.py
|
|
43
|
+
tests/test_metrics.py
|
|
39
44
|
tests/test_mz_axis_resolution.py
|
|
40
45
|
tests/test_no_data_leakage.py
|
|
41
46
|
tests/test_package.py
|