Skip to content

Modified PeakPickerHiRes to address issue #5687 - #6781

Closed
alhigaylan wants to merge 0 commit into
OpenMS:developfrom
alhigaylan:develop
Closed

alhigaylan wants to merge 0 commit into
OpenMS:developfrom
alhigaylan:develop

Conversation

@alhigaylan

@alhigaylan alhigaylan commented Mar 14, 2023 •

Copy link
Copy Markdown
Collaborator

Description

#5687 Modified code to allow peak core lacking left or right neighbor peaks to be picked as well. Code passed PeakPickerHiRes_test and I applied it to the supplied test.mzML file from issue #5687 (see attached picture below).

I want feedback on how I handled spline bisection. From OpenMS 2013 pub "The bisection method is used to find the root of spline derivative. The root gives the m/z value of the peak's apex and thus the position of the centroid representing the peak; the value of the spline at this position yields the corresponding intensity value."

In cases where left or right neighbor peaks are missing, I considered creating a 'phantom' peak whose distance from central m/z peak is equal to the distance between existing core neighbor and central peak. I can then feed 'left_peak_mz', 'central_peak_mz', 'right_peak_mz' to Math::spline_bisection method.

This throws error because the introduced 'phantom' peak is outside the range of spline obtained from 'CubicSpline2d(peak_raw_data)'. I could try to include the phantom peak to the peak array 'peak_raw_data', but then how to handle its corresponding ion mobility array?

For now, I simply assign 'central_peak_mz' value to the missing 'left_peak_mz' or right_peak_mz' and then this gets passed to Math::spline_bisection method. It works because we are still within the spline range. Picture below shows I obtained a correct isotope mass. So is there a need to properly model symmetrical peak shape?

raw_isotope

Picked_isotope

To run PeakPickerHiRes on this data, you have to override centroid check and specify ms_levels. use -force and -algorithm:ms_level 1

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

}
// MZ spacing sanity checks
double left_to_central = 0.0, central_to_right = 0.0, min_spacing = 0.0;
bool no_left_neighbor = false, no_right_neighbor = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe inverse?
bool no_left_neighbor -> has_left_neighbor
could remove the double negations !no_...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me! I will revise these when I make an updated commit :)

@cbielow

cbielow commented Mar 15, 2023

Copy link
Copy Markdown
Contributor

very intersting solution. Thanks!
Just to be sure this works on all platforms and does not regress by future changes, could you please add a test in PeakPickerHiRes_test.cpp which uses the test.mzML to find the peaks in question.
Our current tests obviously do not capture the new behaviour and we should make sure that the algorithm keeps working as expected. Thanks again!

// We have to add a proper peak to peak_spline and have to decide what ion mobility value to assign to it.

// for now, simply replace mz value of missing neighbor with central mz peak.
left_neighbor_mz = (no_left_neighbor) ? central_peak_mz: left_neighbor_mz;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be fine.
What is repoted if report_FWHM is enabled?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double midpoint_deriv_val = peak_spline.derivative(mid);

with your solution now, it will start in the middle and probably move up to the top where the derivative gets close to zero and yield the correct result.
If you add a phantom peak it might error because it evaluates the derivative exactly at or slightly outside the peak range.

I think how you do it is fine with our implementation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be fine.
What is repoted if report_FWHM is enabled?

Here is a screenshot with the FWHM reported in ppm.

Screen Shot 2023-04-06 at 12 59 02 PM

@timosachsenberg

Copy link
Copy Markdown
Contributor

There seems to be some test failing because PeakPickerIterative (a tool from hannes) find more peaks:
https://cdash.seqan.de/test/49418916


Offending lines:			(tab_width = 8, first_column = 1)

in1:  /home/jenkins/ws/openms/PR/bldtst/79892110/build/src/tests/topp/PeakPickerIterative.mzML.tmp   (line: 159, position/column: 59/81)
			<spectrum id="scan=17359" index="0" defaultArrayLength="!
			                                                        6" dataProcessingRef="dp_sp_0">

in2:  /home/jenkins/ws/openms/PR/bldtst/79892110/source/src/tests/topp/PeakPickerIterative_1_output.mzML   (line: 159, position/column: 59/81)
			<spectrum id="scan=17359" index="0" defaultArrayLength="!
			                                                        3" dataProcessingRef="dp_sp_0">


Easy Access:
/home/jenkins/ws/openms/PR/bldtst/79892110/build/src/tests/topp/PeakPickerIterative.mzML.tmp:159:81:
/home/jenkins/ws/openms/PR/bldtst/79892110/source/src/tests/topp/PeakPickerIterative_1_output.mzML:159:81:

diff /home/jenkins/ws/openms/PR/bldtst/79892110/build/src/tests/topp/PeakPickerIterative.mzML.tmp /home/jenkins/ws/openms/PR/bldtst/79892110/source/src/tests/topp/PeakPickerIterative_1_output.mzML
FuzzyDiff took 0.00 s (wall), 0.00 s (CPU), 0.00 s (system), 0.00 s (user); Peak Memory Usage: 26 MB.

@timosachsenberg

Copy link
Copy Markdown
Contributor

@hroest or @alhigaylan can you check the test results / update the tests?

@alhigaylan

Copy link
Copy Markdown
Collaborator Author

There seems to be some test failing because PeakPickerIterative (a tool from hannes) find more peaks: https://cdash.seqan.de/test/49418916


Offending lines:			(tab_width = 8, first_column = 1)

in1:  /home/jenkins/ws/openms/PR/bldtst/79892110/build/src/tests/topp/PeakPickerIterative.mzML.tmp   (line: 159, position/column: 59/81)
			<spectrum id="scan=17359" index="0" defaultArrayLength="!
			                                                        6" dataProcessingRef="dp_sp_0">

in2:  /home/jenkins/ws/openms/PR/bldtst/79892110/source/src/tests/topp/PeakPickerIterative_1_output.mzML   (line: 159, position/column: 59/81)
			<spectrum id="scan=17359" index="0" defaultArrayLength="!
			                                                        3" dataProcessingRef="dp_sp_0">


Easy Access:
/home/jenkins/ws/openms/PR/bldtst/79892110/build/src/tests/topp/PeakPickerIterative.mzML.tmp:159:81:
/home/jenkins/ws/openms/PR/bldtst/79892110/source/src/tests/topp/PeakPickerIterative_1_output.mzML:159:81:

diff /home/jenkins/ws/openms/PR/bldtst/79892110/build/src/tests/topp/PeakPickerIterative.mzML.tmp /home/jenkins/ws/openms/PR/bldtst/79892110/source/src/tests/topp/PeakPickerIterative_1_output.mzML
FuzzyDiff took 0.00 s (wall), 0.00 s (CPU), 0.00 s (system), 0.00 s (user); Peak Memory Usage: 26 MB.

Ok so I had a discussion with Hannes and we could go about this in two ways: Either make this modified PeakPickerHiRes behavior an optional parameter or update output test for PeakPickerIterative to bypass this.

I took a look at PeakPickterIterative_1_input.mzML and output. To me the overall LC-MS map looks similar.

Raw PeakPickerIterative_1_input map
Screen Shot 2023-04-06 at 12 47 59 PM

Current PeakPickerIterative_1_output map

Screen Shot 2023-04-06 at 12 48 11 PM

PeakPickerIterative output when applying it to PeakPickerIterative_1_input.mzML in my modified OpenMS environment (modified PeakPickerHiRes)

Screen Shot 2023-04-06 at 12 48 22 PM

Since PeakPickerIterative is not commonly used, would updating the test files make sense? If problems occur in the future then we can this modified PeakPickerHiRes optional.

@timosachsenberg

Copy link
Copy Markdown
Contributor

I think updating the tests is fine. On first glance it looks like the old code finds more/better peaks (more consistent with the isotopic traces) though.

@jpfeuffer

Copy link
Copy Markdown
Contributor

To me, it looks like the new code finds more.

@alhigaylan

Copy link
Copy Markdown
Collaborator Author

I made a new commit with the following changes:

  1. Removed double negation from PeakPickerHiRes.
  2. Added new test file to test for PeakPickerHiRes new behavior. The new test is titled "PeakPickerHiRes_6_input/output.mzML"
  3. Swapped PeakPickterIterative_1_output.mzML with the new file generated in my new environment.

I also made a follow-up commit because I had a hiccup and deleted some code from CMakeList.txt file in the test directory. Hope I fixed my mess.

Also -- I think I was not properly testing PeakPickerHiRes system-wide. It seems like there are other tests that fail. Namely OpenSWATHWorkflow tests and PeakPickerHiRes. One ID_Mapper test failed too. I took a look at one of the failed PeakPickerHiRes tests and it seems like it is the same story as PeakPickerIterative test. The new code find more peaks and fails.

I am not sure about OpenSWATH and ID_Mapper test. I will have to take a more look into it.

Screen Shot 2023-04-16 at 11 12 23 PM

@timosachsenberg

Copy link
Copy Markdown
Contributor

I can give it a quick look

@timosachsenberg

Copy link
Copy Markdown
Contributor

I can confirm that I also get these failed tests. But to me it looks like it now reports less peaks???
e.g. the new output when applied in test 4

