Skip to content

Possbility bug#1

Open
trishorts wants to merge 17 commits into
RayMSMS:PossbilityBugfrom
trishorts:PossbilityBug
Open

Possbility bug#1
trishorts wants to merge 17 commits into
RayMSMS:PossbilityBugfrom
trishorts:PossbilityBug

Conversation

@trishorts
Copy link
Copy Markdown

PR Changes Overview — ChildScanTolerance Fixes

Date: 2026-04-08
Branch: ChildScanTolerance
Based on: fixes_report.md review (fixes 001-031)
Scope: Critical and select maintenance fixes only


Summary

These changes fix several critical bugs in the low-resolution (ion trap) product mass tolerance feature introduced in PR smith-chem-wisc#2635. The core issues were:

  1. Wrong default fallbackProductMassTolerance_LowRes defaulted to a hardcoded AbsoluteTolerance(0.35) instead of inheriting from ProductMassTolerance, silently applying Da tolerance where ppm was expected.
  2. No auto-detection of low-res scans — callers had to manually pass isLowRes: true, and most didn't, causing ion trap scans to use the wrong (narrow) tolerance.
  3. Incorrect probability calculation — the p value for glycopeptide scoring used the wrong tolerance window for ion trap scans, inflating statistical confidence.
  4. GUI unit mismatch — the UI combo box showed "ppm" when the tolerance was null, but saving produced a Da value.
  5. Dead code / unnecessary overload — a 22-parameter forwarding overload added maintenance burden with no benefit.

Files Changed

1. MetaMorpheus/EngineLayer/CommonParameters.cs

Fix 001 (Critical) — Wrong default fallback for ProductMassTolerance_LowRes

Line Change
89 productMassTolerance_LowRes ?? new AbsoluteTolerance(0.35) changed to productMassTolerance_LowRes ?? ProductMassTolerance

When no explicit low-res tolerance is provided, it now inherits the resolved ProductMassTolerance value (default 20 ppm) instead of hardcoding 0.35 Da. This ensures backward compatibility — existing configs without a low-res setting behave identically to before the PR.


2. MetaMorpheus/EngineLayer/MetaMorpheusEngine.cs

Fix 002 (Critical) — Auto-detect low-res scans from analyzer metadata

Change Description
MatchFragmentIons signature Removed bool isLowRes = false parameter
MatchFragmentIons body Added bool isLowRes = IsLowResolutionScan(scan) auto-detection
MatchFragmentIonsOfAllCharges signature Removed bool isLowRes = false parameter
MatchFragmentIonsOfAllCharges body Added bool isLowRes = IsLowResolutionScan(scan) auto-detection
New method IsLowResolutionScan internal static helper that checks scan.TheScan.MzAnalyzer for IonTrap2D / IonTrap3D

This centralizes the low-res determination so every call site automatically gets the correct tolerance without needing to independently determine the scan type. The helper is internal static so it can be reused by GlycoSearchEngine and tests.


3. MetaMorpheus/EngineLayer/GlycoSearch/GlycoSearchEngine.cs

Fix 002 (Critical) — Remove manual isLowRes passing at child scan call site

Line Change
~335 Removed bool isIonTrapData = ... and isLowRes: isIonTrapData from MatchFragmentIons call (now auto-detected)

Fix 008 (Critical) — Parent scan p calculation uses wrong tolerance

Line Change
~326 Added var parentProductTolerance = IsLowResolutionScan(theScan) ? ...LowRes : ... before p calculation

Bug fix (build error from fix 002) — Stale isIonTrapData reference in child scan p calculation

Line Change
~358 Changed isIonTrapData to IsLowResolutionScan(childScan)

4. MetaMorpheus/GUI/TaskWindows/GlycoSearchTaskWindow.xaml.cs

Fix 013 (Critical) — UI combo box defaults to ppm when tolerance is null

