Skip to content

Feature: Add SRM support in OpenSwathWorkflow - #8700

Merged
timosachsenberg merged 75 commits into
OpenMS:developfrom
singjc:feat/osw_srm
Jan 29, 2026
Merged

timosachsenberg merged 75 commits into
OpenMS:developfrom
singjc:feat/osw_srm

Conversation

@singjc

@singjc singjc commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

This pull request introduces a new abstraction layer for chromatogram handling in the OpenSwath workflow, for more flexible and modular support for different data types (SRM/MRM, DIA/SWATH). It adds a set of new handler classes, interfaces, and overloads, and updates the workflow and related APIs to use these abstractions.

Also updated the multi-input for separate mzML experiments (not just split mzMLs), so you can process multiple mzMLs in the same command.

I think there could be more abstractions/refactoring, but to avoid this PR from getting larger than it is, we can look at that in a separate PR. I think this current one should be a good initial start for adding SRM support to begin with.

Chromatogram Handling Abstraction

  • Introduced the IChromatogramHandler abstract interface for chromatogram handling, with methods for collecting iRT chromatograms and extracting/mapping chromatograms for transitions. Includes a static factory for creating the default handler. (src/openms/include/OpenMS/ANALYSIS/TARGETED/IChromatogramHandler.h)
  • Added concrete handler implementations: SRMChromHandler for SRM/MRM data, DIAChromHandler for DIA/SWATH/PRM data, and DefaultChromHandler which delegates to the appropriate handler based on input. (src/openms/include/OpenMS/ANALYSIS/TARGETED/SRMChromHandler.h, src/openms/include/OpenMS/ANALYSIS/TARGETED/DIAChromHandler.h, src/openms/include/OpenMS/ANALYSIS/TARGETED/DefaultChromHandler.h) [1] [2] [3]

OpenSwath Workflow and API Updates

  • Updated OpenSwathWorkflow and related classes to use the new chromatogram handler abstraction, including support for a new srm_ flag, additional parameters (such as mrm_mapping_param), and extended method signatures to allow handler injection and configuration. (src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathWorkflow.h) [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Added a convenience overload to MRMMapping to accept OpenSwath::LightTargetedExperiment directly, improving usability for OpenSwath workflows. (src/openms/include/OpenMS/ANALYSIS/TARGETED/MRMMapping.h)

Helper and Utility Additions

  • Added ChromatogramProcessor helper class to encapsulate feature finding and scoring on chromatogram inputs, simplifying RT normalization and related tasks. (src/openms/include/OpenMS/ANALYSIS/TARGETED/ChromatogramProcessor.h)

Bugfixes and Minor Improvements

  • Added a const-qualified template specialization for ChromatogramExtractor::extract_id_ to avoid linker errors when using both const and non-const versions. (src/openms/include/OpenMS/ANALYSIS/OPENSWATH/ChromatogramExtractor.h)
  • Improved member initialization and method signatures in OpenSwathOSWWriter, and added new methods for run management. (src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathOSWWriter.h) [1] [2]

Include Order and Forward Declarations

  • Reorganized and clarified include order and forward declarations throughout the codebase for improved clarity and build efficiency. (src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathWorkflow.h, src/openms/include/OpenMS/ANALYSIS/TARGETED/MRMMapping.h) [1] [2] [3]

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).

Summary by CodeRabbit

  • New Features

    • SRM/MRM support in OpenSwathWorkflow for chromatogram-only inputs, with per-run processing and calibration.
    • New MRM mapping parameters and a unified chromatogram-handler framework for SRM vs DIA extraction.
    • Run management for OSW outputs (register/update runs) and per-run artifact handling.
    • Automatic targeted file loader that detects SRM vs DIA inputs.
  • Tests

    • Extensive unit and integration tests for new handlers, loaders, and SRM workflows.

✏️ Tip: You can customize this high-level summary in your review settings.

singjc added 30 commits January 22, 2026 21:23
…RM chrom to transition mapping is handled in separate module using MRMMapper
…nforce iRT mapping failure as fatal

Moved previously file-local helper logic into SRMChromHandler methods to reduce indirection and translation units.

Details:
- Inlined collectChromatogramsForIrt_internal and extractAndMapChromatogramsForTransitions_internal into SRMChromHandler implementations.
- Use non-verbose Param::update when applying MRMMapping parameters to avoid noisy default-override messages.
- Treat MRMMapping failures during iRT collection as fatal: log an ERROR and throw Exception::MissingInformation so the workflow aborts early rather than continuing with unmapped iRT chromatograms.
- During transition extraction, if MRMMapping throws, log a warning and continue to the isolation-window fallback mapping (do not return early).

This keeps iRT calibration strict while allowing robust fallback during regular transition mapping.
…erface

Expanded the Doxygen documentation for IChromatogramHandler to clarify responsibilities, error policies, and factory semantics. This helps future maintainers and clarifies why target-specific mapping lives in the handler/provider layer.
…hWorkflow.h

Scanned OpenSwathBase.cpp and confirmed FileHandler is still included and used in implementation files (loadTransitions, loadTransformations, getTypeByFileName etc.). Removing the debug-only include from the public header reduces header surface area and compilation coupling while preserving functionality in implementation files.
…andler interface and ChromatogramProcessor class
…oring on chromatogram inputs

chore(OpenSwathWorkflow): clean up debug logging and improve log clarity
…OSW and sqMass; wire per-file run_id for extraction

Add multi-run plumbing so multiple independent input experiment files (multiple mzML / SRM inputs)
can be processed into a single OSW and a single sqMass while preserving per-file RUN bookkeeping.
New/changed APIs:
Internal::MzMLSqliteHandler::setRunId(UInt64) — allow changing the run id used by the sqMass handler at runtime.
MSDataSqlConsumer::addRun(const String & filename, UInt64 run_id) — insert a RUN entry into the sqMass and mark that a run has been written.
MSDataSqlConsumer::setRunId(UInt64) — change the current run id used for subsequent chromatogram/spectrum writes.
Guard MSDataSqlConsumer destructor to avoid writing a duplicate RUN row if runs were already registered via addRun.
OpenSwathOSWWriter was previously extended (header change) to allow multi-run registration (addRun, setRunId); the workflow is now wired to use it.
Workflow wiring:
OpenSwathWorkflow.cpp:
Register a unique run_id per unique input filename and call oswwriter.addRun(run_id, filename).
When a sqMass consumer is in use, call MSDataSqlConsumer::addRun(...) as well so the sqMass gets RUN entries.
Before extracting each group's swath maps (grouped by originating filename via swath_map_sources), set the current run id in both the OSW writer and the sqMass consumer (setRunId) so FEATURES and CHROMATOGRAM rows are written with the correct RUN_ID.
Behavioral effect:
Multiple input experiment mzMLs are treated as independent runs, can be processed in a single tool invocation, and the resulting .osw and .sqMass will contain one RUN row per input file with features/chromatograms linked to the proper RUN_ID.
…umers and maintain deterministic ID sequence"

This reverts commit 364dc08.
…A data

- Added support for SRM-specific processing in OpenSwathWorkflow, allowing the workflow to handle chromatogram-only data.
- Introduced a new boolean parameter `srm_` to indicate if the data is chromatogram-only SRM data.
- Updated constructors and methods across various handlers (DIAChromHandler, DefaultChromHandler, SRMHandler) to accept and utilize the new `TransformationDescription` parameter.
- Enhanced the `collectIrtChromatogramsForIrt` methods to accommodate the new transformation handling.
- Improved logging for empty chromatograms and mapping results in SRMHandler.
- Adjusted the OpenSwathWorkflow to detect chromatogram-only data during initialization and set the appropriate processing mode.
…etedDataFileLoader

- Implemented comprehensive tests for DefaultChromHandler to validate chromatogram collection and mapping functionalities, including edge cases for empty swath maps, no transitions, mismatched transitions, and invalid parameters.
- Created tests for SRMFile to ensure proper exception handling for file loading scenarios.
- Developed tests for SRMHandler to verify chromatogram normalization and extraction/mapping processes, including handling of partial matches and multiple chromatograms for a single transition.
- Added tests for TargetedDataFileLoader to check for error handling with non-existent files, empty filenames, and invalid file extensions.
…plement associated changes

- Introduced SRMChromHandler class to handle SRM chromatograms.
- Updated references in OpenSwathWorkflow and other source files to use SRMChromHandler.
- Added unit tests for SRMChromHandler to ensure functionality.
- Added MRMChromHandler class to manage MRM chromatograms, including normalization of m/z values and mapping chromatograms to transitions.
- Implemented MRMFile class for loading MRM mzML files and normalizing chromatogram data.
- Updated TargetedDataFileLoader to utilize MRMFile for chromatogram-only mzML files.
- Refactored existing SRM references to MRM where applicable for consistency.
- Added unit tests for MRMChromHandler and MRMFile to ensure functionality and correctness.
- Updated OpenSwathWorkflow to detect MRM mode in addition to SRM.
…g and continuing on InvalidRange and IllegalArgument exceptions
@singjc

singjc commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@jcharkow

Wow great work, exciting that you got this working! The one major comment is that it would be good to be consistent with usage of SRM/MRM. I'm not sure if we can get an AI to just rename all instances of SRM to MRM or visa versa just for consistency.

I renamed everything to MRM for consistency.

Taking a step back, I'm assuming that you already thought more about why it is better to incorporate it into OpenSWATHWorkflow rather than create a standalone tool.

Probably for maintainability one tool is better but there does seem to be a bit of a disconnect in the workflows. I think the main difference between them is SRM does not need extraction while DIA does? Am I missing anything else? E.g. Is all of the RT calibration still relevant? I guess iRT calibration is still needed but it is probably a lot simpler than DIA.

Yes, it will be easier for maintaining and updating one tool, which can be seen with the other separated OpenSwath(Analyzer/DIAPreScoring/RTNormalizer). Some of these have not be updated alongside OpenSwathWorkflow, so some of them don't have all of the features that the full OpenSwathWorkflow tool has.