gitpod@alhigaylan-openms-6s4abodgb0g:/workspace/OpenMS/build$ grep "defaultArrayLength" /workspace/OpenMS/build/src/tests/topp/PeakPickerHiRes_4.tmp 
                        <chromatogram id="tr1" index="0" defaultArrayLength="2">
                        <chromatogram id="tr3" index="1" defaultArrayLength="3">
                        <chromatogram id="tr2" index="2" defaultArrayLength="1">
                        <chromatogram id="tr4" index="3" defaultArrayLength="2">
                        <chromatogram id="tr5" index="4" defaultArrayLength="2">

vs the old data:

gitpod@alhigaylan-openms-6s4abodgb0g:/workspace/OpenMS/build$ grep "defaultArrayLength" 
/workspace/OpenMS/src/tests/topp/PeakPickerHiRes_2_output.mzML
                        <chromatogram id="tr1" index="0" defaultArrayLength="2">
                        <chromatogram id="tr3" index="1" defaultArrayLength="4">
                        <chromatogram id="tr2" index="2" defaultArrayLength="1">
                        <chromatogram id="tr4" index="3" defaultArrayLength="2">
                        <chromatogram id="tr5" index="4" defaultArrayLength="3">

I think one should inspect test outputs manually and compare it to the old output (e.g., in TOPPView). Check that no strange behavior is introduced (e.g., lost peaks that should be pickerd) and decide if the new output is ok + update the tests.

@timosachsenberg

Copy link
Copy Markdown
Contributor

Especially as it seems to return less peaks from chromatograms (as opposed to the expected "more peaks").

@poshul

poshul commented Oct 25, 2023

Copy link
Copy Markdown
Collaborator

@alhigaylan can we take a look at this when I am in Toronto?

@alhigaylan alhigaylan closed this Nov 6, 2023
timosachsenberg added a commit to alhigaylan/diaWeaver that referenced this pull request Jan 15, 2026
Testing across all PeakPickerHiRes test datasets showed zero regression
on conventional instrument data (Orbitrap, FTMS, simulation). The
permissive behavior (allowing peaks with only one valid neighbor) is
now always enabled, which is essential for TimsTOF data support.

Resolves OpenMS#5687, OpenMS#6781

Co-Authored-By: Claude Opus 4.5 <[email protected]>
timosachsenberg added a commit that referenced this pull request Jan 16, 2026
…o leading flank peaks (#8649)

* modify ppHiRes to pick non-symmetrical peaks

* introduce tests for new hires param

* update TOPPWRITEINI_OVERWRITE test file

* Remove one_sided parameter, make permissive peak picking the default

Testing across all PeakPickerHiRes test datasets showed zero regression
on conventional instrument data (Orbitrap, FTMS, simulation). The
permissive behavior (allowing peaks with only one valid neighbor) is
now always enabled, which is essential for TimsTOF data support.

Resolves #5687, #6781

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Fix PeakPickerHiRes: make one_sided behavior opt-in via parameter

The one_sided logic (allowing peaks without flanks on both sides) was
being applied unconditionally, breaking existing tests. Now:
- Default (one_sided=false): require both left AND right neighbors (original behavior)
- one_sided=true: allow peaks with either left OR right neighbor (for TimsTOF data)

This preserves backward compatibility while adding the new functionality.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Rename parameter: one_sided -> allow_missing_flank

More descriptive name that clearly conveys the parameter's purpose:
allowing peaks that are missing data points on one side (flank).

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Reset contrib submodule to match develop

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Fix PeakPickerHiRes: guard bisection bounds adjustment with check_spacings

When check_spacings is false, has_left_neighbor and has_right_neighbor
remain at their initialized value of false. Without this guard, the
bisection range would collapse to a single point (central_peak_mz),
causing incorrect peak picking behavior.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Add comprehensive unit tests for allow_missing_flank parameter

Tests cover:
- Symmetric peak picking (should work regardless of setting)
- Peak with missing left flank (rejected when false, accepted when true)
- Peak with missing right flank (rejected when false, accepted when true)
- Ion mobility data handling with missing flank

Note: Both flanks cannot fail the spacing check simultaneously since
min_spacing is always the smaller of the two spacings.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Update WRITE_INI_OUT.ini for allow_missing_flank parameter

Regenerate test reference file to reflect parameter rename from
one_sided to allow_missing_flank with updated description.

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* Update src/tests/class_tests/openms/source/PeakPickerHiRes_test.cpp

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [TEST] Fix expected IM value in allow_missing_flank test

The test was expecting only core points (central + right neighbor) in
the ion mobility weighted average, but the algorithm also extends the
peak and includes the next point (100.08, 200, IM=1.4) because it meets
the spacing_difference_gap criteria.

Updated expected value: 1.2357 -> 1.27222 (= 1145/900)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: Mohammed AlHigaylan <[email protected]>
Co-authored-by: Timo Sachsenberg <[email protected]>
Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: timosachsenberg <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: timosachsenberg <[email protected]>
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.

5 participants