Skip to main content

maldi-nn

Deep learning tools and models for MALDI-TOF mass spectra analysis.

Package features:

  • Reading and preprocessing functions for MALDI-TOF MS spectra.
  • Model definitions to process SMILES strings with state-of-the-art techniques (for feature-based AMR prediction).
  • Model definitions to pre-train state-of-the-art Transformer networks on MALDI-TOF MS data
  • Model definitions and scripts to train AMR models on the DRIAMS database.
  • Model definitions and scripts to train species identification models.

Install

maldi-nn is distributed on PyPI.

pip install maldi-nn

In case this package loses backward-compatibility with more-recent versions of PyTorch and PyTorch Lightning: the code has been tested with torch==2.0.1 and pytorch-lightning==2.0.9. If you encounter errors with these packages, try running the code using these versions.

You may need to install PyTorch before running this command in order to ensure the right CUDA kernels for your system are installed

Quick start

We have uploaded some example spectra from the RKI database and our pre-trained models in the assets folder.

To quickly start playing around with our models, follow:

In bash:

pip install maldi-nn
git clone https://github.com/gdewael/maldi-nn.git

In Python:

from maldi_nn.spectrum import *
from maldi_nn.models import MaldiTransformer
import torch
spectrum = SpectrumObject.from_bruker(
    "./maldi-nn/assets/RKI_example/Bacillus_anthracis/acqu",
    "./maldi-nn/assets/RKI_example/Bacillus_anthracis/fid"
    )

preprocessor = SequentialPreprocessor(
    VarStabilizer(method="sqrt"),
    Smoother(halfwindow=10),
    BaselineCorrecter(method="SNIP", snip_n_iter=20),
    Trimmer(),
    PersistenceTransformer(extract_nonzero=True),
    Normalizer(sum=1),
    PeakFilter(max_number=200),
)

spectrum_preprocessed = preprocessor(spectrum)
spectrum_tensors = spectrum_preprocessed.torch()

model = MaldiTransformer.load_from_checkpoint("../../maldi-nn/assets/MaldiTransformerM.ckpt").eval().cpu()

mlm_logits, spectrum_embedding = model(spectrum_tensors)

prob_noise_peak = torch.sigmoid(mlm_logits)

Other Maldi Transformer model sizes are available at https://huggingface.co/gdewael/MaldiTransformer/tree/main.

Academic Reproducibility

This package contains all code and scripts to reproduce: "An antimicrobial drug recommender system using MALDI-TOF MS and dual-branch neural networks", and "Pre-trained Maldi Transformers improve MALDI-TOF MS-based prediction". All information regarding reproducing our results can be found in the reproduce folder README

Credits

  • Implementations of many MALDI reading and processing functions were based on the R package MaldiQuant.
  • Topological Peak Filtering was taken from the Topf package.

Citation

Antimicrobial drug recommenders:

@article{dewaele2023antimicrobial,
  title={An antimicrobial drug recommender system using MALDI-TOF MS and dual-branch neural networks},
  url={http://dx.doi.org/10.1101/2023.09.28.559916},
  DOI={10.1101/2023.09.28.559916},
  publisher={Cold Spring Harbor Laboratory},
  author={De Waele, Gaetan and Menschaert, Gerben and Waegeman, Willem},
  year={2023},
  month=sep,
}

Maldi Transformers:

@article{dewaele2024pre,
  title={Pre-trained Maldi Transformers improve MALDI-TOF MS-based prediction},
  author={De Waele, Gaetan and Menschaert, Gerben and Vandamme, Peter and Waegeman, Willem},
  journal={bioRxiv},
  pages={2024--01},
  year={2024},
  publisher={Cold Spring Harbor Laboratory}
}

Metadata

Release files for maldi-nn 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maldi-nn 0.2.5
File Size Uploaded
maldi_nn-0.2.5.tar.gz 43.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for maldi-nn 0.2.5
File Interpreter ABI Platform
maldi_nn-0.2.5-py3-none-any.whl Python 3 none any Details

Total release size: 48.9 MB

Release files / maldi_nn-0.2.5.tar.gz

Download URL maldi_nn-0.2.5.tar.gz
Size 43.0 MB
Tags Source
SHA-256 checksum
How to use checksums
14227caa673c4a7e00e1b5abe5d6c90d89afb41f1f2a1e371aedd8e49e7697c2
BLAKE2b-256 checksum
How to use checksums
f035cfd336ab1c8489c282a01b66166b093d924418ea84fc9aff86f189ee952a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.5

Release files / maldi_nn-0.2.5-py3-none-any.whl

Download URL maldi_nn-0.2.5-py3-none-any.whl
Size 5.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f2e1e68e6fe196f447ce3f630d6558dcf672d880bbad8c6ec971d63750cc5e00
BLAKE2b-256 checksum
How to use checksums
ed101c2982d0b7d47249e593bc39fb9033adc96031952ad69d2d9b673a236043
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.2.5 This release

2 release files

0.2.4

2 release files

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page