Line Change
190 Added `task.CommonParameters.ProductMassTolerance_LowRes == null

When null, the combo box now defaults to "Da" (index 0), consistent with the save fallback behavior.

Fix 014 (Critical) — Save button hardcodes 0.35 Da fallback

Line Change
374 new AbsoluteTolerance(0.35) changed to ProductMassTolerance

The save fallback now inherits the user's configured product tolerance instead of hardcoding a Da value.

Fix 019 (Maintenance) — Updated CheckTaskSettingsValidity call site

Lines Change
264-268 Removed productMassTolerance_LowResTextBox.Text from positional arg smith-chem-wisc#3; added it as named arg productMassTolerance_LowRes: at end of call

Required by the signature change in TaskValidator.cs.


5. MetaMorpheus/GUI/Util/TaskValidator.cs

Fix 019 (Maintenance) — Remove dead overload, clean up signature

Change Description
Removed using Org.BouncyCastle.Tls Unused import
Deleted 22-parameter forwarding overload Entire method (~50 lines) that just forwarded to the 23-param version with null
Moved productMassTolerance_LowRes to end of signature Now an optional parameter with = null default

Existing 22-arg callers (XLSearch, Search, Calibrate, GPTMD task windows) continue to compile unchanged. The single caller that passes the low-res value (GlycoSearchTaskWindow) now uses a named argument.


6. MetaMorpheus/Test/GlycoSearchEngineTest.cs

Test updates — Aligned assertions with new default behavior

Test Change
TestLowResToleranceConstruction_Default (line 83) Now expects PpmTolerance(20) instead of AbsoluteTolerance(0.35)
TestLowResToleranceConstruction_Default2 (line 103) Now expects PpmTolerance(20) — TOML deserialization constructs with defaults before setting properties
TestLowResToleranceConstruction_Default2 (line 125) Written TOML round-trip: expects PpmTolerance(20)
LowRes_CalibrateAndSearch (line 330) Post-calibration: low-res retains original 20 ppm (calibration doesn't update it)
Removed isLowRes: true / isLowRes: false args Two call sites each — parameter no longer exists

Fixes Applied vs. Skipped

Fix Severity Status Reason
001 Critical Applied Wrong default fallback
002 Critical Applied Missing auto-detection
008 Critical Applied Parent scan p uses wrong tolerance
009 Critical Skipped Already covered by fix 008
011 Critical Skipped User decision — large new feature addition to FindNGlycan
013 Critical Applied UI combo box null handling
014 Critical Applied Save button hardcoded fallback
017 Critical Skipped Refactoring only, no active bug
019 Critical Applied Removed dead overload
005-031 (Major/Minor) Various Not yet reviewed Deferred to follow-up

Build & Test Status

  • All compilation errors resolved
  • All previously failing tests updated and passing

RayMSMS and others added 17 commits March 27, 2026 13:00
* Fix the bug by capping the p to 1

* add a tester to reach the line

* finish my unit test
* Added fragment params to common params

* Created UI control and view model for fragmentation parameters

* Updated Mzlib

* Update to fix toml read/write

* Update Mod parsing

* Fixed how ambiguity handles refragmentation

* mzlib update

* fixed mion loss annotations

* MetaDraw: DeconExploration Range Update

* MetaDraw: DeconExploration Range Update

* Custom M Ions: UI

* tempMzLib

* Obo update

* Updated obo and PtmListLoader

* Added M-Ion stuff in to metadraw

* mzlib

* Update test

* updated mzlib

* test changes

* Split M Ions

* MetaDraw: PlotModel Stat splitting by grouping property.

* Agent: GItignore

* Secondary axis

* grouping better

* fixed redundant addition

* fix bad test

* test

* MetaDrawSettingsTests

* Reduce grouping options

* remove unnecessary change

* plot  model stat tests

* decon testing

* decon plot testing

* Expand test coverage

* feat(FragmentationParams): add chemical formula column to M-Ion loss table

- Add ChemicalFormula property to MIonLossViewModel to expose formula string
- Add Chemical Formula column to the M-Ion losses DataGrid
- Rearrange FragmentationParamsControl layout:
  - Left column: Max Fragment Mass only
  - Right column: All checkboxes (Complementary, N/C Terminal, Internal, M-Ions)
  - Bottom section: GroupBox with evenly spaced buttons, DataGrid, and notes

* fix(FragmentationReanalysisViewModel): correct constructor parameter logic

Swap the parameter initialization blocks so that:
- When isProtein=true, use DigestionParams and SearchParameters (protein)
- When isProtein=false, use RnaDigestionParams and RnaSearchParameters (RNA)

Previously these were inverted, causing wrong fragmentation parameters
to be loaded based on the analyte type.

* fix(FragmentationReanalysis): include NeutralLoss in ion equality comparer

Add NeutralLoss to both Equals() and GetHashCode() methods so that
ions with different neutral losses (e.g., b5 with -80 Da loss vs b5
without loss) are treated as distinct. This preserves neutral loss
fragment ions from the original PSM during refragmentation.

* fix(FragmentationParamsControl): correct N/C-terminal checkbox bindings

Swap the XAML bindings so that:
- N-Terminal Ions checkbox binds to LeftSideFragmentIons (not RightSide)
- C-Terminal Ions checkbox binds to RightSideFragmentIons (not LeftSide)

This fixes the crossed bindings issue where selecting 'N-Terminal Ions'
was silently enabling C-terminal ion search and vice versa.

* fix(FragmentationParamsViewModel): preserve terminus flags in ReloadMIonLosses

- Capture current LeftSideFragmentIons/RightSideFragmentIons state and
  reconstruct the proper FragmentationTerminus to pass to DigestionParams
- Remove redundant selection restoration loop - LoadAvailableMIonLosses
  already restores selections from FragmentationParameters.MIonLosses
- This prevents silently resetting N/C-terminal ion flags to defaults
  when user reloads custom M-Ion losses

* fix(FragmentationReanalysisViewModel): add thread safety for static dictionary mutation

Add a static lock object and wrap the DissociationTypeCollection dictionary
writes and subsequent Fragment() calls to ensure thread safety when
multiple refragmentation operations run concurrently.

This prevents race conditions where concurrent calls could corrupt
the shared static dictionary state.

* fix(FragmentationParamsViewModel): branch on IsRnaMode for ReloadMIonLosses

CommonParameters constructor checks 'if (digestionParams is RnaDigestionParams)'
to select RNA vs protein defaults. Passing a protein DigestionParams in RNA mode
causes it to override the passed fragmentationParams with new FragmentationParams().

- Branch on IsRnaMode when constructing digestion params
- Add test ReloadMIonLosses_InRnaMode_PreservesRnaFragmentationParams to verify
  that ToFragmentationParams() returns RnaFragmentationParams after reload

* fix(locking products): custom products are now locked properly

* fix(mode change popup)
…r by scan's mass analyzer to determind the resolution
* redesign calibrate task window to mimic search task window

* allow modern search style calibration

* fasd

* some xaml stuff not sure this works

* internal review

* calibration task coverage

* response to review comments

* eliminate reflection from calibration tests

* Add .editorconfig with insert_final_newline = true

* Remove launchSettings.json (unrelated to this PR)

* Normalize trailing newlines per .editorconfig

* unit test coverage for exceptions in calibration task

* replace exception with messagebox

---------

Co-authored-by: MICHAEL SHORTREED <mrshortreed@wisc.edu>
* enable spectrum library calculation in non-specific search

* this test don't work

* ok i think this test work

* a better unit test

* major complaints dealt with

* Change PSM count assertion to check for greater than 30

---------

Co-authored-by: pcruzparri <43578034+pcruzparri@users.noreply.github.com>
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