diff --git a/src/file_types.rs b/src/file_types.rs index cdcbb6e..cd51898 100644 --- a/src/file_types.rs +++ b/src/file_types.rs @@ -1,25 +1,34 @@ +use mzdata::io::MassSpectrometryFormat; + pub enum SpectrumFileType { MascotGenericFormat, MzML, + MzMLb, BrukerRaw, - // ThermoRaw, + ThermoRaw, Unknown, } pub fn match_file_type(spectrum_path: &str) -> SpectrumFileType { - let extension = spectrum_path.split('.').last().unwrap_or("").to_lowercase(); - match extension.as_str() { - "mgf" => SpectrumFileType::MascotGenericFormat, - "mzml" => SpectrumFileType::MzML, - "d" | "ms2" => SpectrumFileType::BrukerRaw, - // "raw" => SpectrumFileType::ThermoRaw, - _ => match ( - folder_contains_extension(spectrum_path, "bin"), - folder_contains_extension(spectrum_path, "parquet"), - ) { - (true, true) => SpectrumFileType::BrukerRaw, - _ => SpectrumFileType::Unknown, - }, + match mzdata::io::infer_from_path(spectrum_path).0 { + MassSpectrometryFormat::MGF => SpectrumFileType::MascotGenericFormat, + MassSpectrometryFormat::MzML => SpectrumFileType::MzML, + MassSpectrometryFormat::MzMLb => SpectrumFileType::MzMLb, + MassSpectrometryFormat::ThermoRaw => SpectrumFileType::ThermoRaw, + MassSpectrometryFormat::Unknown => { + let extension = spectrum_path.split('.').last().unwrap_or("").to_lowercase(); + match extension.as_str() { + "d" | "ms2" => SpectrumFileType::BrukerRaw, + _ => match ( + folder_contains_extension(spectrum_path, "bin"), + folder_contains_extension(spectrum_path, "parquet"), + ) { + (true, true) => SpectrumFileType::BrukerRaw, + _ => SpectrumFileType::Unknown, + }, + } + } + _ => SpectrumFileType::Unknown } } diff --git a/src/lib.rs b/src/lib.rs index f8bc25d..5b6205c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,11 +19,10 @@ pub fn get_precursor_info(spectrum_path: String) -> PyResult { + SpectrumFileType::MascotGenericFormat | SpectrumFileType::MzML | SpectrumFileType::MzMLb | SpectrumFileType:: ThermoRaw => { parse_mzdata::parse_precursor_info(&spectrum_path) } SpectrumFileType::BrukerRaw => parse_timsrust::parse_precursor_info(&spectrum_path), - // SpectrumFileType::ThermoRaw => parse_with_mzdata_thermo(&spectrum_path, file_type), SpectrumFileType::Unknown => return Err(PyOSError::new_err("Unsupported file type")), }; @@ -39,11 +38,10 @@ pub fn get_ms2_spectra(spectrum_path: String) -> PyResult { + SpectrumFileType::MascotGenericFormat | SpectrumFileType::MzML | SpectrumFileType::MzMLb | SpectrumFileType:: ThermoRaw => { 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), SpectrumFileType::Unknown => return Err(PyOSError::new_err("Unsupported file type")), };