I was also just thinking of the end-user, who would usually look for a single tool for whatever targeted data (SRM/MRM/PRM/DIA) they have.

iRT calibration is still used for RT, mz and Im calibration is not applicable because we already have extracted chromatograms with SRM/PRM

@timosachsenberg what is your opinion on multiple tools vs one tool. I believe you mentioned previously that having one big tool is better from your previous experience with QuantMS?

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@src/openms/include/OpenMS/ANALYSIS/TARGETED/IChromatogramHandler.h`:
- Around line 10-13: Remove the unnecessary include of MRMMapping.h from
IChromatogramHandler.h: the header <OpenMS/ANALYSIS/TARGETED/MRMMapping.h> is
not used (no MRMMapping symbol appears in IChromatogramHandler) so delete that
include line and ensure remaining includes (e.g., MSChromatogram.h,
TransformationDescription.h, <memory>) still satisfy all referenced symbols and
Param usage in the IChromatogramHandler interface.

In `@src/openms/include/OpenMS/FORMAT/MRMFile.h`:
- Around line 21-33: Add pybind-style .pxd bindings for the new public API
structs so Python can see MRMFile and TargetedDataFileLoader: create .pxd
binding files mirroring the existing pattern used for
SwathFile/TraMLFile/MzMLFile, declare the structs MRMFile and
TargetedDataFileLoader with OPENMS_DLLAPI exposure, and expose their load
methods that return std::vector<::OpenSwath::SwathMap> (make sure
::OpenSwath::SwathMap is declared/imported in the .pxd). Ensure the signatures
match the C++ declarations (e.g., MRMFile::loadMzML and the
TargetedDataFileLoader load methods) so pyOpenMS builds and Python can call
them.

In `@src/openms/source/ANALYSIS/TARGETED/MRMChromHandler.cpp`:
- Around line 44-52: The empty catch blocks around parsing of precursor and
product m/z (the block that reads prec_mz from
it->second[0].getValue().toString().toDouble(), sets Precursor p =
chrom.getPrecursor(); p.setMZ(prec_mz); chrom.setPrecursor(p), and the analogous
product-m/z block) silently swallow errors—change them to catch std::exception&
(or catch (...) then rethrow/log) and log the failure with context (include the
raw string value and the exception.what() if available) using the project's
logging facility before continuing so parsing errors are visible for debugging;
apply the same fix to the product m/z parsing block as well.
- Around line 148-151: The code unconditionally forces
map_multiple_assays="true" after merging parameters, which overrides any user
setting in mrm_mapping_param; change the logic in the block around
mapper.getParameters()/mrm_p.update(...) so that you only set
mrm_p.setValue("map_multiple_assays","true") when the user did not explicitly
provide that key in mrm_mapping_param (i.e., check for existence of
"map_multiple_assays" in mrm_mapping_param before overriding), otherwise leave
the user-provided value intact, then call mapper.setParameters(mrm_p).
🧹 Nitpick comments (11)
src/openms/include/OpenMS/FORMAT/MRMFile.h (1)

11-15: Include <vector> explicitly for std::vector usage.

Line 31 uses std::vector but the header doesn’t include <vector>, which risks transitive-include breakage.

🔧 Proposed fix
 `#include` <OpenMS/OPENSWATHALGO/DATAACCESS/SwathMap.h>
 `#include` <OpenMS/DATASTRUCTURES/String.h>
 `#include` <OpenMS/METADATA/ExperimentalSettings.h>
 `#include` <memory>
+#include <vector>
src/openms/source/FORMAT/MRMFile.cpp (1)

26-27: Replace std::endl with '\n' in logging.

Line 26 uses std::endl, which flushes unnecessarily.

🔧 Proposed fix
-  OPENMS_LOG_INFO << "Loading SRM/MRM mzML " << file << std::endl;
+  OPENMS_LOG_INFO << "Loading SRM/MRM mzML " << file << '\n';

As per coding guidelines, avoid std::endl; prefer \n for better performance in logging and output operations.

src/openms/include/OpenMS/FORMAT/TargetedDataFileLoader.h (1)

11-29: Use full Doxygen @brief/@param blocks and add <vector>.

Public API docs should use the standard Doxygen format, and std::vector should be explicitly included.

🔧 Proposed fix
 `#include` <OpenMS/OPENSWATHALGO/DATAACCESS/SwathMap.h>
 `#include` <OpenMS/DATASTRUCTURES/String.h>
 `#include` <OpenMS/METADATA/ExperimentalSettings.h>
 `#include` <memory>
+#include <vector>
 
 namespace OpenMS
 {
   namespace Interfaces { class IMSDataConsumer; }
 
-  /// Dispatcher that detects whether an mzML contains spectra (SWATH/DIA)
-  /// or chromatograms only (SRM/MRM) and forwards to the appropriate loader.
-  struct OPENMS_DLLAPI TargetedDataFileLoader
-  {
-    /// Load a file and return Swath maps (may represent chromatogram-only SRM/MRM data)
-    static std::vector<::OpenSwath::SwathMap> loadFile(const String& file,
-                                                      const String& tmp,
-                                                      std::shared_ptr<ExperimentalSettings>& exp_meta,
-                                                      const String& readoptions,
-                                                      Interfaces::IMSDataConsumer* plugin_consumer = nullptr);
-  };
+  /**
+    `@brief` Dispatcher that detects whether an mzML contains spectra (SWATH/DIA) or
+    chromatograms only (SRM/MRM) and forwards to the appropriate loader.
+
+    Selects the loader based on mzML content type.
+  */
+  struct OPENMS_DLLAPI TargetedDataFileLoader
+  {
+    /**
+      `@brief` Load a file and return Swath maps (may represent chromatogram-only SRM/MRM data).
+
+      `@param`[in] file Input mzML file.
+      `@param`[in] tmp Temporary directory (for cached data).
+      `@param`[out] exp_meta Experimental settings extracted from the file.
+      `@param`[in] readoptions Loader read options string.
+      `@param`[in] plugin_consumer Optional consumer plugin.
+      `@return` Swath maps.
+    */
+    static std::vector<::OpenSwath::SwathMap> loadFile(const String& file,
+                                                      const String& tmp,
+                                                      std::shared_ptr<ExperimentalSettings>& exp_meta,
+                                                      const String& readoptions,
+                                                      Interfaces::IMSDataConsumer* plugin_consumer = nullptr);
+  };

As per coding guidelines, add Doxygen comments for new public methods/classes and use @brief with @param tags.

src/tests/class_tests/openms/source/MRMFile_test.cpp (1)

23-33: Consider adding a positive test case with valid SRM/MRM data.

The test only covers exception scenarios (non-existent file, empty filename). For comprehensive coverage of the new MRMFile::loadMzML API, consider adding a test with a valid SRM/MRM mzML file that verifies:

  • Successful loading returns non-empty SwathMap vector
  • exp_meta is populated correctly
  • Chromatograms are normalized (precursor/product m/z set)

This would require adding a small test data file to src/tests/class_tests/libs/data/ prefixed with MRMFile_. As per coding guidelines, test data files should be placed in that directory and prefixed with the class name.

src/tests/class_tests/openms/source/MRMChromHandler_test.cpp (1)

145-146: Consider using OpenMS logging macros for debug output.

The std::cout statements (lines 145, 204, 262, 363, 445) are useful for debugging but could use OPENMS_LOG_INFO for consistency with OpenMS logging patterns. However, this is minor for test files.

src/openms/include/OpenMS/ANALYSIS/TARGETED/MRMChromHandler.h (2)

62-63: Remove redundant blank line before closing brace.

Static analysis indicates a redundant blank line at line 62.

🔧 Proposed fix
   static void normalizeChromatogramMZ(MSChromatogram& chrom);
-
 };

14-16: Consider forward-declaring ChromExtractParams to reduce header coupling.

Including OpenSwathWorkflow.h is heavy. Since ChromExtractParams is passed by const reference, a forward declaration would suffice in the header, with the full include moved to MRMChromHandler.cpp.

♻️ Suggested change
-// Need ChromExtractParams (defined in OpenSwathWorkflow.h)
-#include <OpenMS/ANALYSIS/OPENSWATH/OpenSwathWorkflow.h>
 `#include` <OpenMS/DATASTRUCTURES/Param.h>
+
+namespace OpenMS { struct ChromExtractParams; }

Then add the full include in MRMChromHandler.cpp.

src/openms/source/ANALYSIS/TARGETED/MRMChromHandler.cpp (1)

182-184: Unused parameter cast to void is a code smell.

Instead of casting cp to void, consider either using the parameter or removing it from the signature if it's truly not needed for SRM/MRM mode.

💭 Consider documenting why the parameter is unused
-    // cp parameter is not used in SRM/MRM handler as it works with pre-existing chromatograms
-    (void)cp;
+    // ChromExtractParams (cp) is intentionally unused in SRM/MRM handler because
+    // SRM/MRM operates on pre-extracted chromatograms from the instrument,
+    // not on raw spectra that require extraction windows.
+    (void)cp;

Alternatively, if this is a polymorphic interface requirement, document it in the interface.

src/topp/OpenSwathWorkflow.cpp (2)

1488-1502: Duplicate dynamic_cast to MSDataSqlConsumer.

Lines 1489-1493 and 1498-1502 perform the same dynamic_cast<MSDataSqlConsumer*>(chromatogramConsumer) and null check. Consider consolidating:

♻️ Proposed consolidation
-    // Also register run in chromatogram consumer if it is a SQL consumer
-    MSDataSqlConsumer* sql_cons = dynamic_cast<MSDataSqlConsumer*>(chromatogramConsumer);
-    if (sql_cons != nullptr)
-    {
-      sql_cons->addRun(current_run_files[0], cur_run);
-    }
-
-    // set current run id in writer
-    oswwriter.setRunId(cur_run);
-    // set current run id for sqMass writer as well
-    MSDataSqlConsumer* sql_cons2 = dynamic_cast<MSDataSqlConsumer*>(chromatogramConsumer);
-    if (sql_cons2 != nullptr)
-    {
-      sql_cons2->setRunId(cur_run);
-    }
+    // set current run id in writer
+    oswwriter.setRunId(cur_run);
+    
+    // Register and set run ID for SQL consumer if applicable
+    MSDataSqlConsumer* sql_cons = dynamic_cast<MSDataSqlConsumer*>(chromatogramConsumer);
+    if (sql_cons != nullptr)
+    {
+      sql_cons->addRun(current_run_files[0], cur_run);
+      sql_cons->setRunId(cur_run);
+    }

