Skip to content

Commit 40f3ee1

Browse files
committed
quant: centre the purity window on the isolation target m/z
The precursor purity window was centred on the precursor m/z, which on Thermo-derived mzML is the monoisotopic m/z from the trailer. When the instrument isolated a heavier isotope, the window missed what was actually isolated (and any interferent next to it) and purity read 1.0. - Spectrum carries isolation_target_mz: mzML MS:1000827, the Thermo isolation window target; None elsewhere. - precursor_purity centres the window on the target, falling back to the precursor m/z. The isotope ladder still starts at the precursor m/z, searched over the whole survey scan, and only peaks inside the window count as envelope. - DOCS.md describes the window centre.
1 parent af0989b commit 40f3ee1

36 files changed

Lines changed: 178 additions & 34 deletions

‎DOCS.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,12 @@ single input run's MS1 scans still need to fit in memory while it is processed.
717717
the same FAIMS compensation voltage, else the last MS1 before it. (On FAIMS runs the last MS1 in
718718
time is usually a survey scan at another voltage, which does not contain the precursor.) The most intense peak
719719
within 10 ppm of the precursor m/z anchors a ¹³C isotope ladder (10 ppm per step, both
720-
directions) inside the strict isolation window. This is the ladder of OpenMS's
720+
directions); the isotopes that fall inside the strict isolation window count as envelope. The
721+
window is centred on the isolation target m/z (mzML `isolation window target m/z`), not on the
722+
precursor m/z: when the instrument isolated a heavier isotope than the monoisotopic m/z it
723+
assigned, the window covers what was actually isolated. Without a recorded target the window
724+
is centred on the precursor m/z. The native `.raw` reader reports the window around the
725+
monoisotopic m/z, so on `.raw` input the window stays centred there. This is the ladder of OpenMS's
721726
`IsobaricChannelExtractor` without its fuzzy window border and next-scan interpolation, and
722727
with ¹³C spacing and a two-sided nearest-peak match (OpenMS steps by the neutron mass and
723728
misses the upper isotopes, OpenMS/OpenMS#10467). Reported per PSM; `--tmt-min-purity`

‎crates/andes/src/bin/andes/quant_run.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ pub(crate) fn run_quant(
989989
quant::precursor_purity(
990990
ms1.peaks(scan),
991991
pmz,
992+
spec.isolation_target_mz,
992993
hit.psm.charge_used,
993994
lo,
994995
hi,

‎crates/andes/src/bin/andes/train.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ pub(crate) fn read_msnet_parquet(path: &Path) -> Result<Vec<MsnetPsm>, Box<dyn s
10221022
activation_method: None,
10231023
isolation_lower_offset: None,
10241024
isolation_upper_offset: None,
1025+
isolation_target_mz: None,
10251026
};
10261027

10271028
out.push(MsnetPsm {

‎crates/input/src/isobaric.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ mod tests {
128128
activation_method: None,
129129
isolation_lower_offset: None,
130130
isolation_upper_offset: None,
131+
isolation_target_mz: None,
131132
}
132133
}
133134

‎crates/input/src/mgf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl<R: BufRead> Iterator for MgfReader<R> {
165165
activation_method: None,
166166
isolation_lower_offset: None,
167167
isolation_upper_offset: None,
168+
isolation_target_mz: None,
168169
}))
169170
}
170171
}

‎crates/input/src/mzml.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const CV_PROFILE: &str = "MS:1000128";
5858
const CV_SELECTED_ION_MZ: &str = "MS:1000744";
5959
/// Isolation-window lower offset in Da (selected m/z − lower = window start).
6060
const CV_ISOLATION_LOWER_OFFSET: &str = "MS:1000828";
61+
/// Isolation-window target m/z: the centre the offsets are measured from.
62+
const CV_ISOLATION_TARGET_MZ: &str = "MS:1000827";
6163
/// Isolation-window upper offset in Da (selected m/z + upper = window end).
6264
const CV_ISOLATION_UPPER_OFFSET: &str = "MS:1000829";
6365
/// `scan window lower limit` / `scan window upper limit` (under `<scanWindow>`).
@@ -304,6 +306,8 @@ struct SpectrumBuilder {
304306
/// Isolation-window upper offset in Da, from `<isolationWindow>`
305307
/// `MS:1000829`. `None` when the mzML omits the isolation window.
306308
isolation_upper_offset: Option<f64>,
309+
/// Isolation-window target m/z, from `<isolationWindow>` `MS:1000827`.
310+
isolation_target_mz: Option<f64>,
307311
/// `<precursor spectrumRef="...">`: the native id of the scan this one was
308312
/// produced from. Links an MS3 reporter scan to its MS2 for quantification.
309313
parent_ref: Option<String>,
@@ -562,6 +566,7 @@ impl<R: BufRead> MzMLReader<R> {
562566
activation_method: sb.activation_method,
563567
isolation_lower_offset: sb.isolation_lower_offset,
564568
isolation_upper_offset: sb.isolation_upper_offset,
569+
isolation_target_mz: sb.isolation_target_mz,
565570
}))
566571
}
567572

