Metabodecon is a work-in-progress project that provides functionality for handling and processing 1D NMR spectra. A more limited version of this was already implemented in R here. This project aims to improve on that by providing a more efficient and flexible implementation in Rust as well as additional features that are not present in the R version.
Current planned and implemented features include (additional suggestions are welcome as issues):
- Efficient representation of 1D NMR spectra
- Read 1D NMR spectra from various formats
- Internal HDF5 format
- Bruker
- JCAMP-DX
- Storing 1D NMR spectra in HDF5 files which are easier to handle and share than the raw data formats
- Preprocessing of 1D NMR spectra
- Removal of the solvent signal
- Smoothing of the signal intensities (various methods)
- Peak detection in 1D NMR spectra
- Curvature analysis
- Fitting of peaks to deconvolute 1D NMR spectra
- Lorentzian functions
- Analytical solution to the system of equations for the Lorentzian parameters using the detected peaks
- Lorentzian functions
- Alignment of 1D NMR spectra using the deconvoluted signals
- Python bindings
- Basic bindings
- Complete Python package
- R bindings
- Basic bindings
- Complete R package
- Command line interface for the core crate
- Graphical user interface for the core crate
For now, the project is in a very early stage. However, you can already include the library crate in your own project by
adding the following to your Cargo.toml
:
[dependencies]
metabodecon = { git = "https://github.com/SombkeMaximilian/metabodecon-rust" }
To install the Python bindings, follow these steps:
-
activate your virtual environment
-
install the
maturin
package usingpip install maturin
-
navigate to the
metabodecon-python
crate and run the following command:maturin develop --release
Here is a simple example of how to use the library in Rust:
use metabodecon::{deconvolution, spectrum};
fn main() {
// Read a spectrum from Bruker TopSpin format
let mut spectrum = spectrum::BrukerReader.read_spectrum(
"path/to/spectrum",
// Experiment Number
10,
// Processing Number
10,
// Signal Region
(-2.208611, 11.807918)
).unwrap();
// Deconvoluter with default options
let deconvoluter: deconvolution::Deconvoluter = Default::default();
// Deconvolute the spectrum
let deconvoluted_spectrum = deconvoluter.deconvolute_spectrum(&mut spectrum).unwrap();
// WIP for now
}
Here is a simple example of how to use the library in Python:
import matplotlib.pyplot as plt
import metabodecon as md
# Read a spectrum from Bruker TopSpin format
spectrum = md.Spectrum.from_bruker(
"path/to/spectrum",
# Experiment Number
10,
# Processing Number
10,
# Signal Region
(-2.208611, 11.807918)
)
# Deconvoluter with default options
deconvoluter = md.Deconvoluter()
# Deconvolute the spectrum
deconvolution = deconvoluter.deconvolute_spectrum(spectrum)
# Extract the chemical shifts, intensities, and signal boundaries
x = spectrum.chemical_shifts
y1 = spectrum.intensities_raw
s = spectrum.signal_boundaries
# Compute the superposition of the deconvoluted peaks
y2 = deconvolution.par_superposition_vec(spectrum.chemical_shifts)
# Plot the spectrum with overlayed deconvoluted signal superposition
plt.figure(figsize = (12, 8), dpi = 300)
plt.plot(x, y1, label = "Original Spectrum")
plt.plot(x, y2, label = "Deconvoluted Spectrum", linewidth=0.5)
plt.gca().invert_xaxis()
plt.axvline(x = s[0], color = "black", label = "Signal Boundaries")
plt.axvline(x = s[1], color = "black")
plt.xlabel("Chemical Shifts", fontsize = 16)
plt.ylabel("Intensity", fontsize = 16)
plt.xticks(fontsize = 14)
plt.yticks(fontsize = 14)
plt.legend()
plt.show()
Here is a simple example of how to use the library in R:
# WIP
Run tests:
cargo test
Run benchmarks:
cargo bench
Currently not accepting contributions, as this is part of my thesis. However, feel free to use it and open issues for suggestions and bug reports. I will get back to them after my thesis is done.
- Hyung-Won Koh et al. “An approach to automated frequency-domain feature extraction in nuclear magnetic resonance spectroscopy”. [DOI] [ScienceDirect]
- Martina Häckl et al. “An R-Package for the Deconvolution and Integration of 1D NMR Data: MetaboDecon1D”. [DOI] [MDPI]
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the GPL-3.0 license, shall be licensed as GPL-3.0, without any additional terms or conditions.