1136-1167: File basename extraction could use File::removeExtension helper if available.

The manual substring extraction for basename and extension handling works but could potentially be simplified using OpenMS file utilities if they exist.

src/openms/source/APPLICATIONS/OpenSwathBase.cpp (1)

57-59: Consider extracting repeated source-population pattern.

The pattern of clearing and populating swath_map_sources with the same filename is repeated multiple times. Consider a small helper to reduce duplication:

♻️ Suggested helper extraction
// Helper to fill swath_map_sources with the same filename for all maps
inline void fillSourcesWithSingleFile(std::vector<String>& sources, 
                                       Size count, 
                                       const String& filename)
{
  sources.clear();
  sources.assign(count, filename);
}

Then replace repeated blocks like:

swath_map_sources.clear();
for (Size i = 0; i < swath_maps.size(); ++i) swath_map_sources.push_back(file_list[0]);

with:

fillSourcesWithSingleFile(swath_map_sources, swath_maps.size(), file_list[0]);

Also applies to: 112-113, 118-119, 124-125

@timosachsenberg

timosachsenberg commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

@jcharkow

Wow great work, exciting that you got this working! The one major comment is that it would be good to be consistent with usage of SRM/MRM. I'm not sure if we can get an AI to just rename all instances of SRM to MRM or visa versa just for consistency.

I renamed everything to MRM for consistency.

Taking a step back, I'm assuming that you already thought more about why it is better to incorporate it into OpenSWATHWorkflow rather than create a standalone tool.
Probably for maintainability one tool is better but there does seem to be a bit of a disconnect in the workflows. I think the main difference between them is SRM does not need extraction while DIA does? Am I missing anything else? E.g. Is all of the RT calibration still relevant? I guess iRT calibration is still needed but it is probably a lot simpler than DIA.

Yes, it will be easier for maintaining and updating one tool, which can be seen with the other separated OpenSwath(Analyzer/DIAPreScoring/RTNormalizer). Some of these have not be updated alongside OpenSwathWorkflow, so some of them don't have all of the features that the full OpenSwathWorkflow tool has.

I was also just thinking of the end-user, who would usually look for a single tool for whatever targeted data (SRM/MRM/PRM/DIA) they have.

iRT calibration is still used for RT, mz and Im calibration is not applicable because we already have extracted chromatograms with SRM/PRM

@timosachsenberg what is your opinion on multiple tools vs one tool. I believe you mentioned previously that having one big tool is better from your previous experience with QuantMS?

I often find one tool per method better. E.g. here it could make sense to have one for SRMWorkflow like IsobaricWorkflow , PRM, DIA etc. Breaking them down even further sometimes makes sense (e.g. for spreading to many nodes) but it is a bit more difficult to use and implies writing out and reading back in results even if they might fit in memory

@singjc

singjc commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

@jcharkow

Wow great work, exciting that you got this working! The one major comment is that it would be good to be consistent with usage of SRM/MRM. I'm not sure if we can get an AI to just rename all instances of SRM to MRM or visa versa just for consistency.

I renamed everything to MRM for consistency.

Taking a step back, I'm assuming that you already thought more about why it is better to incorporate it into OpenSWATHWorkflow rather than create a standalone tool.
Probably for maintainability one tool is better but there does seem to be a bit of a disconnect in the workflows. I think the main difference between them is SRM does not need extraction while DIA does? Am I missing anything else? E.g. Is all of the RT calibration still relevant? I guess iRT calibration is still needed but it is probably a lot simpler than DIA.

Yes, it will be easier for maintaining and updating one tool, which can be seen with the other separated OpenSwath(Analyzer/DIAPreScoring/RTNormalizer). Some of these have not be updated alongside OpenSwathWorkflow, so some of them don't have all of the features that the full OpenSwathWorkflow tool has.
I was also just thinking of the end-user, who would usually look for a single tool for whatever targeted data (SRM/MRM/PRM/DIA) they have.
iRT calibration is still used for RT, mz and Im calibration is not applicable because we already have extracted chromatograms with SRM/PRM

@timosachsenberg what is your opinion on multiple tools vs one tool. I believe you mentioned previously that having one big tool is better from your previous experience with QuantMS?

I often find one tool per method better. E.g. here it could make sense to have one for SRMWorkflow like IsobaricWorkflow , PRM, DIA etc. Breaking them down even further sometimes makes sense (e.g. for spreading to many nodes) but it is a bit more difficult to use and implies writing out and reading back in results even if they might fit in memory

I would be okay separating it out into a separate tool, but I think I would want to decouple/abstract some of the processing and chromatogram analysis logic from OpenSwathWorkflow, so it can be shared for generic chromatogram analysis stuff. I would do that in a separate PR though.

@jcharkow

Copy link
Copy Markdown
Collaborator

@jcharkow

Wow great work, exciting that you got this working! The one major comment is that it would be good to be consistent with usage of SRM/MRM. I'm not sure if we can get an AI to just rename all instances of SRM to MRM or visa versa just for consistency.

I renamed everything to MRM for consistency.

Taking a step back, I'm assuming that you already thought more about why it is better to incorporate it into OpenSWATHWorkflow rather than create a standalone tool.
Probably for maintainability one tool is better but there does seem to be a bit of a disconnect in the workflows. I think the main difference between them is SRM does not need extraction while DIA does? Am I missing anything else? E.g. Is all of the RT calibration still relevant? I guess iRT calibration is still needed but it is probably a lot simpler than DIA.

Yes, it will be easier for maintaining and updating one tool, which can be seen with the other separated OpenSwath(Analyzer/DIAPreScoring/RTNormalizer). Some of these have not be updated alongside OpenSwathWorkflow, so some of them don't have all of the features that the full OpenSwathWorkflow tool has.
I was also just thinking of the end-user, who would usually look for a single tool for whatever targeted data (SRM/MRM/PRM/DIA) they have.
iRT calibration is still used for RT, mz and Im calibration is not applicable because we already have extracted chromatograms with SRM/PRM

@timosachsenberg what is your opinion on multiple tools vs one tool. I believe you mentioned previously that having one big tool is better from your previous experience with QuantMS?

I often find one tool per method better. E.g. here it could make sense to have one for SRMWorkflow like IsobaricWorkflow , PRM, DIA etc. Breaking them down even further sometimes makes sense (e.g. for spreading to many nodes) but it is a bit more difficult to use and implies writing out and reading back in results even if they might fit in memory

I would be okay separating it out into a separate tool, but I think I would want to decouple/abstract some of the processing and chromatogram analysis logic from OpenSwathWorkflow, so it can be shared for generic chromatogram analysis stuff. I would do that in a separate PR though.

Sounds good, yes I think separating it out into a another tool may bloat this PR so I am in favour of merging and addressing that in a separate issue.

@jcharkow

Copy link
Copy Markdown
Collaborator

Another PR would be to see if we can remove some of the old TOPP tools in favour of this new interface.

@timosachsenberg

Copy link
Copy Markdown
Contributor

candidate for Januaries PR of the month ;)

@timosachsenberg
timosachsenberg enabled auto-merge (squash) January 29, 2026 17:33
@timosachsenberg
timosachsenberg merged commit b3a0225 into OpenMS:develop Jan 29, 2026
46 of 48 checks passed
khushiiagrawal pushed a commit to khushiiagrawal/OpenMS that referenced this pull request Feb 7, 2026
* feat(SRMHandler): implement SRMHandler for chromatogram collection and mapping

* feat(SRM): add SRMFile and TargetedDataFileLoader implementations for chromatogram handling

* feat(OpenSwathBase): integrate TargetedDataFileLoader for file loading

* feat(MRMMapping): add overload for mapping LightTargetedExperiment to TargetedExperiment

* feat(SRMHandler, OpenSwathWorkflow): add MRMMapping parameter support for chromatogram extraction and mapping

* feat(OpenSwathWorkflow): enhance SRMHandler integration for chromatogram extraction and mapping

* feat(MRMFeatureFinderScoring): revert code to original state, since SRM chrom to transition mapping is handled in separate module using MRMMapper

* feat(OpenSwathWorkflow): add MRMMapping parameter support for chromatogram mapping

* [TARGETED,FEATURE] Inline SRM helper logic into SRMChromHandler and enforce iRT mapping failure as fatal

Moved previously file-local helper logic into SRMChromHandler methods to reduce indirection and translation units.

Details:
- Inlined collectChromatogramsForIrt_internal and extractAndMapChromatogramsForTransitions_internal into SRMChromHandler implementations.
- Use non-verbose Param::update when applying MRMMapping parameters to avoid noisy default-override messages.
- Treat MRMMapping failures during iRT collection as fatal: log an ERROR and throw Exception::MissingInformation so the workflow aborts early rather than continuing with unmapped iRT chromatograms.
- During transition extraction, if MRMMapping throws, log a warning and continue to the isolation-window fallback mapping (do not return early).

This keeps iRT calibration strict while allowing robust fallback during regular transition mapping.

* [TARGETED,DOC] Add detailed documentation to IChromatogramHandler interface

Expanded the Doxygen documentation for IChromatogramHandler to clarify responsibilities, error policies, and factory semantics. This helps future maintainers and clarifies why target-specific mapping lives in the handler/provider layer.

* [OPENSWATH,CHORE] Remove debug-only FileHandler include from OpenSwathWorkflow.h

Scanned OpenSwathBase.cpp and confirmed FileHandler is still included and used in implementation files (loadTransitions, loadTransformations, getTypeByFileName etc.). Removing the debug-only include from the public header reduces header surface area and compilation coupling while preserving functionality in implementation files.

* feat(SRMHandler): refactor SRM handling by introducing IChromatogramHandler interface and ChromatogramProcessor class

* feat(ChromatogramProcessor): add new class for feature finding and scoring on chromatogram inputs
chore(OpenSwathWorkflow): clean up debug logging and improve log clarity

* (feat,openswath): Write multi-run support: register multiple RUNs in OSW and sqMass; wire per-file run_id for extraction

Add multi-run plumbing so multiple independent input experiment files (multiple mzML / SRM inputs)
can be processed into a single OSW and a single sqMass while preserving per-file RUN bookkeeping.
New/changed APIs:
Internal::MzMLSqliteHandler::setRunId(UInt64) — allow changing the run id used by the sqMass handler at runtime.
MSDataSqlConsumer::addRun(const String & filename, UInt64 run_id) — insert a RUN entry into the sqMass and mark that a run has been written.
MSDataSqlConsumer::setRunId(UInt64) — change the current run id used for subsequent chromatogram/spectrum writes.
Guard MSDataSqlConsumer destructor to avoid writing a duplicate RUN row if runs were already registered via addRun.
OpenSwathOSWWriter was previously extended (header change) to allow multi-run registration (addRun, setRunId); the workflow is now wired to use it.
Workflow wiring:
OpenSwathWorkflow.cpp:
Register a unique run_id per unique input filename and call oswwriter.addRun(run_id, filename).
When a sqMass consumer is in use, call MSDataSqlConsumer::addRun(...) as well so the sqMass gets RUN entries.
Before extracting each group's swath maps (grouped by originating filename via swath_map_sources), set the current run id in both the OSW writer and the sqMass consumer (setRunId) so FEATURES and CHROMATOGRAM rows are written with the correct RUN_ID.
Behavioral effect:
Multiple input experiment mzMLs are treated as independent runs, can be processed in a single tool invocation, and the resulting .osw and .sqMass will contain one RUN row per input file with features/chromatograms linked to the proper RUN_ID.

* feat(OpenSwathWorkflow): enhance RUN ID handling for SQL consumers and maintain deterministic ID sequence

* Revert "feat(OpenSwathWorkflow): enhance RUN ID handling for SQL consumers and maintain deterministic ID sequence"

This reverts commit 364dc08.

* feat(OpenSwathWorkflow): add sqMassRunID to output test for OpenSwathWorkflow

* feat(OpenSwathWorkflow): enhance MS1 extraction handling for chromatograms

* feat(OpenSwathWorkflow): implement DIA and Default chromatogram handlers for improved chromatogram extraction

* feat(OpenSwathWorkflow): enhance chromatogram handling for SRM and DIA data

- Added support for SRM-specific processing in OpenSwathWorkflow, allowing the workflow to handle chromatogram-only data.
- Introduced a new boolean parameter `srm_` to indicate if the data is chromatogram-only SRM data.
- Updated constructors and methods across various handlers (DIAChromHandler, DefaultChromHandler, SRMHandler) to accept and utilize the new `TransformationDescription` parameter.
- Enhanced the `collectIrtChromatogramsForIrt` methods to accommodate the new transformation handling.
- Improved logging for empty chromatograms and mapping results in SRMHandler.
- Adjusted the OpenSwathWorkflow to detect chromatogram-only data during initialization and set the appropriate processing mode.

* feat(OpenSwathBase): add consistency check for input file types in SWATH loading

* feat(SRMFile, TargetedDataFileLoader): update log messages for clarity in mzML loading

* feat(SRMChromHandler): add normalizeChromatogramMZ utility function for m/z normalization

* add,tests: OpenSwathWorfklow SRM inputs (multi)

* feat(OpenSwathWorkflow): refine SRM mode detection and streamline m/z window application logic

* feat(SRMChromHandler): add OPENMS_DLLAPI specifier for SRMChromHandler class

* feat(DIAChromHandler, DefaultChromHandler): add OPENMS_DLLAPI specifier for improved visibility

* feat(ChromatogramProcessor, SRMFile): add OPENMS_DLLAPI specifier for improved visibility

* Add unit tests for DefaultChromHandler, SRMFile, SRMHandler, and TargetedDataFileLoader

- Implemented comprehensive tests for DefaultChromHandler to validate chromatogram collection and mapping functionalities, including edge cases for empty swath maps, no transitions, mismatched transitions, and invalid parameters.
- Created tests for SRMFile to ensure proper exception handling for file loading scenarios.
- Developed tests for SRMHandler to verify chromatogram normalization and extraction/mapping processes, including handling of partial matches and multiple chromatograms for a single transition.
- Added tests for TargetedDataFileLoader to check for error handling with non-existent files, empty filenames, and invalid file extensions.

* feat(SRMChromHandler): replace SRMHandler with SRMChromHandler and implement associated changes

- Introduced SRMChromHandler class to handle SRM chromatograms.
- Updated references in OpenSwathWorkflow and other source files to use SRMChromHandler.
- Added unit tests for SRMChromHandler to ensure functionality.

* refactor(MRMFeatureFinderScoring): reorder parameter setting for m/z extraction windows

* feat(OpenSwathWorkflow): add debug output for iRT chromatograms and handle file creation errors

* Refactor OpenSwathWorkflow and related components for improved logging and error handling

- Changed logging level from INFO to DEBUG for sampling priority peptides and successfully sampled peptides in OpenSwathHelper.cpp.
- Updated OpenSwathWorkflow.cpp to enhance error handling for missing chromatograms in SRM mode, throwing exceptions instead of skipping.
- Removed redundant counters and logging in OpenSwathWorkflow.cpp to reduce noise and improve clarity.
- Adjusted logging messages in SRMChromHandler.cpp to provide clearer information on mapped chromatograms.
- Refactored the OpenSwathWorkflow to streamline file processing, ensuring unique output filenames for multiple input files.
- Enhanced the calibration process by ensuring proper handling of linear and nonlinear iRT transformations, with detailed logging for each step.

* feat(OpenSwathWorkflow): add MRM mapping parameters and update related functionality

* refactor(OpenSwathWorkflow): remove mz-extraction tolerance propagation from feature-finder parameters

* feat(OpenSwathWorkflow): add SRM support

* fix(TargetedDataFileLoader): add OPENMS_DLLAPI to TargetedDataFileLoader struct

* fix(TargetedDataFileLoader_test): update exception type for empty filename and invalid file extension tests

* fix(DIAChromHandler, SRMChromHandler): clarify unused parameters in chromatogram extraction methods

* fix(DefaultChromHandler): add exception handling for SRM and DIA chromatogram collection and extraction

* fix(OpenSwathWorkflow): add SRM parameter to extraction methods and clean up function signatures

* fix(ChromatogramExtractor): remove redundant const_cast in extract_id_ method

* fix(IChromatogramHandler): add OPENMS_DLLAPI to class declaration for proper DLL export

* fix(MRMMapping): add overload for mapping chromatograms using LightTargetedExperiment

* fix(MzMLSqliteHandler): add documentation for setRunId method

* fix(TargetedDataFileLoader): remove redundant ExperimentalSettings class declaration

* fix(SRMFile): enhance documentation for SRM file loader and loadMzML method

* fix(MRMFeatureFinderScoring): remove unused cstdio include

* fix(OpenSwathOSWWriter): store run_id after inserting into RUN table

* fix(TargetedDataFileLoader): adjust indentation for improved code readability

* fix(OpenSwathWorkflow): remove redundant MS1 extraction logic for clarity

* fix(DefaultChromHandler): add null check for sm.sptr in chromatogram mode determination

* fix(OpenSwathWorkflow): remove redundant comments related to peakgroup file output

* fix(SRMChromHandler): remove legacy nativeID parsing in favor of CV terms for SRM mzML data

* fix(OpenSwathWorkflow): remove unused chromatogram m/z caching logic for clarity

* fix(OpenSwathOSWWriter): refactor SQL insertion to use prepared statements for improved security

* fix(OpenSwathWorkflow): implement run grouping logic for processing multiple input files

* fix(OpenSwathWorkflow): add tests for split DIA input files functionality

* fix(OpenSwathWorkflow): enhance error logging for SWATH file loading failures

* fix(DefaultChromHandler): improve error handling by throwing exceptions on failures

* fix(TargetedDataFileLoader): format code for improved readability

* fix(OpenSwathWorkflow): remove unused includes for cleaner code

* fix(DefaultChromHandler): improve error handling for SRM data by adding catch blocks for IllegalArgument exceptions

* rename: SRM -> MRM MRMChromHandler and MRMFile for MRM data handling

- Added MRMChromHandler class to manage MRM chromatograms, including normalization of m/z values and mapping chromatograms to transitions.
- Implemented MRMFile class for loading MRM mzML files and normalizing chromatogram data.
- Updated TargetedDataFileLoader to utilize MRMFile for chromatogram-only mzML files.
- Refactored existing SRM references to MRM where applicable for consistency.
- Added unit tests for MRMChromHandler and MRMFile to ensure functionality and correctness.
- Updated OpenSwathWorkflow to detect MRM mode in addition to SRM.

* refactor: rename SRM to MRM in OpenSwathWorkflow and DefaultChromHandler for consistency

* fix(OpenSwathWorkflow): update input documentation to clarify support for SRM/MRM/PRM/DIA mzML files

* fix(OpenSwathWorkflow): enhance error handling for MRM mode by logging and continuing on InvalidRange and IllegalArgument exceptions

* fix(OpenSwathWorkflow): update MRMMapping documentation to clarify support for SRM/MRM data

* fix(IChromatogramHandler): remove unnecessary MRMMapping include

* fix(MRMChromHandler): enhance error handling and logging for precursor m/z parsing

* feat: add MRMFile and TargetedDataFileLoader classes for SRM/MRM file handling

---------

Co-authored-by: Timo Sachsenberg <[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.

4 participants