@@ -693,6 +698,13 @@ impl<R: BufRead> MzMLReader<R> {
693698
}
694699
}
695700
}
701+
CV_ISOLATION_TARGET_MZ if self.state == State::IsolationWindow => {
702+
if let Ok(mz) = cv.value.parse::<f64>() {
703+
if let Some(sb) = self.current.as_mut() {
704+
sb.isolation_target_mz = (mz.is_finite() && mz > 0.0).then_some(mz);
705+
}
706+
}
707+
}
696708

697709
// Acquired m/z range: the first `<scanWindow>` of the scan.
698710
CV_SCAN_WINDOW_LOWER if self.state == State::Scan => {
@@ -2891,6 +2903,7 @@ mod tests {
28912903
assert_eq!(spectra.len(), 1);
28922904
assert_eq!(spectra[0].isolation_lower_offset, Some(1.5));
28932905
assert_eq!(spectra[0].isolation_upper_offset, Some(1.5));
2906+
assert_eq!(spectra[0].isolation_target_mz, Some(500.5));
28942907
// The isolation-window target (MS:1000827) must NOT clobber the
28952908
// selectedIon precursor m/z.
28962909
assert!((spectra[0].precursor_mz - 500.5).abs() < 1e-6);
@@ -2912,6 +2925,7 @@ mod tests {
29122925
assert_eq!(spectra.len(), 1);
29132926
assert_eq!(spectra[0].isolation_lower_offset, None);
29142927
assert_eq!(spectra[0].isolation_upper_offset, None);
2928+
assert_eq!(spectra[0].isolation_target_mz, None);
29152929
}
29162930

29172931
// ── Instrument-type detection ────────────────────────────────────────────
@@ -3745,7 +3759,7 @@ mod tests {
37453759
/// One spectrum's fields, for comparing two reads of the same file.
37463760
fn spectrum_fingerprint(s: &Spectrum) -> String {
37473761
format!(
3748-
"{}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}",
3762+
"{}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}|{:?}",
37493763
s.title,
37503764
s.precursor_mz.to_bits(),
37513765
s.precursor_charge,
@@ -3754,6 +3768,7 @@ mod tests {
37543768
s.activation_method,
37553769
s.isolation_lower_offset.map(f64::to_bits),
37563770
s.isolation_upper_offset.map(f64::to_bits),
3771+
s.isolation_target_mz.map(f64::to_bits),
37573772
s.precursor_intensity.map(f32::to_bits),
37583773
s.peaks
37593774
.iter()

‎crates/input/src/thermo.rs‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,17 @@ impl ThermoRawReader {
158158
let precursor_intensity = if inten > 0.0 { Some(inten) } else { None };
159159

160160
// Isolation window: RawFileReader gives absolute m/z bounds
161-
// (lower, target, upper); the model stores offsets from the target,
162-
// matching mzML's `isolation window lower/upper offset`. Skip a
163-
// degenerate/absent window (the cascade is its only consumer).
161+
// (lower, target, upper); the model stores the target and the offsets
162+
// from it, matching mzML's `isolation window target m/z` and
163+
// `lower/upper offset`. Skip a degenerate/absent window.
164164
let w = p.isolation_window();
165165
let (lo, tg, up) = (w.lower(), w.target(), w.upper());
166-
let (isolation_lower_offset, isolation_upper_offset) = if tg > 0.0 && up > lo {
167-
(Some((tg - lo).abs()), Some((up - tg).abs()))
168-
} else {
169-
(None, None)
170-
};
166+
let (isolation_lower_offset, isolation_upper_offset, isolation_target_mz) =
167+
if tg > 0.0 && up > lo {
168+
(Some((tg - lo).abs()), Some((up - tg).abs()), Some(tg))
169+
} else {
170+
(None, None, None)
171+
};
171172

172173
Some(Spectrum {
173174
// The Thermo controller native id (e.g.
@@ -187,6 +188,7 @@ impl ThermoRawReader {
187188
activation_method: map_dissociation(p.activation().dissociation_method()),
188189
isolation_lower_offset,
189190
isolation_upper_offset,
191+
isolation_target_mz,
190192
})
191193
}
192194

‎crates/input/src/timstof.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl TimsTofReader {
146146
activation_method: None,
147147
isolation_lower_offset,
148148
isolation_upper_offset,
149+
isolation_target_mz: None,
149150
})
150151
}
151152
}

‎crates/model-train/src/gbdt/dataset.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ mod tests {
156156
activation_method: None,
157157
isolation_lower_offset: None,
158158
isolation_upper_offset: None,
159+
isolation_target_mz: None,
159160
}
160161
}
161162

‎crates/model-train/src/gbdt/frag_dataset.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ mod tests {
133133
activation_method: None,
134134
isolation_lower_offset: None,
135135
isolation_upper_offset: None,
136+
isolation_target_mz: None,
136137
}
137138
}
138139

0 commit comments

Comments
 (0)