Skip to content

Commit

Permalink
use mz_read to read mgfs and mzmls
Browse files Browse the repository at this point in the history
This add support for gziped files, without the need for us to implement
it.
  • Loading branch information
paretje committed Aug 13, 2024
1 parent 5c3dce4 commit a22de42
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ crate-type = ["cdylib"]
pyo3 = "0.20.0"
mzdata = "0.20.0"
timsrust = "0.3.0"
mzpeaks = "0.17.0"
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn get_ms2_spectra(spectrum_path: String) -> PyResult<Vec<ms2_spectrum::MS2S

let spectra = match file_type {
SpectrumFileType::MascotGenericFormat | SpectrumFileType::MzML => {
parse_mzdata::read_ms2_spectra(&spectrum_path, file_type)
parse_mzdata::read_ms2_spectra(&spectrum_path)
}
SpectrumFileType::BrukerRaw => parse_timsrust::read_ms2_spectra(&spectrum_path),
// SpectrumFileType::ThermoRaw => parse_with_mzdata_thermo(&spectrum_path, file_type),
Expand Down
21 changes: 5 additions & 16 deletions src/parse_mzdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fs::File;

use mzdata::io::{MGFReader, MzMLReader};
use mzdata::params::ParamValue;
use mzdata::mz_read;

use crate::file_types::SpectrumFileType;
use crate::ms2_spectrum::MS2Spectrum;
Expand Down Expand Up @@ -81,24 +82,12 @@ pub fn parse_precursor_info(
/// Read MS2 spectra from spectrum files with mzdata
pub fn read_ms2_spectra(
spectrum_path: &str,
file_type: SpectrumFileType,
) -> Result<Vec<MS2Spectrum>, std::io::Error> {
let file = File::open(spectrum_path)?;
match file_type {
SpectrumFileType::MascotGenericFormat => Ok(MGFReader::new(file)
.map(MS2Spectrum::from)
.collect::<Vec<MS2Spectrum>>()),

SpectrumFileType::MzML => Ok(MzMLReader::new(file)
.filter(|spectrum| spectrum.description.ms_level == 2)
mz_read!(spectrum_path.as_ref(), reader => {
reader.filter(|spectrum| spectrum.description.ms_level == 2)
.map(MS2Spectrum::from)
.collect::<Vec<MS2Spectrum>>()),

_ => Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Unsupported file type for mzdata",
)),
}
.collect::<Vec<MS2Spectrum>>()
})
}

// pub fn parse_precursor_info_thermo(
Expand Down

0 comments on commit a22de42

Please sign in to comment.