Skip to content

Commit

Permalink
fix: incorrect filenames in output introduced in 06be420
Browse files Browse the repository at this point in the history
  • Loading branch information
lazear committed Sep 19, 2023
1 parent 51001ad commit b04bfbe
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.14.1-alpha.1]
### Fixed
- Fix bug introduced by 06be420 where `file_id` was not being propagated into scans, resulting in only the first filename being written to output files

## [v0.14.1-alpha]
## Added
### Added
- Added additional output showing search progress if `SAGE_LOG=trace` environment variable is set
- Added additional warnings about precursor tolerances
- Added configuration option `precursor_charge` to make it explicit what charge states are being searched in the case where the mzML does not contain charge state information, or where `wide_window` is turned on.
Expand Down
6 changes: 3 additions & 3 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 crates/sage-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-cli"
version = "0.14.1-alpha"
version = "0.14.1-alpha.1"
authors = ["Michael Lazear <michaellazear92@gmail.com"]
edition = "2021"
rust-version = "1.62"
Expand Down
2 changes: 1 addition & 1 deletion crates/sage-cloudpath/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-cloudpath"
version = "0.14.1-alpha"
version = "0.14.1-alpha.1"
authors = ["Michael Lazear <michaellazear92@gmail.com"]
edition = "2021"
rust-version = "1.62"
Expand Down
15 changes: 7 additions & 8 deletions crates/sage-cloudpath/src/mzml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const SELECTED_ION_CHARGE: &[u8] = b"MS:1000041";
const ISO_WINDOW_LOWER: &[u8] = b"MS:1000828";
const ISO_WINDOW_UPPER: &[u8] = b"MS:1000829";

#[derive(Default)]
pub struct MzMLReader {
ms_level: Option<u8>,
// If set to Some(level) and noise intensities are present in the MzML file,
Expand All @@ -73,10 +72,10 @@ impl MzMLReader {
/// # Example
///
/// A minimum level of 2 will not parse or return MS1 scans
pub fn with_level_filter(ms_level: u8) -> Self {
pub fn with_file_id_and_level_filter(file_id: usize, ms_level: u8) -> Self {
Self {
ms_level: Some(ms_level),
file_id: 0,
file_id,
signal_to_noise: None,
}
}
Expand Down Expand Up @@ -115,7 +114,7 @@ impl MzMLReader {
let mut binary_dtype = Dtype::F64;
let mut binary_array = None;

let mut spectrum = RawSpectrum::default();
let mut spectrum = RawSpectrum::default_with_file_id(self.file_id);
let mut precursor = Precursor::default();
let mut iso_window_lo: Option<f32> = None;
let mut iso_window_hi: Option<f32> = None;
Expand Down Expand Up @@ -194,7 +193,7 @@ impl MzMLReader {
let level = extract_value!(ev);
if let Some(filter) = self.ms_level {
if level != filter {
spectrum = RawSpectrum::default();
spectrum = RawSpectrum::default_with_file_id(self.file_id);
state = None;
}
}
Expand All @@ -206,7 +205,7 @@ impl MzMLReader {
let value = extract_value!(ev);
if value == 0.0 {
// No ion current, break out of current state
spectrum = RawSpectrum::default();
spectrum = RawSpectrum::default_with_file_id(self.file_id);
state = None;
} else {
spectrum.total_ion_current = value;
Expand Down Expand Up @@ -357,7 +356,7 @@ impl MzMLReader {
}
(false, _) => {}
}
spectrum = RawSpectrum::default();
spectrum = RawSpectrum::default_with_file_id(self.file_id);
None
}
_ => state,
Expand Down Expand Up @@ -464,7 +463,7 @@ mod test {
</binaryDataArrayList>
</spectrum>
"#;
let mut spectra = MzMLReader::default().parse(s.as_bytes()).await?;
let mut spectra = MzMLReader::with_file_id(0).parse(s.as_bytes()).await?;

assert_eq!(spectra.len(), 1);
let s = spectra.pop().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/sage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sage-core"
version = "0.14.1-alpha"
version = "0.14.1-alpha.1"
authors = ["Michael Lazear <michaellazear92@gmail.com"]
edition = "2021"
rust-version = "1.62"
Expand Down
12 changes: 12 additions & 0 deletions crates/sage/src/spectrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct ProcessedSpectrum {

#[derive(Default, Debug, Clone)]
/// An unprocessed mass spectrum, as returned by a parser
/// *CRITICAL*: Users must set all fields manually, including `file_id`
pub struct RawSpectrum {
pub file_id: usize,
/// MSn level
Expand All @@ -97,6 +98,17 @@ pub struct RawSpectrum {
pub intensity: Vec<f32>,
}

impl RawSpectrum {
/// Return a [`RawSpectrum`] with default values, but with the `file_id` field
/// properly set
pub fn default_with_file_id(file_id: usize) -> Self {
Self {
file_id,
..Default::default()
}
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum Representation {
Profile,
Expand Down

0 comments on commit b04bfbe

Please sign in to comment.