Skip to content

[FEATURE] NASE: search a background of known RNAs (background:enable) - #10940

Draft
poshul wants to merge 6 commits into
codex/nase-stack/foundationsfrom
codex/nase-stack/09-background
Draft

poshul wants to merge 6 commits into
codex/nase-stack/foundationsfrom
codex/nase-stack/09-background

Conversation

@poshul

@poshul poshul commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Written by an AI agent using GPT-6.2 Sol.

Build follow-up. This branch now includes #10927 at d45a5c1340, with the upstream ONNX Runtime archive fallback (#10947) and the Windows MassExplainer header fix. All 72 selected CTests passed in the ONNX-enabled Linux Debug build, including the NASE, DecoyDatabase, PeptDeep, Compomer, MassExplainer, and FLASH core checks. Windows validation is pending CI.

Description

Stacked on #10927 (base: codex/nase-stack/foundations).

Restacked onto #10927 at d45a5c1340. The merge preserves the complete report-independent rescoring pool and native fallback identities while keeping background explanations out of training. Pooled parent sets are merged with IdentifiedOligo::merge before applying the database-only target/decoy rule, so background parents cannot turn a database decoy into a target. Background filtering precedes the native report cutoff. Regression checks cover both interactions.

Adds an optional background search to NucleicAcidSearchEngine: a set of known RNAs that the sequence database lacks is searched alongside it, and spectra best explained by a background sequence are left out of the results, of Percolator rescoring and of the FDR calculation.

Why. Entrapment checks on HAP1 tRNA data (PXD016328) showed that many high-scoring decoy and entrapment matches were real human RNAs missing from the tRNA database: tRNA 3' end variants, mitochondrial and rRNA oligos, U6 snRNA and others. With four nucleotides and short T1 oligos, shuffled decoys and false targets often reproduce such molecules exactly or nearly. Each molecule then brings dozens of correlated spectra to whichever label it happens to match, which skews the target-decoy estimate in both directions. This follows the "subset-neighbor search" of Lin, Plubell, Keich and Noble (J Proteome Res 2021, 20:4153): background sequences and their decoys compete for every spectrum, and spectra they win are removed for targets and decoys alike. The background sequences are real ones, not hypothetical sequence variants. A prototype with all one-edit variants of the target oligos as neighbors absorbed 40% of the correct target matches and made the estimate worse.

What changes

  • Options (all off/empty by default; existing results are unchanged):

    • background:enable
    • background:database: a custom FASTA. Without it, the built-in human background is used; the help text warns that it only suits human samples.
    • background:out: a TSV of the left-out spectra and their background hits.
  • Built-in human background, share/OpenMS/SEQUENCES/RNA/human_background_rna.fasta, 1769 sequences:

    • GtRNAdb hg38 mature tRNAs with 3' ends CCA, CC, C and none
    • NC_012920.1 on both strands, plus its 22 tRNAs
    • 45S and 5S rRNA
    • 15 abundant small RNAs

    A README and the script that rebuilds it sit alongside.

  • RNABackgroundDatabase (NASE helper) shuffles each digestion product separately and deterministically. It keeps the enzyme's cleavage residues and the 3' residue in place, and every product of the same text gets the same shuffle, so related sequences keep shared oligos. NASE uses it to:

    • make a decoy of every background sequence. Its oligos equal no target, background or decoy oligo.
    • reshuffle decoy oligos of the database that equal a target or background oligo. This is a blacklist of real molecules for decoys.
    • Both checks cover the searchable oligos, including missed-cleavage combinations of consecutive products and those assembled from products shorter than oligo:min_size (review of [FEATURE] DecoyDatabase: per-product RNA shuffle with blacklist (shuffle_products) #10941). NASE uses the search's missed cleavages, plus variable_max_per_oligo when modifications can block cleavage (e.g. m7G). Components of a colliding combination try other shuffles; a change is kept only if it removes collisions around that product without creating a new one (a first version that only lowered the count moved a collision onto a mitochondrial oligo, see the review thread). Each product keeps one shuffle everywhere. Combinations of products that cannot change (e.g. G, AG) can remain and are logged. On one HAP1 file (min. length 7), colliding decoy combinations went from 1759 to 1109 (database decoys) and from 10281 to 8046 (background decoys).
    • An oligo with a background parent and no database target parent is a background oligo, also if a database decoy shares it: it is a real molecule, and subset-neighbor search leaves such matches out.
  • Labelling:

    • A spectrum is left out only if all its best-scoring hits are background hits, meaning the oligo has a background parent (a background sequence or its decoy) and no target parent of the database.
    • A database oligo tied with a background oligo keeps the spectrum.
    • Background parents don't count when deciding whether an oligo is a decoy, and they are removed before FDR, so the output never lists them.
  • A digest written with digest_out keeps its background. Reusing it gives identical results, with a warning if the flag isn't set.

Entrapment check.

The following figures are from the feature's earlier benchmark checkpoint; those real-data searches were not rerun for this restack.

  • Setup:
    • 3 HAP1 clones × 6 independent shuffles of entrapment and decoys
    • 420 target tRNAs plus as many entrapment tRNAs, shuffled decoys of both
    • HyperScore, oligo:min_size 7, no missed cleavages
    • estimated FDP = 2E/(T+E), median over the 18 searches (maximum in brackets)
Decoys and entrapment Score, q Target spectra off → on Estimated FDP off → on
shuffled per T1 product, avoiding human RNA oligos native, 5% 1020 → 1519 3.3% (17.6%) → 2.4% (12.4%)
Percolator, 5% 1718 → 1848 5.9% (15.9%) → 3.4% (16.0%)
Percolator, 10% 1936 → 1954 11.0% (21.1%) → 5.2% (20.7%)
DecoyDatabase (whole tRNAs shuffled) native, 5% 1198 → 1592 5.3% (8.6%) → 5.0% (12.5%)
Percolator, 5% 1828 → 1893 7.2% (13.7%) → 5.1% (15.6%)
  • The background left out about 3300 to 3500 spectra per search, mostly spectra that had no database hit at all.
  • The gain is larger with decoys shuffled per digestion product. Whole-tRNA shuffles of related tRNAs give more distinct decoy oligos than target oligos. A separate change will add such a mode to DecoyDatabase.

Limitations (documented in TOPP_NASE_Background)

  • Sample-specific variants are not covered. For example, HAP1 carries a tRNA-Arg-CCT variant (CUCCACCUG, dbSNP rs1958029127) that still matched an entrapment sequence.
  • Single searches still exceed the nominal FDR, and oligo-level results at 1% are too few to judge.
  • Some background oligos cannot be shuffled into a new decoy (U stretches, short oligos). We recommend oligo:min_size 7.
  • Searches with the built-in background take about 6× longer (HAP1 file: 4.7 s → 30 s), mainly because of the mitochondrial genome.
  • GtRNAdb's terms for redistributing its tRNA sequences still need checking. The RefSeq sequences are unrestricted.

Tests

  • New:
    • RNABackgroundDatabase_test: fixed residues, determinism, avoiding forbidden products, consistent rewrites, short products, missed-cleavage combinations (the review's case: targets ACGUAG and CAGAUG, RNase T1, min. length 5, one missed cleavage)
    • TOPP_NucleicAcidSearchEngine_background (+ _out, _tsv_out): targets T0–T9 moved into a custom background are left out, and no background sequence appears in the mzTab
    • TOPP_NucleicAcidSearchEngine_background_builtin: the built-in file is found
  • Restack validation: a fresh out-of-tree GCC 15.2 Debug build of OpenMS core/CLI, NASE and affected tests with system dependencies (ONNX, OpenTIMS, Thermo RAW and pyOpenMS disabled). All 43 selected CTests pass: 11 C++ suites and all 32 NASE TOPP tests. This includes the three rescoring reference comparisons that failed on the old base; no reference outputs or comparison tolerances were changed for the restack.
  • An additional background-plus-Percolator check excluded 18 background spectra from training. Its 633 remaining feature/label rows and learned results were exactly identical between a fresh top-1 search and a cached-digest top-2 search. Full-repository, pyOpenMS and new real-data calibration tests were not run.

Checklist

  • New and existing unit tests pass locally with my changes (43 selected tests pass; full repository suite not run)

AI use (see the OpenMS AI Policy)

  • I have read the OpenMS AI Policy, and I understand, have reviewed and tested every change in this PR and can explain it in my own words
  • Substantial AI use in PR (e.g. agentic tools wrote significant parts); commits carry a Co-authored-by: trailer, and the description above explains the design intent and rationale

No need to edit the CHANGELOG file: entries are generated automatically once per week from merged changes.

🤖 Generated with Claude Code

…d:enable)

Spectra of abundant RNAs that the sequence database lacks match decoys or
false targets, often dozens of spectra per molecule, which skews the
target-decoy FDR. With 'background:enable', NASE searches a background of
known RNAs alongside the database ('subset-neighbor search', Lin et al.,
J Proteome Res 2021) and leaves out every spectrum whose best hit is a
background sequence or one of its decoys, before rescoring and FDR.

- Options: 'background:enable', 'background:database' (custom FASTA;
  default: built-in human background) and 'background:out' (TSV of the
  left-out spectra).
- Built-in human background (share/OpenMS/SEQUENCES/RNA): GtRNAdb hg38
  mature tRNAs with 3' ends CCA/CC/C/none, mitochondrial genome (both
  strands) and tRNAs, 45S/5S rRNA and 15 abundant small RNAs, with the
  script that builds it.
