Better regex validation - #239
Conversation
…tterns - Implemented _validate_regular_expressions function to check regex patterns in configuration. - Added tests for regex validation, covering valid, invalid, and edge cases. - Updated parse_psms and parse_spectra to apply ID patterns and handle errors accordingly.
There was a problem hiding this comment.
Pull Request Overview
Add stricter validation and application of regex patterns for PSM and spectrum IDs, with targeted exceptions and tests to prevent silent mismatches.
- Add _validate_regular_expressions to validate regex syntax and ensure exactly one capturing group.
- Apply psm_id_pattern early in parse_psms with invariant check on unique IDs; add spectrum ID remapping in parse_spectra with clearer configuration errors.
- Add tests covering valid/invalid regex patterns and ID mapping edge cases.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_parse_spectra.py | Adds factory and a new test for non-matching spectrum_id_pattern; updates expected exception types. |
| tests/test_parse_psms.py | New tests verifying psm_id_pattern extraction and uniqueness-invariance errors. |
| tests/test_config_parser.py | Adds tests for _validate_regular_expressions including valid, invalid, and edge cases. |
| ms2rescore/parse_spectra.py | Introduces _apply_spectrum_id_pattern and integrates it into _get_precursor_values; refines exception types and messages. |
| ms2rescore/parse_psms.py | Moves and strengthens psm_id_pattern handling with a uniqueness check; removes duplicate application later in the function. |
| ms2rescore/config_parser.py | Implements _validate_regular_expressions and wires it into parse_configurations; minor import adjustments. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Add validation and exception raising for PSM and spectrum ID regex patterns: