Skip to content
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
21 changes: 11 additions & 10 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
]

[workspace.package]
version = "0.25.0"
version = "0.26.0"
edition = "2024"
authors = ["Sebastian Paez"]
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "timsseek-workspace"
version = "0.25.0"
version = "0.26.0"
requires-python = ">=3.11,<3.13"
dependencies = [
"jupyter[python]>=1.1.1",
Expand Down Expand Up @@ -55,7 +55,7 @@ packages = [
]

[tool.bumpver]
current_version = "0.25.0"
current_version = "0.26.0"
version_pattern = "MAJOR.MINOR.PATCH[-PYTAGNUM]"
tag_message = "v{new_version}"
commit_message = "chore: bump version to {new_version}"
Expand Down
2 changes: 1 addition & 1 deletion python/speclib_builder/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "speclib_builder"
version = "0.25.0"
version = "0.26.0"
requires-python = ">=3.11,<3.13"
dependencies = [
"rich",
Expand Down
2 changes: 1 addition & 1 deletion python/timsseek_rescore/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "timsseek_rescore"
version = "0.25.0"
version = "0.26.0"
requires-python = ">=3.11,<3.13"
dependencies = [
"polars",
Expand Down
2 changes: 1 addition & 1 deletion python/timsseek_rts_receiver/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "timsseek_rts_receiver"
version = "0.25.0"
version = "0.26.0"
requires-python = ">=3.11,<3.13"
description = "Add your description here"
dependencies = [
Expand Down
1 change: 1 addition & 0 deletions rust/timsquery/src/models/aggregators/spectrum_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ impl Add for MzMobilityStatsCollector {
}
}
}

52 changes: 52 additions & 0 deletions rust/timsquery/src/models/indexed_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

use crate::models::aggregators::{
ChromatogramCollector,
MzMobilityStatsCollector,
PointIntensityAggregator,
SpectralCollector,
};
Expand Down Expand Up @@ -453,3 +454,54 @@ impl<FH: KeyLike> QueriableData<ChromatogramCollector<FH, f32>> for IndexedPeaks
}
}
}

impl<FH: KeyLike> QueriableData<SpectralCollector<FH, MzMobilityStatsCollector>> for IndexedPeaksHandle {
fn add_query(
&self,
aggregator: &mut SpectralCollector<FH, MzMobilityStatsCollector>,
tolerance: &Tolerance,
) {
match self {
IndexedPeaksHandle::Eager(eager) => eager.add_query(aggregator, tolerance),
IndexedPeaksHandle::Lazy(lazy) => {
let ranges = QueryRanges::from_elution_group(aggregator, tolerance, |rt| {
lazy.rt_ms_to_cycle_index(rt)
});

let cycle_range_u32 = match ranges.ms1_cycle_range {
Restricted(x) => Restricted(
TupleRange::try_new(x.start().as_u32(), x.end().as_u32()).unwrap(),
),
Unrestricted => Unrestricted,
};

aggregator
.iter_mut_precursors()
.for_each(|((_idx, mz), ion)| {
let mz_range = tolerance.mz_range_f32(mz as f32);
lazy.query_peaks_ms1(mz_range, cycle_range_u32, ranges.im_range)
.for_each(|peak| {
*ion += peak;
});
});

aggregator
.iter_mut_fragments()
.for_each(|((_idx, mz), ion)| {
let mz_range = tolerance.mz_range_f32(*mz as f32);
let results = lazy.query_peaks_ms2(
ranges.quad_range,
mz_range,
cycle_range_u32,
ranges.im_range,
);
for (_isolation_scheme, peaks) in results {
for peak in peaks {
*ion += peak;
}
}
});
}
}
}
}
17 changes: 17 additions & 0 deletions rust/timsquery/src/models/tolerance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,21 @@ impl Tolerance {
..self
}
}

/// Scale the mobility tolerance by `factor` (e.g. 2.0 to double the window).
pub fn with_wider_mobility(self, factor: f32) -> Self {
let wider = match self.mobility {
MobilityTolerance::Absolute((low, high)) => {
MobilityTolerance::Absolute((low * factor, high * factor))
}
MobilityTolerance::Pct((low, high)) => {
MobilityTolerance::Pct((low * factor, high * factor))
}
MobilityTolerance::Unrestricted => MobilityTolerance::Unrestricted,
};
Self {
mobility: wider,
..self
}
}
}
40 changes: 40 additions & 0 deletions rust/timsquery/src/serde/library_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ use super::elution_group_inputs::{
ElutionGroupInput,
ElutionGroupInputError,
};
pub use super::spectronaut_io::SpectronautPrecursorExtras;
use super::spectronaut_io::{
read_library_file as read_spectronaut_tsv,
sniff_spectronaut_library_file,
};
use crate::TimsElutionGroup;
use crate::ion::IonAnnot;
use std::path::Path;
Expand Down Expand Up @@ -40,6 +45,7 @@ impl From<ElutionGroupInputError> for LibraryReadingError {
#[derive(Debug)]
pub enum FileReadingExtras {
Diann(Vec<DiannPrecursorExtras>),
Spectronaut(Vec<SpectronautPrecursorExtras>),
}

#[derive(Debug)]
Expand Down Expand Up @@ -187,14 +193,48 @@ impl ElutionGroupCollection {

Err(LibraryReadingError::UnableToParseElutionGroups)
}

fn try_read_spectronaut(path: &Path) -> Result<Self, LibraryReadingError> {
match sniff_spectronaut_library_file(path) {
Ok(()) => {
info!("Detected Spectronaut TSV library file");
let egs = match read_spectronaut_tsv(path) {
Ok(egs) => egs,
Err(e) => {
warn!("Failed to read Spectronaut TSV library file: {:?}", e);
return Err(LibraryReadingError::UnableToParseElutionGroups);
}
};
let (egs, extras): (Vec<_>, Vec<_>) = egs.into_iter().unzip();
info!("Successfully read Spectronaut TSV library file");
Ok(ElutionGroupCollection::MzpafLabels(
egs,
Some(FileReadingExtras::Spectronaut(extras)),
))
}
Err(e) => {
debug!("File is not Spectronaut format: {:?}", e);
Err(LibraryReadingError::UnableToParseElutionGroups)
}
}
}
}

pub fn read_library_file<T: AsRef<Path>>(
path: T,
) -> Result<ElutionGroupCollection, LibraryReadingError> {
// Try DIA-NN first
let diann_attempt = ElutionGroupCollection::try_read_diann(path.as_ref());
if let Ok(egs) = diann_attempt {
return Ok(egs);
}

// Try Spectronaut next
let spectronaut_attempt = ElutionGroupCollection::try_read_spectronaut(path.as_ref());
if let Ok(egs) = spectronaut_attempt {
return Ok(egs);
}

// Fall back to JSON
ElutionGroupCollection::try_read_json(path.as_ref())
}
3 changes: 3 additions & 0 deletions rust/timsquery/src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod diann_io;
mod elution_group_inputs;
pub mod index_serde;
mod library_file;
mod spectronaut_io;

pub use chromatogram_output::*;
pub use index_serde::*;
Expand All @@ -11,5 +12,7 @@ pub use library_file::{
ElutionGroupCollection,
FileReadingExtras,
LibraryReadingError,
SpectronautPrecursorExtras,
read_library_file,
};
pub use spectronaut_io::LibrarySniffError;
Loading