Skip to content

Conversation

Alexander-Sol
Copy link
Contributor

Summary
This PR introduces two new classes to the EngineLayer namespace that provide a standardized way to represent precursor features and manage collections of unique precursors. These additions will be used in upcoming workflows that require deduplication of precursor lists (e.g., external decon pairing, MRM selected precursor handling).

Key Changes

  • Precursor class

    • Immutable representation of a precursor feature, storing:

      • MonoisotopicPeakMz
      • Mass
      • Charge
      • Intensity
      • EnvelopePeakCount
      • Optional FractionalIntensity
    • Constructor enforces initialization of all required fields.

  • PrecursorSet class

    • Maintains a collection of non-overlapping precursors, defined by a user-specified m/z tolerance.
    • Supports adding new precursors only if no equivalent precursor (within m/z tolerance) already exists in the set.
    • Implements IEnumerable<Precursor> for easy iteration.
    • Provides Add and ContainsEquivalent methods for controlled set membership.

Motivation
Currently, there is no unified way in MetaMorpheus to store and deduplicate precursors with m/z-based uniqueness rules. These classes encapsulate that logic in a reusable, testable form, enabling future features like:

  • Efficient merging of precursor lists from multiple sources.
  • Tolerance-aware filtering for external deconvolution results.
  • MRM precursor table handling without duplicate entries.

Next Steps

  • Integrate PrecursorSet into the GetMs2Scans workflow for per-scan precursor list construction.
  • Use Precursor and PrecursorSet in the new MRM and external decon features currently in development.

@Alexander-Sol Alexander-Sol requested a review from Copilot August 12, 2025 17:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces new infrastructure for managing precursor features with m/z tolerance-based deduplication in the MetaMorpheus engine. The implementation provides a foundation for upcoming workflows requiring unique precursor handling such as external deconvolution pairing and MRM precursor management.

Key changes include:

  • Introduction of an immutable Precursor record class to standardize precursor data representation
  • Implementation of a PrecursorSet class that maintains collections of unique precursors based on m/z tolerance
  • Comprehensive test coverage for both classes with edge cases and boundary conditions

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
MetaMorpheus/EngineLayer/PrecursorSet.cs Main implementation containing both Precursor record and PrecursorSet class with tolerance-based uniqueness logic
MetaMorpheus/EngineLayer/Precursor.cs Empty file that appears to be a placeholder
MetaMorpheus/Test/PrecursorSetTests.cs Comprehensive unit tests covering all functionality including tolerance checking, bucket management, and edge cases
MetaMorpheus/EngineLayer/Ms2ScanWithSpecificMass.cs Minor formatting change adding blank line
Comments suppressed due to low confidence (1)

@@ -0,0 +1 @@

Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

This file contains only a BOM character and appears to be a placeholder. If the Precursor record is defined in PrecursorSet.cs instead, this empty file should be removed to avoid confusion.

Suggested change


Copilot uses AI. Check for mistakes.

namespace EngineLayer
{
public record Precursor(double MonoisotopicPeakMz, int Charge, double Mass, double Intensity, int EnvelopePeakCount, double? FractionalIntensity = null);

Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

[nitpick] The Precursor record is defined in the same file as PrecursorSet. Consider moving it to its own file (Precursor.cs) for better organization and maintainability, especially since there's already a Precursor.cs file in the project.

Suggested change

Copilot uses AI. Check for mistakes.

return false;
}

integerKey = (int)Math.Round(precursor.MonoisotopicPeakMz * 100.0);
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

The magic number 100.0 for m/z scaling appears multiple times in the code. Consider extracting this as a named constant (e.g., private const double MZ_SCALE_FACTOR = 100.0) to improve maintainability and make the scaling factor more explicit.

Suggested change
integerKey = (int)Math.Round(precursor.MonoisotopicPeakMz * 100.0);
integerKey = (int)Math.Round(precursor.MonoisotopicPeakMz * MzScaleFactor);

Copilot uses AI. Check for mistakes.

Copy link

codecov bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 97.82609% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.64%. Comparing base (059cfc0) to head (b29d7ad).

Files with missing lines Patch % Lines
MetaMorpheus/EngineLayer/PrecursorSet.cs 97.82% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2553   +/-   ##
=======================================
  Coverage   96.63%   96.64%           
=======================================
  Files         158      159    +1     
  Lines       23854    23900   +46     
  Branches     3322     3330    +8     
=======================================
+ Hits        23052    23097   +45     
- Misses        797      798    +1     
  Partials        5        5           
Flag Coverage Δ
unittests 94.75% <96.66%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
MetaMorpheus/EngineLayer/PrecursorSet.cs 97.82% <97.82%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants