Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timsrust 0.3.0 #140

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions crates/sage-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Runner {
min_deisotope_mz.unwrap_or(0.0),
);

let bruker_extensions = [".d", ".tdf", ".tdf_bin"];
let bruker_extensions = [".d", ".tdf", ".tdf_bin", "ms2", "raw"];
let spectra = chunk
.par_iter()
.enumerate()
Expand All @@ -213,10 +213,16 @@ impl Runner {
let path_lower = path.to_lowercase();
let res = if path_lower.ends_with(".mgf.gz") || path_lower.ends_with(".mgf") {
sage_cloudpath::util::read_mgf(path, file_id)
} else if bruker_extensions
.iter()
.any(|ext| path_lower.ends_with(ext))
{
} else if bruker_extensions.iter().any(|ext| {
if path_lower.ends_with(std::path::MAIN_SEPARATOR) {
path_lower
.strip_suffix(std::path::MAIN_SEPARATOR)
.unwrap()
.ends_with(ext)
} else {
path_lower.ends_with(ext)
}
}) {
sage_cloudpath::util::read_tdf(path, file_id)
} else {
sage_cloudpath::util::read_mzml(path, file_id, sn)
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-cloudpath/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ log = "0.4.0"
once_cell = "1.0"
tokio = { version = "1.0", features = ["fs", "io-util", "rt", "macros"] }
quick-xml = { version = "0.31.0", features = ["async-tokio"] }
timsrust = "0.2.4"
timsrust = "0.3.0"
rayon = "1.5"
reqwest = { version = "0.11", features = ["json", "rustls-tls"], default-features = false }
regex = "1.6"
Expand Down
30 changes: 20 additions & 10 deletions crates/sage-cloudpath/src/tdf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use rayon::prelude::*;
use sage_core::spectrum::{Precursor, RawSpectrum, Representation};
use sage_core::{
mass::Tolerance,
spectrum::{Precursor, RawSpectrum, Representation},
};

pub struct TdfReader;

Expand All @@ -9,21 +12,28 @@ impl TdfReader {
path_name: impl AsRef<str>,
file_id: usize,
) -> Result<Vec<RawSpectrum>, timsrust::Error> {
let dda_spectra: Vec<timsrust::Spectrum> =
timsrust::FileReader::new(path_name.as_ref())?.read_all_spectra();
let spectra: Vec<RawSpectrum> = (0..dda_spectra.len())
let spectrum_reader = timsrust::io::readers::SpectrumReader::new(path_name.as_ref());
let spectra: Vec<RawSpectrum> = (0..spectrum_reader.len())
.into_par_iter()
.map(|index| {
let dda_spectrum = &dda_spectra[index];
let dda_spectrum = spectrum_reader.get(index);
let mut precursor: Precursor = Precursor::default();
let dda_precursor: timsrust::Precursor =
dda_spectrum.precursor.unwrap_as_precursor();
let dda_precursor: timsrust::ms_data::Precursor = dda_spectrum.precursor;
precursor.mz = dda_precursor.mz as f32;
precursor.charge = Option::from(dda_precursor.charge as u8);
// precursor.ion_mobility = Option::from(dda_precursor.im as f32);
precursor.intensity = Option::from(dda_precursor.intensity as f32);
precursor.charge = match dda_precursor.charge {
Some(x) => Some(x as u8),
None => None,
};
precursor.intensity = match dda_precursor.intensity {
Some(x) => Some(x as f32),
None => None,
};
precursor.spectrum_ref = Option::from(dda_precursor.frame_index.to_string());
precursor.inverse_ion_mobility = Option::from(dda_precursor.im as f32);
precursor.isolation_window = Option::from(Tolerance::Da(
-dda_spectrum.isolation_width as f32 / 2.0,
dda_spectrum.isolation_width as f32 / 2.0,
));
let spectrum: RawSpectrum = RawSpectrum {
file_id,
precursors: vec![precursor],
Expand Down
Loading