Integrations Module#
Bridges between MaldiBatchKit and sibling toolkits in the MaldiSuite ecosystem.
MaldiSet Adapter#
- class maldibatchkit.integrations.MaldiSetAdapter(*, batch_column, species_column=None, quality_column=None)[source]#
Bases:
objectBridge
maldiamrkit.MaldiSetand MaldiBatchKit correctors.The adapter does three things:
Extracts the feature matrix
ds.Xand any metadata columns (batch / species / quality) from aMaldiSet.Delegates to a MaldiBatchKit corrector (or any sklearn-compatible transformer with the right constructor signature) to produce a corrected matrix.
Returns a new
MaldiSetwhoseXproperty yields the corrected matrix, leaving the original dataset untouched.
Batch / covariate slicing follows the rest of the package: pass the metadata column names at construction time; the adapter pulls the aligned series from
ds.metaitself so users do not have to rebuild arrays manually.- Parameters:
batch_column (
str) – Column inds.metawith the batch labels.species_column (
str|None) – Column inds.metawith species labels (used when the chosen corrector needs a species covariate).quality_column (
str|None) – Column inds.metawith per-sample quality scores (used bymaldibatchkit.QualityWeightedComBat).
Examples
>>> from maldiamrkit import MaldiSet >>> from maldibatchkit.integrations import MaldiSetAdapter >>> from maldibatchkit import SpeciesAwareComBat >>> adapter = MaldiSetAdapter(batch_column="Batch", species_column="Species") >>> corrected_ds = adapter.correct(ds, SpeciesAwareComBat) >>> corrected_ds.X.head() # corrected feature matrix
- correct(ds, transformer_cls, *, transformer_kwargs=None)[source]#
Run
transformer_cls(batch=..., ...)and return a new MaldiSet.- Parameters:
ds (
MaldiSet) – Source dataset.transformer_cls (type) – A MaldiBatchKit corrector class (or any transformer whose constructor takes
batch=and, optionally, a species-style protected-covariate argument namedspecies/discrete_covariates/design/covariatesand/or aquality=argument).transformer_kwargs (
dict[str,Any] |None) – Extra keyword arguments forwarded totransformer_cls.
- Returns:
Shallow-copied dataset with its
_X_cachereplaced by the corrected feature matrix. Thespectralist is the same object in the returnedMaldiSet; labels / metadata are unchanged.- Return type:
Example#
from maldiamrkit import MaldiSet
from maldibatchkit.integrations import MaldiSetAdapter
from maldibatchkit import SpeciesAwareComBat
# Load dataset (aggregated by an antibiotic label)
ds = MaldiSet.from_directory(
"spectra/", "metadata.csv",
aggregate_by=dict(antibiotics="Ceftriaxone"),
)
# The adapter reads batch / species / quality from ds.meta
adapter = MaldiSetAdapter(
batch_column="Batch",
species_column="Species",
quality_column="SNR",
)
# Returns a NEW MaldiSet with corrected X and untouched labels
corrected_ds = adapter.correct(ds, SpeciesAwareComBat)
corrected_ds.X # harmonised feature matrix
corrected_ds.y # AMR labels, unchanged