Skip to content

Fix: Improve validation in _handle_region_coords #1183

Open
vinitjain2005 wants to merge 3 commits intomalariagen:masterfrom
vinitjain2005:fix-region-validation
Open

Fix: Improve validation in _handle_region_coords #1183
vinitjain2005 wants to merge 3 commits intomalariagen:masterfrom
vinitjain2005:fix-region-validation

Conversation

@vinitjain2005
Copy link

Description:
This PR enhances the validation and error handling in the _handle_region_coords function, ensuring robust parsing of genomic region strings.

Changes Made:

  • Implemented strict regex validation for region format (contig:start-end)

  • Added type checking for the region input

  • Improved error messages for better debugging

  • Removed silent failure (None return) and replaced with explicit exceptions

  • Added logical validation:

    • Start position must be ≥ 1
    • End position must be ≥ start
  • Added validation to ensure the contig exists

  • Added boundary checks against contig length

Before vs After:

Before:

  • Weak regex validation
  • Allowed malformed inputs
  • Could return None silently
  • Limited error handling

After:

  • Strict format validation
  • Clear and descriptive error messages
  • No silent failures
  • Strong input validation

Testing:

  • Tested with valid input: "chr1:100-200"

  • Tested invalid inputs:

    • "chr1-100-200"
    • "chr1:abc-xyz"
    • "chr1:200-100"
  • All invalid cases now raise appropriate exceptions

Impact:
Improves reliability and prevents incorrect genomic region parsing, reducing the risk of downstream errors.

Related Issue:
Closes #1182

Github: @vinitjain2005

@vinitjain2005
Copy link
Author

vinitjain2005 commented Mar 22, 2026

@jonbrenas @tristanpwdennis please verify and merge the issue

Refactor error messages for clarity and consistency.
@vinitjain2005 vinitjain2005 requested a review from jonbrenas March 22, 2026 15:52
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.

Improve validation for genomic region parsing in _handle_region_coords

2 participants