Repository navigation
[FIX] PeptideIndexer: check enzyme specificity on the unmodified protein sequence (fixes #1793) - #10190
Conversation
…ein sequence With 'IL_equivalent', PeptideIndexing replaced every 'L' (and 'J') by 'I' in the protein sequence in-place, and then handed that substituted string to EnzymaticDigestion::isValidProduct(). Cleavage sites were therefore determined on the substituted sequence, which silently destroys sites for enzymes that cleave after 'L' but not after 'I' (and invents sites where the protein had an 'I'). Affected enzymes in Enzymes.xml: Chymotrypsin, Chymotrypsin/P, TrypChymo, PepsinA, PepsinA + P, leukocyte elastase and elastase-trypsin-chymotrypsin. The same string also supplied the flanking residues, so 'aa_before'/'aa_after' were reported as 'I' wherever the protein really had an 'L' or 'J'. The substitution is now done into a separate per-thread buffer which is used for the Aho-Corasick search only; the original sequence is passed to search() as 'full_prot' and drives both the enzyme filter and the flanking residues. Since the substitution preserves length, hit positions carry over unchanged. When 'IL_equivalent' is off, the buffer stays empty and the search string aliases the original, so nothing extra is allocated on the default path. This also removes the guard which rejected 'IL_equivalent' for Chymotrypsin, Chymotrypsin/P and TrypChymo: it covered only three of the seven affected enzymes, and it compared the raw 'enzyme:name' parameter, so it never triggered for the default 'auto' where the enzyme comes from the idXML. Adds a regression test with a chymotryptic peptide preceded by 'L' in the database, which was dropped by the enzyme filter before this change, plus a second protein carrying 'I' instead of 'L' to confirm I/L-equivalent matching still works and that the flanking residues are reported unsubstituted. Fixes #1793 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014cwvmMpsfDb9mD7JwivuuR
…gle-pass I/L substitution Review follow-up to the PeptideIndexer I/L fix. 'elastase-trypsin-chymotrypsin' was the only one of the seven enzymes cleaving after I/L whose regex omitted 'J' -- "(?<=[ALIVKRWFYX])(?!P)" -- although its own RegExDescription says it "cuts after A,L,I(or J),V,K,R,W,F,Y". A peptide preceded by 'J' in the database was therefore rejected as non-specific. With '-IL_equivalent' this was masked, because 'J' was rewritten to 'I' in-place before the cleavage sites were determined; now that the enzyme filter sees the protein unsubstituted, the omission is exposed for that path too. Adding 'J' to the character class fixes both, and matches the six sibling enzymes. The rule is defined twice: Enzymes.xml is what ProteaseDB loads at runtime (a test reverting only that file fails), BuiltInProteaseDataProvider.cpp is the compiled-in fallback. Both are updated. CometAdapter's own enzyme table is a separate Comet-side format and is deliberately left alone. Also builds the I/L-substituted search copy in a single std::transform pass instead of a copy plus two std::replace scans, since this runs for every protein, and includes <algorithm> directly rather than relying on a transitive header. The regression test gains a 'J'-flanked case covering both IL_equivalent settings; it fails on both without the regex fix. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014cwvmMpsfDb9mD7JwivuuR
…Size count_j_proteins counted database proteins containing 'J' so the run could warn that they eat into the 'aaa_max' budget. As a uint16_t it wrapped silently at 65536, and since the warning is guarded by 'if (count_j_proteins)' the message was not merely wrong but absent for any exact multiple of 65536. Verified with a generated FASTA of exactly 65536 'J'-bearing proteins: before, PeptideIndexer printed no 'J' warning at all; after, it reports "found 65536 protein sequences in your database containing the amino acid 'J'". Pre-existing, unrelated to the I/L specificity fix, but in the same function and directly adjacent to the reworked 'J' handling; included at the reviewer's request. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014cwvmMpsfDb9mD7JwivuuR
6049e67 to
0514ebc
Compare
|
@cbielow ready for review |
|
@copilot resolve the merge conflicts in this pull request |
|
|
@cbielow looks correct to me. |
timosachsenberg
left a comment
There was a problem hiding this comment.
This moves the I/L(/J) substitution into a per-thread copy that only the Aho-Corasick search sees. Enzyme specificity and flanking residues now come from the original sequence, and 'J' is added to the elastase-trypsin-chymotrypsin rule. I checked:
- Index alignment: '*' is stripped before the copy and the transform is 1:1, so search positions match. X positions are identical in both strings, so the chunk offsets computed on
prot_searchare valid offsets intoprot. - Performance: there are no per-hit copies (
full_protis a reference to the thread-localprot). The IL path makes one pass into a reused buffer instead of two in-place passes; the default path is unchanged. - Semantics: N-terminal Met clipping (
sequence[0]=='M'), X/B/Z handling and decoy labelling are unaffected. Every regex with L also has J, so 'J' reaching the regex now behaves consistently. - Tests fail without the fix (guard exception / count 0 for Protein1).
CI is green and the PR merges cleanly. Only the CHANGELOG needs work (inline).
Generated by Claude Code
The develop merges had left both entries in the released 3.6.0 section. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UXTNzqFdQLpo9frG4dFizB
|
Merged the current develop and fixed the CHANGELOG review point in a5059ef. Both PeptideIndexer entries now sit in the 3.7.0 section under TOPP tools → Changes → PeptideIndexer instead of the released 3.6.0 section. The PR's diff against develop is otherwise unchanged. Generated by Claude Code |
…#10301, #10611, #10606, #10608, #10609, #10617, #10610, #10578 ProSE Percolator rescoring, #10628) Only CHANGELOG conflicted; both entries are kept. Develop's changes to FalseDiscoveryRate, IDScoreGetterSetter, ConsensusMapMergerAlgorithm, FileInfo and ProSE work on the established classes, which this branch keeps as they are. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
Description
Fixes #1793 — the root cause named in that issue's title is still present on
develop.With
IL_equivalent,PeptideIndexingreplaced everyL(andJ) byIin place in the protein sequence, and then handed that substituted string toEnzymaticDigestion::isValidProduct(). Cleavage sites were therefore determined on the substituted sequence, which silently destroys sites for enzymes that cleave afterLbut not afterI(and invents sites where the protein had anI):Demonstrated with Chymotrypsin's own regex from
Enzymes.xmland one of the peptides from the issue report:Affected enzymes in
Enzymes.xml(those withI/L/Jin their cleavage regex):Chymotrypsin,Chymotrypsin/P,TrypChymo,PepsinA,PepsinA + P,leukocyte elastase,elastase-trypsin-chymotrypsin.The same string also supplied the flanking residues, so
aa_before/aa_afterwere reported asIwherever the protein really had anLorJ— wrong for every enzyme, trypsin included.Fix
The substitution now goes into a separate per-thread buffer used for the Aho-Corasick search only; the original sequence is passed to
search()asfull_protand drives both the enzyme filter and the flanking residues. Since the substitution preserves length, hit positions carry over unchanged.Memory impact is negligible: the original protein sequences are already resident in
FASTAContainer's double-buffered chunk cache, and this only adds one scratch string per thread (amortised to the longest protein seen, so single-digit MB even at high thread counts, against a ~400 MB resident FASTA cache). WhenIL_equivalentis off — the default —prot_ILstays empty andprot_searchaliasesprot, so nothing extra is allocated on the default path.This also removes the guard that rejected
IL_equivalentforChymotrypsin/Chymotrypsin/P/TrypChymowith anInvalidParameterexception. It was never a fix, and it was unsound twice over: it covered only 3 of the 7 affected enzymes, and it compared the rawenzyme:nameparameter, so it never triggered for the defaultenzyme:name=autowhere the enzyme comes from the idXML — which is why the problem kept resurfacing (see the 2022 comment on #1793).Second commit: a pre-existing gap this uncovers
Once the enzyme filter sees the protein unsubstituted, a
Jin the database reaches the cleavage rules asJ. Six of the seven enzymes above listJexplicitly;elastase-trypsin-chymotrypsindid not:Its own
RegExDescriptionreads "cuts after A,L,I(or J),V,K,R,W,F,Y unless followed by P", so the regex simply contradicted its documented intent. A peptide preceded byJwas rejected as non-specific — already the case before this PR wheneverIL_equivalentwas off;IL_equivalent=truehappened to mask it by rewritingJtoIfirst. AddingJto the class fixes both paths.The rule is defined twice:
share/OpenMS/CHEMISTRY/Enzymes.xmlis whatProteaseDBloads at runtime (reverting only that file makes the new test fail), andBuiltInProteaseDataProvider.cppis the compiled-in fallback. Both are updated.CometAdapter.cppalso carries the class in Comet's own enzyme-file format and is deliberately left alone.Regression tests
New
[EXTRA]section inPeptideIndexing_test.cpp, both parts run withIL_equivalentoff and on:specificity=full,aaa_max=0:Protein1=AAGGL·DTAYDDLGNSGHF·SSGGAAProtein2=AAGGW·DTAYDDIGNSGHF·SSGGAAIL_equivalent=falseIL_equivalent=trueplus
aa_before == 'L'(not'I'). Protein2 is a control: valid under either sequence, so it isolates the enzyme filter from the I/L matching feature itself.elastase-trypsin-chymotrypsinwithProtein3=GGG·J·DTAYDDSGNSGGGG— aJflank, expected to match under both settings, withaa_before == 'J'.Both are verified non-vacuous by reverting each fix independently and watching the corresponding assertions fail (
accessions.count(...): got '0', expected '1') — theUnmatched peptidesymptom from #1793.No reference outputs needed regenerating:
TOPP_PeptideIndexer_10is the only test using-IL_equivalentand it passes against its checked-in reference, and no test or.inistores the enzyme regex (the.inifiles list the enzyme by name only).Also
PeptideIndexing.hclaimed thatIL_equivalent+write_protein_sequencesstores both sequence versions, "roughly equivalent to the size of the FASTA database file itself". That was already stale —write_protein_sequencere-reads the original entry viaproteins.readAt()— so the paragraph now describes what actually happens.Checklist
PeptideIndexing_test,ProteaseDB_test,EnzymaticDigestion_test,ProteaseDigestion_test,AhoCorasickAmbiguous_test,PeptideEvidence_testand all 27TOPP_PeptideIndexer_*tests: 33/33 pass (Ubuntu 24.04, g++ 13, Release)PeptideIndexingis bound insrc/pyOpenMS/bindings/bind_misc.cpp, but no binding change is needed: this is a behaviour fix with no API change, and the binding docstring does not restate the I/L paragraph edited inPeptideIndexing.h🤖 Generated with Claude Code
https://claude.ai/code/session_014cwvmMpsfDb9mD7JwivuuR
Summary by CodeRabbit