- RNABackgroundDatabase: deterministic per-digestion-product shuffles
  (cleavage residues and the 3' residue stay). NASE uses it to make the
  background decoys and to reshuffle database decoy oligos that equal a
  target or background oligo.
- Background parents never make an oligo a decoy or a background hit and
  are removed before FDR, so they do not appear in the results.
- Tests: RNABackgroundDatabase_test; TOPP tests with targets moved into a
  custom background, and with the built-in background.
- Docs: TOPP_NASE_Background, including an entrapment check on HAP1 tRNA
  data (18 searches): at q <= 5%, native 1020 -> 1570 target spectra
  (estimated FDP 3.3% -> 2.1%), Percolator FDP 5.9% -> 3.4%, with
  per-oligo shuffled decoys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review of #10941: decoys were checked against real oligos only product by
product. Products shorter than the minimum length were shuffled without
any check, so a missed-cleavage combination of decoy products could equal
a target oligo (e.g. targets ACGUAG and CAGAUG with RNase T1, min. length
5 and one missed cleavage: each target's decoy is the other target).

RNABackgroundDatabase::rewrite() now handles all sequences together and
checks the combinations of up to missed_cleavages + 1 consecutive products
of every rewritten sequence. Components of forbidden combinations try
further shuffles (a short product may also stay as it is) and keep the
one that leaves the fewest forbidden combinations around its occurrences;
each product keeps one replacement everywhere, so decoy/target balance is
kept. productKeys() lists missed-cleavage combinations too. NASE uses the
search's missed cleavages, plus 'variable_max_per_oligo' when modifications
can block cleavage.

On HAP1 tRNA data (built-in background, min. length 7), this reduces the
decoy combinations equal to a real oligo from 1759 to 832 (database decoys)
and from 10281 to 6304 (background decoys); the rest consist of products
that cannot change (e.g. G, AG). Regression test with the review's case.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
poshul and others added 2 commits November 18, 2026 20:29
…ound oligos are background

The missed-cleavage repair of beacf12 kept a reshuffle if it lowered
the number of colliding combinations, so it could trade collisions and
create a new one. On HAP1 data it reshuffled the decoy of
tRNA-Phe-GAA-4-1 into UAUG + CACG, joined across a 2'-O-methyl G: the
mitochondrial oligo UAUGCACG, which then collected up to 65 spectra per
run as a decoy. Native results lost a third of their target spectra at
q 5% (1570 -> 1028, median of 18 entrapment searches).

- RNABackgroundDatabase::rewrite(): a candidate is only taken if the
  forbidden combinations around the product afterwards are a strict
  subset of those before (no new collision).
- An oligo with a background parent and no database target parent is a
  background oligo, also if a database decoy shares it (it is a real
  molecule; subset-neighbor search leaves such matches out).

18 entrapment searches (HAP1, built-in background, min. length 7): native
1519 target spectra at q 5% (estimated FDP 2.4%), Percolator 1848 (3.4%);
before the repair 1570 (2.1%) and 1855 (3.4%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@poshul
poshul added this pull request to stack #10944 November 18, 2026 20:01
Preserve background removal before native reporting and rescoring. Merge
parent sets with the existing IdentifiedOligo API before applying the
shared database-only target/decoy rule, so training and final FDR agree.

Validated with 43 selected CTests and a fresh/cached Percolator comparison.

Co-authored-by: OpenAI Codex (GPT-6) <[email protected]>
Inherit the updated develop base and the MassExplainer header fix.

Co-authored-by: OpenAI Codex (GPT-6.2 Sol) <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant