# MaldiAMRKit
<p align="center">
<img src="docs/maldiamrkit.png" alt="MaldiAMRKit" width="250"/>
</p>
<p align="center">
<strong>Toolkit to read and preprocess MALDI-TOF mass-spectra for AMR analyses</strong>
</p>
## 🚀 Installation
```bash
pip install maldiamrkit
```
## 🏃 Quick Start
```python
from maldiamrkit.spectrum import MaldiSpectrum
from maldiamrkit.dataset import MaldiSet
from maldiamrkit.peak_detector import MaldiPeakDetector
# Load and preprocess a single spectrum
spec = MaldiSpectrum("data/1s.txt").preprocess() # smoothing, baseline removal, normalisation
spec.bin(3) # [optional] bin width 3 Da
spec.plot(binned=True) # plot
# Build a dataset from a directory of spectra + metadata CSV
data = MaldiSet.from_directory(
"data/", "data/metadata/metadata.csv",
aggregate_by=dict(antibiotic="Drug"),
bin_width=3
)
X, y = data.X, data.y["Drug"]
# Machine learning pipeline
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
pipe = Pipeline([
("peaks", MaldiPeakDetector(binary=False, prominence=0.05)),
("scaler", StandardScaler()),
("clf", LogisticRegression(max_iter=500))
])
pipe.fit(X, y)
```
For further details please see the [quick guide](docs/quick_guide.ipynb).
## 🤝 Contributing
Pull requests, bug reports, and feature ideas are welcome: feel free to open a PR!
## 📝 License
This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.
## 🙏 Acknowledgements
This pipeline is based on the methodology described in the following publication and aims to facilitate the application of similar approaches on MALDI-TOF spectra for AMR prediction in a machine learning context:
> **Weis, C., Cuénod, A., Rieck, B., et al.** (2022). *Direct antimicrobial resistance prediction from clinical MALDI-TOF mass spectra using machine learning*. **Nature Medicine**, 28, 164–174. [https://doi.org/10.1038/s41591-021-01619-9](https://doi.org/10.1038/s41591-021-01619-9)
Please consider citing this work if you find `MaldiAMRKit` useful.
Raw data
{
"_id": null,
"home_page": null,
"name": "MaldiAMRKit",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "MALDI, mass-spectrometry, machine-learning, scikit-learn",
"author": null,
"author_email": "Ettore Rocchi <ettoreroc@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a0/ae/014286f1877a6d2d9859775c98de636c025002c435774603fc3b7fa58ae2/maldiamrkit-0.2.2.tar.gz",
"platform": null,
"description": "# MaldiAMRKit\n\n<p align=\"center\">\n <img src=\"docs/maldiamrkit.png\" alt=\"MaldiAMRKit\" width=\"250\"/>\n</p>\n<p align=\"center\">\n <strong>Toolkit to read and preprocess MALDI-TOF mass-spectra for AMR analyses</strong>\n</p>\n\n## \ud83d\ude80\u00a0Installation\n\n```bash\npip install maldiamrkit\n```\n\n## \ud83c\udfc3\u00a0Quick Start\n\n```python\nfrom maldiamrkit.spectrum import MaldiSpectrum\nfrom maldiamrkit.dataset import MaldiSet\nfrom maldiamrkit.peak_detector import MaldiPeakDetector\n\n# Load and preprocess a single spectrum\nspec = MaldiSpectrum(\"data/1s.txt\").preprocess() # smoothing, baseline removal, normalisation\nspec.bin(3) # [optional]\u00a0bin width 3 Da\nspec.plot(binned=True) # plot\n\n# Build a dataset from a directory of spectra + metadata CSV\ndata = MaldiSet.from_directory(\n \"data/\", \"data/metadata/metadata.csv\",\n aggregate_by=dict(antibiotic=\"Drug\"),\n bin_width=3\n)\nX, y = data.X, data.y[\"Drug\"]\n\n# Machine learning pipeline\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.linear_model import LogisticRegression\n\npipe = Pipeline([\n (\"peaks\", MaldiPeakDetector(binary=False, prominence=0.05)),\n (\"scaler\", StandardScaler()),\n (\"clf\", LogisticRegression(max_iter=500))\n])\npipe.fit(X, y)\n```\nFor further details please see the [quick guide](docs/quick_guide.ipynb).\n\n## \ud83e\udd1d Contributing\n\nPull requests, bug reports, and feature ideas are welcome: feel free to open a PR!\n\n## \ud83d\udcdd\u00a0License\n\nThis project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.\n\n## \ud83d\ude4f Acknowledgements\n\nThis pipeline is based on the methodology described in the following publication and aims to facilitate the application of similar approaches on MALDI-TOF spectra for AMR prediction in a machine learning context:\n\n> **Weis, C., Cu\u00e9nod, A., Rieck, B., et al.** (2022). *Direct antimicrobial resistance prediction from clinical MALDI-TOF mass spectra using machine learning*. **Nature Medicine**, 28, 164\u2013174. [https://doi.org/10.1038/s41591-021-01619-9](https://doi.org/10.1038/s41591-021-01619-9)\n\nPlease consider citing this work if you find `MaldiAMRKit` useful.\n",
"bugtrack_url": null,
"license": null,
"summary": "Toolkit to read and preprocess MALDI-TOF mass-spectra for AMR analyses.",
"version": "0.2.2",
"project_urls": {
"Documentation": "https://github.com/EttoreRocchi/MaldiAMRKit#readme",
"Homepage": "https://github.com/EttoreRocchi/MaldiAMRKit",
"Issues": "https://github.com/EttoreRocchi/MaldiAMRKit/issues",
"Source": "https://github.com/EttoreRocchi/MaldiAMRKit"
},
"split_keywords": [
"maldi",
" mass-spectrometry",
" machine-learning",
" scikit-learn"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "079536cc51c0beccd23fad2d884c27391174acc88c0818e239ca811b107f1d2c",
"md5": "559f202e3342a42f0fb76dca399a0c25",
"sha256": "d1d72d5ba4223693df6d079f265fbd1a8af21d17fba5d9c797acd494cfdbb467"
},
"downloads": -1,
"filename": "maldiamrkit-0.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "559f202e3342a42f0fb76dca399a0c25",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10854,
"upload_time": "2025-07-22T12:44:39",
"upload_time_iso_8601": "2025-07-22T12:44:39.857778Z",
"url": "https://files.pythonhosted.org/packages/07/95/36cc51c0beccd23fad2d884c27391174acc88c0818e239ca811b107f1d2c/maldiamrkit-0.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a0ae014286f1877a6d2d9859775c98de636c025002c435774603fc3b7fa58ae2",
"md5": "c0fa52ed647f2f5cd67150c96f86c899",
"sha256": "159ab8f0bfe131d0e2e6201c43adb05a055fd21f264d777e115cb18cff19556e"
},
"downloads": -1,
"filename": "maldiamrkit-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "c0fa52ed647f2f5cd67150c96f86c899",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 9319,
"upload_time": "2025-07-22T12:44:40",
"upload_time_iso_8601": "2025-07-22T12:44:40.872339Z",
"url": "https://files.pythonhosted.org/packages/a0/ae/014286f1877a6d2d9859775c98de636c025002c435774603fc3b7fa58ae2/maldiamrkit-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-22 12:44:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "EttoreRocchi",
"github_project": "MaldiAMRKit#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "maldiamrkit"
}