https://github.com/rformassspectrometry/spectripy
Interfacing R's Spectra package with the Python world.
https://github.com/rformassspectrometry/spectripy
infrastructure mass-spectrometry python rstats
Last synced: 6 months ago
JSON representation
Interfacing R's Spectra package with the Python world.
- Host: GitHub
- URL: https://github.com/rformassspectrometry/spectripy
- Owner: rformassspectrometry
- License: artistic-2.0
- Created: 2022-02-25T09:06:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-07T14:42:28.000Z (6 months ago)
- Last Synced: 2025-04-14T22:52:22.837Z (6 months ago)
- Topics: infrastructure, mass-spectrometry, python, rstats
- Language: R
- Homepage: https://rformassspectrometry.github.io/SpectriPy/
- Size: 5.81 MB
- Stars: 11
- Watchers: 5
- Forks: 7
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
# Integrating [*Spectra*](https://github.com/RforMassSpectrometry/Spectra) with Python's *matchms* library
[](https://www.repostatus.org/#active)
[](https://github.com/RforMassSpectrometry/SpectriPy/actions?query=workflow%3AR-CMD-check-bioc)
[](https://codecov.io/gh/rformassspectrometry/SpectriPy)
[](https://opensource.org/licenses/Artistic-2.0)
[](https://joss.theoj.org/papers/58765b0ffd655f01192ba3660b35900f)
The *SpectriPy* package allows integration of Python MS packages into a
[*Spectra*](https://github.com/RforMassSpectrometry/Spectra)-based MS analysis
in R. By wrapping Python functionality into R functions, *SpectriPy* allows a
seamless integration of Python libraries into R. For example, *SpectriPy* can
leverage the spectral similarity, filtering, normalization etc. calculations
from the Python [*matchms*](https://github.com/matchms/) library and contains
functions to convert between R's `Spectra::Spectra` objects and Python's
`matchms.Spectrum` and `spectrum_utils.spectrum.MsmsSpectrum` objects. R and
Python spectral objects are easily translated and available in one workflow
(i.e. a quarto document), enabling the advanced user or developer to create
custom functions or workflows on `Spectra` objects in Python and executing
them in R using the *reticulate* R package, and vice versa.If you use *SpectriPy* in your research, please cite:
_SpectriPy: Enhancing Cross-Language Mass Spectrometry Data Analysis with R and
Python. IN PREPARATION._# Installation
Detailed information on the [installation and configuration of SpectriPy](detailed-installation-configuration.qmd),
including guidelines for first time R users can be found under the "vignettes".TLDR:
- Prerequisites: R >= 4.4.0.
- System requirement: *reticulate* (i.e., setup Python environment if not
already available)```r
#' R session:install.packages("reticulate")
reticulate::install_miniconda()
```- Package requirements: Bioconductor's *BiocManager*, *remotes*
```r
#' R session:if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install(version = "3.20")install.packages("remotes")
```- Package: *SpectriPy*
```r
#' R session:BiocManager::install("RforMassSpectrometry/SpectriPy")
```# Documentation for users
See the extensive documentation for the use of *SpectriPy*:
- The rendered [SpectriPy package’s vignette](https://rformassspectrometry.github.io/SpectriPy/articles/SpectriPy.html),
- The code of the [SpectriPy vignette](vignettes/SpectriPy.qmd),
- A [tutorial](vignettes/SpectriPy_tutorial.qmd) for the annotation of LC-MS/MS
spectra using an MGF library and the CosineGreedy algorithm from *matchms*.TLDR:
```r
#' R session:library(Spectra)
library(SpectriPy)
```## Example: Spectra similarity calculations using `matchms`
The *SpectriPy* package provides the `compareSpectriPy()` function that allows
to perform spectra similarity calculations using the scoring functions from MS
Python packages. For example, the [*CosineGreedy*](https://matchms.readthedocs.io/en/latest/api/matchms.similarity.CosineGreedy.html) parameter `CosineGreedyParam` from the
*matchms* Python package.1) We create some simple example spectra.
```r
#' R session:library(Spectra)
library(SpectriPy)#' Create a Spectra object with two MS2 spectra for Caffeine.
caf <- DataFrame(
msLevel = c(2L, 2L),
name = "Caffeine",
precursorMz = c(195.0877, 195.0877)
)
caf$intensity <- list(
c(340.0, 416, 2580, 412),
c(388.0, 3270, 85, 54, 10111))
caf$mz <- list(
c(135.0432, 138.0632, 163.0375, 195.0880),
c(110.0710, 138.0655, 138.1057, 138.1742, 195.0864))
caf <- Spectra(caf)#' Create a Spectra object with two MS2 spectra for 1-Methylhistidine
mhd <- DataFrame(
msLevel = c(2L, 2L),
precursorMz = c(170.0924, 170.0924),
id = c("HMDB0000001", "HMDB0000001"),
name = c("1-Methylhistidine", "1-Methylhistidine"))
mhd$mz <- list(
c(109.2, 124.2, 124.5, 170.16, 170.52),
c(83.1, 96.12, 97.14, 109.14, 124.08, 125.1, 170.16))
mhd$intensity <- list(
c(3.407, 47.494, 3.094, 100.0, 13.240),
c(6.685, 4.381, 3.022, 16.708, 100.0, 4.565, 40.643))
mhd <- Spectra(mhd)
```2) We calculate pairwise similarities between all spectra defined above and
those of caffeine using *Spectra*'s built-in `compareSpectra()` function.```r
#' R session:all <- c(caf, mhd)
res_r <- compareSpectra(all, caf)
res_r
```3) We calculate the similarity using the *CosineGreedy* function from *matchms*,
changing the `tolerance` to a value of `0.05` (instead of the default `0.1`).```r
#' R session:res <- compareSpectriPy(all, caf, param = CosineGreedy(tolerance = 0.05))
res
```As a result `compareSpectriPy()` returns also a numeric matrix of similarities.
Note also that the first `compareSpectriPy()` call takes usually a little longer
because the Python setup has to be initialized.# Documentation for developers
See the [developer notes](devnotes.md).
## Contributions
Contributions are highly welcome and should follow the [contribution
guidelines](https://rformassspectrometry.github.io/RforMassSpectrometry/articles/RforMassSpectrometry.html#contributions).
General information on the package structure and some helpful pointers are given
in the [developer notes](devnotes.md) document. Also, please check the
[coding style
guidelines](https://rformassspectrometry.github.io/RforMassSpectrometry/articles/RforMassSpectrometry.html#coding-style)
and importantly, follow our [code of
conduct](https://rformassspectrometry.github.io/RforMassSpectrometry/articles/RforMassSpectrometry.html#code-of-conduct).# License
See the [DESCRIPTION](DESCRIPTION) and [LICENSE](LICENSE) file.