Use when you have a mature R analysis pipeline (e.g., using Spectra objects
Scanned 9/12/2026
Install to Claude Code
npx -y skills add HolobiomicsLab/asb-skill-collections --skill cross-language-interface-implementation --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Cross Language Interface Implementation?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/holobiomicslab-cross-language-interface-implementation)More formats (shields.io, HTML) on the badges page.
---
name: cross-language-interface-implementation
description: Use when you have a mature R analysis pipeline (e.g., using Spectra objects
for MS data) but need access to specialized algorithms or calculations available
only in Python libraries (e.g., CosineGreedy similarity from matchms).
license: CC-BY-4.0
metadata:
edam_operation: http://edamontology.org/operation_3357
edam_topics:
- http://edamontology.org/topic_3520
- http://edamontology.org/topic_0091
tools:
- SpectriPy
- R
- reticulate
- Spectra
- matchms
- spectrum_utils
techniques:
- LC-MS
license_tier: open
provenance_tier: literature
derived_from:
- doi: 10.21105/joss.08070
title: spectripy
evidence_spans:
- The *SpectriPy* package allows integration of Python MS packages into a [*Spectra*](https://github.com/RforMassSpectrometry/Spectra)-based
MS analysis in R
- MS analysis in R. By wrapping Python functionality into R functions, *SpectriPy*
allows a seamless integration of Python libraries into R
claims: []
provenance:
collection: https://w3id.org/holobiomicslab/asb-skill/collection/metabolomics/v2
assembled_by: scripts/collect_metabolomics_collection.py
sources:
- build: coll_spectripy_cq
doi: 10.21105/joss.08070
title: spectripy
dedup_kept_from: coll_spectripy_cq
schema_version: 0.2.0
attribution:
generator: AgenticScienceBuilder
original_doi: 10.21105/joss.08070
all_source_dois:
- 10.21105/joss.08070
zenodo_doi: 10.5281/zenodo.20794027
curators: []
promoter: Louis-Félix Nothias
sponsor: CNRS & Université Côte d'Azur
---
# cross-language-interface-implementation
## Summary
Design and implement a bidirectional wrapping layer that serializes domain objects between R and Python environments, allowing R-based workflows to call Python libraries and vice versa while preserving object structure and metadata. This skill enables seamless integration of specialized Python mass spectrometry packages (e.g., matchms, spectrum_utils) into R-centric Spectra-based analysis pipelines.
## When to use
You have a mature R analysis pipeline (e.g., using Spectra objects for MS data) but need access to specialized algorithms or calculations available only in Python libraries (e.g., CosineGreedy similarity from matchms). You want to avoid reimplementing those algorithms in R and prefer a lightweight bridge that preserves round-trip fidelity of spectral objects.
## When NOT to use
- The target algorithm or calculation already exists in mature R packages (e.g., Spectra::compareSpectra); rewriting in R is simpler than cross-language glue.
- Python environment setup is blocked (e.g., system Python unavailable, conda/virtualenv unreachable, or user lacks permission to install packages).
- Latency or throughput demands are extreme: cross-language calls incur serialization overhead; batch processing within Python or R alone may be faster.
## Inputs
- R Spectra object (S4 object containing MS/MS spectra with peaks, precursor m/z, intensity, and metadata)
- Python library specification (package name, version)
- Target Python function signature or class method
## Outputs
- R Spectra object (restored from Python computation, with all original attributes preserved)
- Numeric matrix or scalar result (similarity scores, fragment matches, or processed spectra metrics)
## How to apply
Establish a cross-language interface using the reticulate R package to (1) define wrapper R functions that accept domain objects (e.g., Spectra) as input; (2) serialize those objects into Python-compatible formats (e.g., matchms.Spectrum or spectrum_utils.spectrum.MsmsSpectrum); (3) invoke the target Python routine on the serialized data; (4) deserialize the result back into the source domain object type; and (5) validate that returned objects preserve expected metadata and peak attributes. Key parameters: use py_require() for automatic Python dependency resolution (reticulate ≥ 1.41), ensure Python ≥ 3.12 is available, and specify Python library versions (e.g., matchms 0.31, spectrum_utils 0.3.2, numpy 2.2.0). The rationale is that object serialization and validation reduce friction and error-prone manual conversions, while dependency management via reticulate reduces installation friction for end users.
## Related tools
- **reticulate** (Provides the R–Python bridge and automatic Python environment setup via py_require(); responsible for object serialization, function invocation, and exception handling.) — https://rstudio.github.io/reticulate
- **SpectriPy** (Implements wrapper functions (e.g., compareSpectriPy) that apply this cross-language pattern to MS similarity metrics; encodes serialization logic for Spectra ↔ matchms.Spectrum conversions.) — https://github.com/RforMassSpectrometry/SpectriPy
- **Spectra** (Provides the domain object model (S4 Spectra class) that serves as the input/output format and target for round-trip serialization.) — https://github.com/RforMassSpectrometry/Spectra
- **matchms** (Python library containing specialized MS similarity algorithms (CosineGreedy, etc.) that are wrapped and called from R via SpectriPy.) — https://github.com/matchms
- **spectrum_utils** (Python library providing MS spectrum preprocessing and normalization routines (spectrum_utils.spectrum.MsmsSpectrum class) integrated via SpectriPy.) — https://github.com/bittremieux-lab/spectrum_utils
## Examples
```
library(Spectra)
library(SpectriPy)
all <- c(caf, mhd)
res <- compareSpectriPy(all, caf, param = CosineGreedy(tolerance = 0.05))
```
## Evaluation signals
- Returned R Spectra object passes schema validation: all peaks (m/z and intensity vectors), precursor m/z, and metadata fields are present and have correct types and dimensions.
- Round-trip fidelity: serializing an R Spectra → Python object → R Spectra yields results identical (or within machine epsilon) to the original Spectra object.
- Python function executes without exception and produces output matching documented behavior (e.g., similarity scores in [0, 1] range for cosine similarity).
- No information loss: metadata attributes (e.g., spectrum IDs, adduct annotations, retention time) survive serialization and deserialization cycles.
- Cross-validated results: output from compareSpectriPy (Python-backed) closely matches reference R implementation or gold-standard scores (if available).
## Limitations
- Python environment must be installed and discoverable on the system; reticulate uses RETICULATE_PYTHON or RETICULATE_PYTHON_ENV environment variables to locate it. If these are set, all Python dependencies must be installed manually, else reticulate will not auto-install them.
- Requires Python ≥ 3.12; older Python versions will fail dependency resolution or runtime checks.
- First cross-language call incurs initialization overhead (Python startup, module loading); subsequent calls are faster but not negligible for high-throughput workflows.
- Serialization overhead: large Spectra objects or repeated serialization in tight loops may become a bottleneck; batch processing in Python is preferred for large datasets.
- No changelog or version tracking documented in the current README, limiting reproducibility and version-specific debugging if bugs or behavioral changes occur.
## Evidence
- [readme] By wrapping Python functionality into R functions, *SpectriPy* allows a seamless integration of Python libraries into R: "By wrapping Python functionality into R functions, *SpectriPy* allows a seamless integration of Python libraries into R"
- [other] SpectriPy integrates Python MS packages into R by wrapping Python functionality into R functions, enabling the use of Python libraries within a Spectra-based MS analysis workflow in R.: "SpectriPy integrates Python MS packages into R by wrapping Python functionality into R functions, enabling the use of Python libraries within a Spectra-based MS analysis workflow in R"
- [readme] contains functions to convert between R's `Spectra::Spectra` objects and `matchms.Spectrum` and `spectrum_utils.spectrum.MsmsSpectrum` objects from the Python *matchms* and *spectrum_utils* libraries: "contains functions to convert between R's `Spectra::Spectra` objects and `matchms.Spectrum` and `spectrum_utils.spectrum.MsmsSpectrum` objects"
- [readme] *SpectriPy*'s Python library management uses the `py_require()` function introduced in *reticulate* version 1.41 and should hence work on most system without problems.: "*SpectriPy*'s Python library management uses the `py_require()` function introduced in *reticulate* version 1.41"
- [other] Serialize the Spectra object and pass it to a Python MS package routine. Execute the Python routine on the passed data. Deserialize the result and return it as a Spectra object to the R environment.: "Serialize the Spectra object and pass it to a Python MS package routine. Execute the Python routine on the passed data. Deserialize the result and return it as a Spectra object"
- [readme] If any of these environment variables are defined, all Python libraries listed below **must** be installed, since *SpectriPy* (respectively *reticulate*) will not try to install them automatically.: "If any of these environment variables are defined, all Python libraries listed below **must** be installed, since *SpectriPy* will not try to install them automatically"
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!