mzdata/lib.rs
1//! `mzdata` provides basic access to raw and processed mass spectrometry data formats in
2//! Rust.
3//!
4//! For a guide, see the [tutorial] section.
5//!
6//! The library currently supports reading:
7//! 1. MGF files using [`MGFReader`] in [`mzdata::io::mgf`](crate::io::mgf)
8//! 2. mzML & indexedmzML files using [`MzMLReader`] in [`mzdata::io::mzml`](crate::io::mzml)
9//! 3. mzMLb files using [`MzMLbReader`] in [`mzdata::io::mzmlb`](crate::io::mzmlb), if the `mzmlb` feature is enabled
10//! 4. Thermo RAW files using [`ThermoRawReader`](crate::io::thermo::ThermoRawReader) in [`mzdata::io::thermo`](crate::io::thermo), if the `thermo` feature is enabled
11//!
12//! and writing:
13//! 1. MGF files using [`MGFWriter`] in [`mzdata::io::mgf`](crate::io::mgf)
14//! 2. mzML & indexedmzML files using [`MzMLWriter`] in [`mzdata::io::mzml`](crate::io::mzml)
15//! 3. mzMLb files using [`MzMLbWriter`] in [`mzdata::io::mzmlb`](crate::io::mzmlb), if the `mzmlb` feature is enabled
16//!
17//! This menagerie of different formats and gzip compression or not can be inferred from a path or [`io::Read`](std::io::Read) using [`io::infer_format`] and [`io::infer_from_stream`].
18//! Conventional dispatch is possible through [`MZReader`]. The [`mz_read`] macro provides a convenient means of working with
19//! a value with zero added overhead, but with a limited scope. The [`mz_write`] macro is the equivalent for opening a writer.
20//! There are additional tools for dealing with file format dispatch in [`MassSpectrometryReadWriteProcess`](crate::io::MassSpectrometryReadWriteProcess).
21//!
22//! It also includes a set of representation layers for spectra in [`mzdata::spectrum`](crate::spectrum)
23//!
24//! # Example
25//! ```rust
26//! use std::fs;
27//! use mzdata::prelude::*;
28//! use mzpeaks::Tolerance;
29//! use mzdata::MZReader;
30//! use mzdata::spectrum::SignalContinuity;
31//!
32//! let reader = MZReader::open_path("./test/data/small.mzML").unwrap();
33//! for spectrum in reader {
34//! println!("Scan {} => BP {}", spectrum.id(), spectrum.peaks().base_peak().mz);
35//!
36//! if spectrum.signal_continuity() == SignalContinuity::Centroid {
37//! let peak_picked = spectrum.into_centroid().unwrap();
38//! println!("Matches for 579.155: {:?}",
39//! peak_picked.peaks.all_peaks_for(
40//! 579.155, Tolerance::Da(0.02)
41//! )
42//! );
43//! }
44//! }
45//! ```
46//!
47//! It uses [`mzpeaks`] to represent peaks and peak lists, and re-exports the basic types. While the high-level
48//! types are templated on simple peak types, more complex, application-specific peak types can be substituted.
49//! See [`mzdata::spectrum::bindata`](crate::spectrum::bindata) for more information about how to directly convert
50//! data arrays to peak lists.
51//!
52//!
53//! ## Traits
54//! The library makes heavy use of traits to abstract over the implementation details of different file formats.
55//! These traits are included in [`mzdata::prelude`](crate::prelude). It also imports [`mzpeaks::prelude`].
56//!
57//!
58pub mod io;
59pub mod meta;
60#[macro_use]
61pub mod params;
62pub mod prelude;
63pub mod spectrum;
64pub mod utils;
65
66pub use crate::io::{MZReader, MZReaderBuilder};
67#[cfg(feature = "mgf")]
68pub use crate::io::mgf::{MGFReader, MGFWriter};
69#[cfg(feature = "mzml")]
70pub use crate::io::mzml::{MzMLReader, MzMLWriter};
71
72#[cfg(feature = "mzmlb")]
73pub use crate::io::mzmlb::{
74 MzMLbReader, MzMLbWriter, MzMLbWriterBuilder,
75};
76
77#[cfg(feature = "thermo")]
78pub use crate::io::thermo::ThermoRawReader;
79
80pub use crate::params::{Param, ParamList};
81
82pub use crate::spectrum::{CentroidSpectrum, RawSpectrum, Spectrum};
83
84#[cfg(doc)]
85pub mod tutorial;
86
87pub use mzpeaks;
88
89#[cfg(feature = "mzsignal")]
90pub use mzsignal;