Skip to content

quant: isobaric reporter (--tmt) and label-free MS1 (--lfq) quant - #119

Closed
timosachsenberg wants to merge 8 commits into
mainfrom
claude/intelligent-johnson-tk7099
Closed

timosachsenberg wants to merge 8 commits into
mainfrom
claude/intelligent-johnson-tk7099

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

andes now quantifies the confident rank-1 PSMs inside the search run, at the feature level, and leaves normalization, protein roll-up and statistics to quantms / OpenMS.

New crate quant (pure algorithms over peak lists):

  • isobaric: TMT 6/10/11/16/18 and iTRAQ 4/8 channel tables (OpenMS values), most-intense-peak reporter extraction within a tolerance, the OpenMS text impurity sheet (4 and 8 column forms) parsed into observed = M * true and solved by Lawson-Hanson NNLS, as IsobaricIsotopeCorrector does.
  • purity: precursor isolation purity from the preceding MS1 scan (isotope ladder at 10 ppm, the PrecursorPurity rule).
  • ms1_index / xic / lfq: a run's MS1 scans indexed by RT; four isotope chromatograms per target, Savitzky-Golay smoothing, apex climbed from the PSM's scan, boundaries at the first valley or 2 % of the apex, trapezoid areas; envelope cosine against the peptide's formula-derived theoretical envelope (formula.rs; modification deltas as averagine atoms).
  • tdc: picked target/decoy competition against a twin extracted 11 Th above each target, giving a feature q-value (IonQuant's ion-level scheme).

Readers: the mzML reader captures every MS1 scan (RT + centroids) and MS3+ scans with their <precursor spectrumRef> on request, without emitting them as searchable spectra; the Thermo reader does the same (master scan via the precursor's parent index). New model::scan::{Ms1Scan, ProductScan}.

Driver: --tmt <plex>, --tmt-level 2|3, --tmt-tol, --tmt-correction, --tmt-min-purity, --lfq, --lfq-tol, --lfq-rt-window, --lfq-min-cosine, --lfq-feature-fdr, --quant-fdr, plus a quant: group in the YAML config. Reporter ions are read from each MS2 while its peaks are in memory; quantification runs after rescoring on PSMs at q <= --quant-fdr (every rank-1 target PSM, with a warning, without rescoring). --lfq / --tmt-level 3 need mzML or .raw and are rejected with --chimeric, MGF, .d and --glyco.

Outputs: Sage-shaped <stem>.tmt.tsv (corrected channels, raw block when a matrix was applied, purity), <stem>.lfq.tsv (wide over runs at the feature FDR), <stem>.lfq_features.tsv (every feature with apex, bounds, areas, score, decoy score, q), and with --output-parquet the QPX feature view quantms.feature.parquet (OpenMS QPXFeatureSchema, file_type feature_file, intensities as [{label, intensity}]).

Tests: unit tests in every quant module and the writers; reader tests for MS1/MS3 capture; end-to-end tests on two synthetic fixtures generated by scripts/make_quant_fixtures.py (six BSA peptides with designed reporter patterns, an interfered precursor, and Gaussian elution profiles) checking the reporter ratios, the impurity correction, the purity, the MS3 linkage and the integrated areas against the designed values.

Claude-Session: https://claude.ai/code/session_0116xbaQQJpHtmofZc5FirfT

Acquisition context (survey scan, scan window, FAIMS) — follow-up commit

The readers now record each MS2's survey-scan reference, acquired m/z range and FAIMS compensation voltage.

  • Purity uses the MS2's own survey scan (else the last MS1 at the same FAIMS voltage). On the FAIMS SPS-MS3 TKO run of PXD017803, purity had been missing for 2,308 of 4,570 PSMs, with a median of 0. Now every PSM has a value (median 0.98). At purity ≥ 0.9, 3,487 PSMs remain and knockout-channel interference drops from 0.128 to 0.040.
  • Reporter scans that do not acquire every channel (the automatic first mass is above 126 Th) are no longer written as zeros. On the FAIMS hrMS2 TKO run this excluded 4,345 of 6,361 PSMs.
  • LFQ on FAIMS runs builds one chromatographic series per voltage. Before, the median integration window was 3.9 s instead of 22 s, and areas were 10.7x too small.

Validation:

  • Reporter intensities match OpenMS IsobaricAnalyzer exactly on the same scans, both with and without the TMTpro impurity matrix.
  • On the six-run UPS1 set (no FAIMS), the LFQ tables are byte-identical to the previous head.
  • Workspace tests: 1,192 passed. clippy with -D warnings is clean, and the thermo feature type-checks.

…ation

andes now quantifies the confident rank-1 PSMs inside the search run, at the
feature level, and leaves normalization, protein roll-up and statistics to
quantms / OpenMS.

New crate `quant` (pure algorithms over peak lists):
- isobaric: TMT 6/10/11/16/18 and iTRAQ 4/8 channel tables (OpenMS values),
  most-intense-peak reporter extraction within a tolerance, the OpenMS text
  impurity sheet (4 and 8 column forms) parsed into observed = M * true and
  solved by Lawson-Hanson NNLS, as IsobaricIsotopeCorrector does.
- purity: precursor isolation purity from the preceding MS1 scan (isotope
  ladder at 10 ppm, the PrecursorPurity rule).
- ms1_index / xic / lfq: a run's MS1 scans indexed by RT; four isotope
  chromatograms per target, Savitzky-Golay smoothing, apex climbed from the
  PSM's scan, boundaries at the first valley or 2 % of the apex, trapezoid
  areas; envelope cosine against the peptide's formula-derived theoretical
  envelope (formula.rs; modification deltas as averagine atoms).
- tdc: picked target/decoy competition against a twin extracted 11 Th above
  each target, giving a feature q-value (IonQuant's ion-level scheme).

Readers: the mzML reader captures every MS1 scan (RT + centroids) and MS3+
scans with their `<precursor spectrumRef>` on request, without emitting them
as searchable spectra; the Thermo reader does the same (master scan via the
precursor's parent index). New `model::scan::{Ms1Scan, ProductScan}`.

Driver: `--tmt <plex>`, `--tmt-level 2|3`, `--tmt-tol`, `--tmt-correction`,
`--tmt-min-purity`, `--lfq`, `--lfq-tol`, `--lfq-rt-window`,
`--lfq-min-cosine`, `--lfq-feature-fdr`, `--quant-fdr`, plus a `quant:`
group in the YAML config. Reporter ions are read from each MS2 while its
peaks are in memory; quantification runs after rescoring on PSMs at
q <= --quant-fdr (every rank-1 target PSM, with a warning, without
rescoring). `--lfq` / `--tmt-level 3` need mzML or .raw and are rejected
with --chimeric, MGF, .d and --glyco.

Outputs: Sage-shaped `<stem>.tmt.tsv` (corrected channels, raw block when
a matrix was applied, purity), `<stem>.lfq.tsv` (wide over runs at the
feature FDR), `<stem>.lfq_features.tsv` (every feature with apex, bounds,
areas, score, decoy score, q), and with --output-parquet the QPX feature
view `quantms.feature.parquet` (OpenMS QPXFeatureSchema, file_type
feature_file, intensities as [{label, intensity}]).

Tests: unit tests in every quant module and the writers; reader tests for
MS1/MS3 capture; end-to-end tests on two synthetic fixtures generated by
scripts/make_quant_fixtures.py (six BSA peptides with designed reporter
patterns, an interfered precursor, and Gaussian elution profiles) checking
the reporter ratios, the impurity correction, the purity, the MS3 linkage
and the integrated areas against the designed values.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_0116xbaQQJpHtmofZc5FirfT
claude added 3 commits October 8, 2026 18:07
…er trailer

The MS3 capture resolved the parent through precursor().parent_index(). On
PXD007683 a05058 (Lumos, ion-trap MS2 + SPS-MS3) that index matched the scan's
Master Scan Number trailer for 5,702 of 37,326 MS3 scans; otherwise it named
the MS3 itself or the last MS2. 7,984 of 12,077 PSMs got no MS3 and 2,543 of
the 4,093 linked ones carried another peptide's reporter ions.

The trailer is on every MS3 of that file. Reading it links 11,963/11,963
shared PSMs to the same MS3 as the mzML path (FileConverter spectrumRef), and
12,008/12,013 scans carry the same reporter values as OpenMS IsobaricAnalyzer.
Without the trailer the scan stays unlinked rather than mislinked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0191LNr9sLGKAN6uGXdyH88H
Boundaries stopped at the first 10 % rise above the running minimum, which on
~1 s Orbitrap survey scans is noise. On PXD001819 (UPS1 2,500 vs 25,000 amol
in yeast, three replicates each) the same yeast peptide's integration window
differed by 2x or more between replicates for half the peptides, and the
area CV was 39.7 % against 10.9 % for OpenMS FeatureFinderIdentification on
the same targets.

Each boundary now sits two half-widths at half maximum from the apex of the
smoothed monoisotopic trace (98 % of a Gaussian), or at an earlier deep valley
(below half the apex, then a 1.5x rise). A feature whose monoisotopic area
holds less than 30 % of its theoretical share is not returned: its M+1..
traces belong to an isotope-shifted species (a deamidated N-G peptide was
integrated at ~100x). 0.9 % of UPS1 features fall below that; the median
observed/theoretical share is 1.07.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0191LNr9sLGKAN6uGXdyH88H
…cosine

- --tmt-level 3 defaults to 20 ppm. The default followed the MS2 model, so
  ion-trap SPS-MS3 data got 0.3 Da and every TMT N/C pair read the same peak
  (127N == 127C on 11,980/11,981 a05058 PSMs). A reporter window that reaches
  half the kit's closest channel spacing is now refused, which also rejects
  TMT10+ at MS2 on ion-trap data.
- --lfq no longer refuses a low-resolution MS2 model: high/low methods
  (Velos/Elite/Fusion/Lumos) have Orbitrap MS1. Each run's MS1 is checked
  instead (share of intense centroids with a 10 ppm isotope partner: Orbitrap
  0.70-0.93, ion-trap-like 0.09-0.32) and a warning names low-resolution runs.
- --lfq-min-cosine was parsed but never applied; lfq.tsv now leaves out
  features below it (lfq_features.tsv and the parquet keep them).
- --chimeric --tmt: say once that purity is not computed there and refuse
  --tmt-min-purity instead of filtering nothing.
- QPX: iTRAQ labels as ITRAQ<channel> (OpenMS's canonical form), and an empty
  scan list instead of [0] when the native id has no scan number.
- Clippy suspicious_map in the new mzML test; parse_protocol doc comment back
  on parse_protocol; GlycoCfg keeps #[serde(default)].
- DOCS: the purity rule as implemented (it is not OpenMS's, which misses the
  upper isotopes: OpenMS/OpenMS#10467), the new boundaries, the MS1 check,
  and 16 bytes per captured MS1 centroid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0191LNr9sLGKAN6uGXdyH88H

Copy link
Copy Markdown
Contributor Author

Fixes for the review above, re-measured against OpenMS

The fixes are three commits on claude/eager-ride-84sqql, on top of this PR's head a52aece. The branch fast-forwards, so it can be pushed onto this PR's branch as is.

  • 3ccd4e5: Thermo SPS-MS3 linkage via the Master Scan Number trailer
  • cea2b8b: LFQ half-width peak boundaries and a monoisotope check
  • 3495a43: SPS-MS3 tolerance, --lfq on high/low data, --lfq-min-cosine, nits and docs

Local checks:

  • cargo clippy --workspace --all-targets -D warnings is clean.
  • The quant, input and output unit tests and all 4 quant e2e tests pass.
  • rustfmt is clean on the touched files. The only remaining diffs are the glyco files that already fail on main.

Before / after, same data and the same OpenMS nightly

Check PR head a52aece With fixes OpenMS
a05058 SPS-MS3, default flags: reporter tolerance used 0.3 Da (127N == 127C on 11,980/11,981 PSMs) 20 ppm (127N == 127C on 1/11,945) —
a05058 native .raw: PSMs with an MS3 4,093 / 12,077, of which 2,543 got another peptide's MS3 12,077 / 12,077; all 11,963 shared PSMs link to the same MS3 as the mzML path —
a05058 native .raw: reporters identical to IsobaricAnalyzer — 12,008 / 12,013 scans reference
OpenMS MS3_nonHierarchical.mzML, default flags 0 / 52 scans identical 52 / 52 reference
--tmt tmt10 on ion-trap MS2 silently merges N/C channels refused, with an explanation —
--lfq on LTQ-Orbitrap / Velos data (OpenMS BSA example, PXD001819) refused runs; MS1 resolution check passes —
BSA, andes area vs FFId on the same targets (log10 Pearson / Spearman) 0.971 / 0.983 0.992 / 0.997 —
UPS1, 6 runs: yeast within-condition CV 39.7 % 11.3 % FFId 10.9 %, ProteomicsLFQ 9.6 %
UPS1: yeast log2FC IQR (expected 0) [−0.28, +0.47] [+0.05, +0.27] FFId [+0.06, +0.27]
UPS1: complete UPS peptides, log2FC (expected 3.32) median 3.65, IQR [3.18, 4.51] median 3.66, IQR [3.59, 3.74] FFId median 3.48, IQR [3.19, 3.51]
UPS1: per-feature agreement with FFId (log10 Pearson / IQR of log ratio) 0.823 / 0.602 0.947 / 0.119 —
UPS1: rows complete across 6 runs 45 % 45 % ProteomicsLFQ 48 %

How the LFQ change was chosen. Before touching Rust, I re-implemented the extraction in Python. The re-implementation reproduced all 28,600 PR-head features to within 1%. I then compared boundary rules on the same features:

Boundary rule Yeast CV
Apex height alone 16.5 %
Valley rule on a Gaussian-smoothed trace 10.9 %
±2 half-widths at half maximum (HWHM) 11.2 %
±2 HWHM, capped at deep valleys (chosen) 11.4 %

I kept the existing 5-point Savitzky–Golay trace and apex climb, and only replaced the boundary rule. The valley cap protects against running into a co-eluting neighbour. Together with the monoisotope check (features with less than 30% of their theoretical mono share are not returned, 0.9% of UPS1 features), the fixed binary gives the 11.3% above.

What changed, by finding

  • B1. --tmt-level 3 defaults to 20 ppm. Plex::check_tolerance refuses any window at or above half the kit's closest channel spacing.
  • B2. The Thermo reader reads the Master Scan Number trailer. Without the trailer, an MS3 stays unlinked rather than mislinked.
  • B3. A low-res MS2 model now gives a warning instead of an error. Each run's MS1 is tested by the share of intense centroids that have a 10 ppm isotope partner: Orbitrap scored 0.70–0.93, ion-trap-like data 0.09–0.32, and runs below 0.5 get a warning.
  • 4 / 5. Half-width boundaries (xic.rs) and LfqParams::min_mono_share = 0.3 (lfq.rs).
  • 6. --lfq-min-cosine now removes features below the threshold from lfq.tsv. lfq_features.tsv and the parquet keep them.
  • Minor.

Not fixed here (need a design call or touch pre-existing code)

  • QPX identity. feature_id is not the BLAKE2b hash of the declared identity_composite. psm_ids are row indices, and psms.parquet has no psm_id.
  • psms.parquet overflow. It is written as a single RecordBatch with Utf8 columns and overflows at about 2 GiB of strings (pre-existing qpx.rs). Multi-run --lfq --output-parquet still panics before quant runs.
  • Purity under --chimeric. The chunked readers consume themselves and don't hand their MS1 to quant.
  • MS1 memory. All runs' MS1 is held until the end (≈ 2.4 GB for 6 UPS1 runs). There is also no per-channel reporter QC line and no match-between-runs.
  • Thermo-feature clippy lints. Three pre-existing lints in thermo.rs (lines 133, 440, 456) only show with --features thermo, which CI doesn't build.

Generated by Claude Code

Cache MS1 scans losslessly in private temporary files before rescoring, then load one run at a time for LFQ and precursor purity. Release prepared-search scratch state before output and Percolator. Document scratch requirements and verify exact round trips and cleanup.

The six-file UPS1 full pipeline now completes within 8 GiB: 6.51 GiB peak process-tree RSS. PIN, Percolator, and LFQ tables are byte-identical; all PSM and feature Parquet data match.
Keep raw-area integration and symmetric target/decoy processing. Retain the existing default, document acquisition-dependent feature-q coverage, and clarify that feature competition cannot replace PSM confidence.
@bigbio bigbio deleted a comment from coderabbitai Bot Oct 9, 2026
…FAIMS voltage)

The readers now record, for every searched MS2, the scan its precursor
references (mzML <precursor spectrumRef>, .raw Master Scan Number), its
acquired m/z range and its FAIMS compensation voltage; MS1 scans keep their
native id and voltage, and MS3 reporter scans their m/z range.

- Precursor purity is computed on the MS2's own survey scan (else the last
  MS1 at the same FAIMS voltage, else the last MS1 in time). On a three-
  voltage FAIMS SPS-MS3 TKO run (PXD017803) the last MS1 in time is usually
  another voltage's survey scan: purity was missing for 2,308 of 4,570 PSMs
  and 0 for most others (median 0); it is now present for all, median 0.98.
  Filtering at purity >= 0.9 keeps 3,487 PSMs and lowers the knockout-channel
  interference (KO/non-KO median) from 0.128 to 0.040.
- A reporter scan whose scan window does not cover every reporter m/z is not
  quantified. On the same study's FAIMS hrMS2 run the automatic first mass
  was above 126 Th for 4,345 of 6,361 quantified PSMs: their low channels
  were never measured and were written as zero intensities.
- Label-free extraction keeps one chromatographic series per FAIMS voltage
  and extracts each precursor at its PSM's voltage. Interleaved voltages put
  zeros between the measured scans: on the FAIMS hrMS2 run the mixed series
  gave a median integration window of 3.9 s instead of 22 s and areas
  10.7x too small.

Runs without FAIMS and without recorded survey references behave as before.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ypriverol

Copy link
Copy Markdown
Contributor

Superseded by #139. It carries all commits from this PR (authorship kept), the defects found while testing them (FAIMS-aware purity and LFQ, purity window centred on the isolation target, unacquired reporter channels skipped, valid float output for values in [1, 10)), and multi-run LFQ with match-between-runs. #139 is stacked on #138 for now. This PR can be closed once #139 is reviewed.

@ypriverol ypriverol closed this Oct 13, 2026
ypriverol added a commit that referenced this pull request Oct 13, 2026
quant: TMT/LFQ quantification and scalable multi-run match-between-runs (supersedes #119)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants