Shared data model
MaldiSet keeps the spectra and their metadata (species, batch, MIC, acquisition date) under the same sample IDs, and correctors match batch labels and covariates to the spectra by ID, not by position.
Preprocessing, batch correction and deep-learning classifiers that share one data model and the scikit-learn API.
pip install maldisuite
m/z (Da). A spectrum from the MaldiAMRKit example data, before and after the default preprocessing.
Why MaldiSuite
MaldiSet keeps the spectra and their metadata (species, batch, MIC, acquisition date) under the same sample IDs, and correctors match batch labels and covariates to the spectra by ID, not by position.
Every transformer is fitted on the training folds and applied unchanged to held-out data, and grouped cross-validation keeps all spectra of a patient, or of an isolate, in the same fold.
Correctors and classifiers are estimators, so Pipeline, cross_val_score and GridSearchCV work without glue code.
Fixed seeds, versions pinned by the meta-package and a Bruker-native data path make reruns from raw spectra repeatable in the same environment.
Packages
Each package has its own repository, documentation and release cycle. Install them one by one, or all together with the maldisuite meta-package.


Data model, preprocessing and AMR-aware evaluation for MALDI-TOF spectra
PreprocessingPipeline, serialisable to JSON/YAMLpip install maldiamrkit


Batch-effect correction for multi-site MALDI-TOF spectra
BatchAwareWarping, QualityWeightedComBat and SpeciesAwareComBatAutoCorrector to pick the corrector inside GridSearchCVBatchCorrectionBenchmarkMaldiSetAdapter and a command-line interfacepip install maldibatchkit


Deep-learning classifiers for binned MALDI-TOF spectra
MaldiMLPClassifier, MaldiCNNClassifier, MaldiResNetClassifier and MaldiTransformerClassifierfrom_spectrum() for other layoutsMaldiSpectrumEncoderpip install maldideepkit
maldisuite meta-packageOne command installs the three packages at versions tested together, with the mzML/mzXML, batch-correction and plotting extras.
pip install maldisuite
| Package | Pinned range | Latest on PyPI |
|---|---|---|
| MaldiAMRKit | [batch,formats] >=0.22.2,<0.23 |
0.22.3 |
| MaldiBatchKit | [viz] >=0.2.0,<0.3 |
0.2.2 |
| MaldiDeepKit | >=0.4.0,<0.5 |
0.4.0 |
Latest versions are read from PyPI when the page loads.
Combine
Each package can be used on its own. Because they share the MaldiSet data model and the scikit-learn API, they also fit in a single Pipeline when a study needs more than one. This is one way to combine all three.
Bruker fid/1r, txt, mzML/mzXML
+ metadata: species, drug, MIC, site, date
R / S per isolate
scored with VME, ME and AUROC
Any package can be left out or used on its own. MaldiBatchKit, for example, is useful only when spectra come from several sites or instruments.
Quick start
pip install maldiamrkit
Python 3.10 or newer. scikit-learn is installed with it.
Point MaldiSet at a folder of spectra, one .txt file per spectrum named after its ID, and a metadata CSV with an ID column, the resistance label and the patient. Labels are encoded as R = 1, S = 0. See the MaldiAMRKit example data for both formats.
Warping and the classifier are refitted inside every training fold, vme_scorer reports the very major error rate, and CaseGroupedKFold keeps all spectra of a patient in the same fold.
from maldiamrkit import MaldiSet
from maldiamrkit.alignment import Warping
from maldiamrkit.evaluation import CaseGroupedKFold, vme_scorer
from maldiamrkit.susceptibility import LabelEncoder
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
# metadata.csv: ID, Drug (R/S), patient_id
data = MaldiSet.from_directory("spectra/", "metadata.csv", bin_width=3)
meta = data.meta.loc[data.X.index]
y = LabelEncoder().fit_transform(data.get_y_single("Drug")) # R=1, S=0
pipe = Pipeline([
("warp", Warping(method="shift")),
("scale", StandardScaler()),
("clf", LogisticRegression(max_iter=1000)),
])
scores = cross_val_score(
pipe, data.X, y,
scoring=vme_scorer,
cv=CaseGroupedKFold(n_splits=5, random_state=0),
groups=meta["patient_id"],
)
print(f"VME: {-scores.mean():.3f}")
Tested with maldiamrkit 0.22.3.
pip install maldibatchkit
Python 3.10 or newer. Works on any spectra-by-bins table, with or without MaldiAMRKit.
A table with one row per spectrum and one column per bin, and the batch and species of each spectrum, matched by ID.
SpeciesAwareComBat removes site effects while keeping species differences, and diagnostic_report compares kBET, LISI and silhouette before and after. Inside a Pipeline it is fitted on the training folds only.
import pandas as pd
from maldibatchkit import SpeciesAwareComBat
from maldibatchkit.diagnostics import diagnostic_report
# X.csv: one row per spectrum, one column per bin; metadata.csv: ID, batch, Species
X = pd.read_csv("X.csv", index_col="ID")
meta = pd.read_csv("metadata.csv", index_col="ID").loc[X.index]
combat = SpeciesAwareComBat(batch=meta["batch"], species=meta["Species"])
X_corrected = combat.fit_transform(X)
print(diagnostic_report(X, X_corrected, meta["batch"]))
Tested with maldibatchkit 0.2.2.
pip install maldideepkit
Python 3.10 or newer. The models run on CPU; a CUDA GPU makes training much faster.
Any matrix of binned spectra, with 0/1 labels and the patient of each spectrum. The defaults are tuned for 6000-bin spectra.
Each classifier is a scikit-learn estimator, so cross_val_score and grouped splits work as with any other model.
import numpy as np
from maldideepkit import MaldiCNNClassifier
from sklearn.model_selection import StratifiedGroupKFold, cross_val_score
# X.npy: binned spectra (n_spectra, n_bins); y.npy: 0/1 labels; groups.npy: patient IDs
X = np.load("X.npy").astype("float32")
y = np.load("y.npy")
groups = np.load("groups.npy", allow_pickle=True)
clf = MaldiCNNClassifier(input_dim=X.shape[1], random_state=0)
scores = cross_val_score(
clf, X, y,
scoring="roc_auc",
cv=StratifiedGroupKFold(n_splits=5),
groups=groups,
)
print(f"AUROC: {scores.mean():.3f}")
Tested with maldideepkit 0.4.0.
pip install maldisuite
Python 3.10 or newer. The deep models run on CPU; a CUDA GPU makes training much faster.
Point MaldiSet at a folder of spectra, one .txt file per spectrum named after its ID, and a metadata CSV with an ID column, the resistance label, species, batch and patient. Labels are encoded as R = 1, S = 0. See the MaldiAMRKit example data for both formats.
Warping, ComBat and the classifier are refitted inside every training fold, and CaseGroupedKFold keeps all spectra of a patient in the same fold.
from maldiamrkit import MaldiSet
from maldiamrkit.evaluation import CaseGroupedKFold, vme_scorer
from maldiamrkit.susceptibility import LabelEncoder
from maldibatchkit import BatchAwareWarping, SpeciesAwareComBat
from maldideepkit import MaldiMLPClassifier
from sklearn.model_selection import cross_val_score
from sklearn.pipeline import Pipeline
# metadata.csv: ID, Drug (R/S), Species, batch, patient_id
data = MaldiSet.from_directory("spectra/", "metadata.csv", bin_width=3)
meta = data.meta.loc[data.X.index]
y = LabelEncoder().fit_transform(data.get_y_single("Drug")) # R=1, S=0
pipe = Pipeline([
("warp", BatchAwareWarping(batch=meta["batch"])),
("combat", SpeciesAwareComBat(batch=meta["batch"],
species=meta["Species"])),
("clf", MaldiMLPClassifier(input_dim=data.X.shape[1],
random_state=0)),
])
scores = cross_val_score(
pipe, data.X, y,
scoring=vme_scorer,
cv=CaseGroupedKFold(n_splits=5, random_state=0),
groups=meta["patient_id"],
)
print(f"VME: {-scores.mean():.3f}")
Tested with maldiamrkit 0.22.3, maldibatchkit 0.2.2 and maldideepkit 0.4.0.
Results
Aggregated results from the analysis behind the MaldiSuite Application Note (under review), on the four DRIAMS sites. Classification scores are means over 3 repeats × 5 folds.
best classifier at each site. n/a: drug not tested at that site. Hover or focus a cell for balanced accuracy, MCC, VME and ME.
Data: results/ of the MaldiSuite-paper repository. Spectra from DRIAMS (Weis et al., Nature Medicine 2022).
Research
MaldiSuite is described in an Application Note currently under review.
Using MaldiSuite in your research? Let us know on GitHub and we will list it here.
Roadmap
The latest release of each package, what is in development and what is planned after it. Order and scope may change.