Skip to content

Conversation

@nh13
Copy link
Owner

@nh13 nh13 commented Dec 22, 2025

Summary

BED format uses 0-based, half-open intervals [start, end).
Changed length calculation from end - start + 1 to end - start.

Closes #102

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed BED file interval coordinate handling to comply with standard genomic conventions. This improves the accuracy of region length calculations, validation checks, and position processing across all genomic operations. The changes ensure consistent and precise handling of genomic intervals from BED file inputs throughout the application.

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 22, 2025

📝 Walkthrough

Walkthrough

Corrects BED interval length calculations across two files from inclusive end (end - start + 1) to half-open convention (end - start), aligning with BED 0-based coordinate system semantics in interval length and related position computations.

Changes

Cohort / File(s) Summary
BED interval calculation in simulator
src/dwgsim.c
Updated three occurrences of interval length computation from end - start + 1 to end - start: tot_len recalculation for regions_bed, accumulation of m for matching contig regions, and j calculation for pos-conditioned logic.
BED interval validation
src/regions_bed.c
Changed len calculation from end - start + 1 to end - start in validation logic; updated corresponding conditional check and warning message text to reflect half-open interval semantics.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Half-open intervals, now we've got it right,
BED coordinates gleaming in the morning light,
Start to end with proper math so true,
Fixing off-by-one bugs—hopping straight on through! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: correcting BED coordinate system calculation from inclusive to half-open intervals.
Linked Issues check ✅ Passed Changes correctly implement issue #102 requirements by replacing all occurrences of end - start + 1 with end - start in BED length calculations across both files.
Out of Scope Changes check ✅ Passed All changes are directly scoped to correcting BED interval calculations as required by issue #102; no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/bed-coordinate-system

Comment @coderabbitai help to get the list of available commands and usage tips.

BED format uses 0-based, half-open intervals [start, end).
Changed length calculation from `end - start + 1` to `end - start`.

Files fixed:
- regions_bed.c: length calculation and validation warning
- dwgsim.c: 3 occurrences of region length calculation

Closes #102

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nh13 nh13 force-pushed the fix/bed-coordinate-system branch from 5007b63 to e20b270 Compare December 25, 2025 03:49
@nh13
Copy link
Owner Author

nh13 commented Dec 25, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/dwgsim.c (1)

693-704: Remove the -1 adjustment from line 697 after BED length correction.

The position mapping formula on line 697 has an off-by-one error. With the corrected length calculation on line 695 (j = end - start), the -1 adjustment produces positions outside the valid BED region [start, end). Change line 697 from:

pos = regions_bed->start[i] + pos - 1; // zero-based

to:

pos = regions_bed->start[i] + pos;
🧹 Nitpick comments (1)
src/regions_bed.c (1)

81-83: Validation check appears to be dead code.

The condition if(end - start != len) should never be true since len = end - start is assigned on line 55, and underflow is prevented by the end < start check on lines 72-75. While the update to match the new BED calculation is correct, this validation block appears to be dead code that could optionally be removed in a future cleanup.

Optional: Remove unreachable validation
-    if(end - start != len) {
-        fprintf(stderr, "Warning: len != end - start [%s,%u,%u,%u]\n", name, start, end, len);
-    }
-    
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae9cd92 and e20b270.

📒 Files selected for processing (2)
  • src/dwgsim.c
  • src/regions_bed.c
🔇 Additional comments (3)
src/dwgsim.c (2)

496-503: Correct BED interval length calculation.

The change from end - start + 1 to end - start correctly implements BED's 0-based, half-open [start, end) convention. The inline comment clearly documents the semantics.


536-543: Correct BED interval length calculation for contig regions.

The change correctly applies BED half-open semantics when accumulating region lengths for a specific contig, consistent with the fix at line 501.

src/regions_bed.c (1)

54-56: Correct BED interval length calculation.

The change from end - start + 1 to end - start correctly implements BED's 0-based, half-open [start, end) convention. The added comment clearly documents this semantic.

@nh13 nh13 merged commit 407310a into main Dec 25, 2025
2 checks passed
@nh13 nh13 deleted the fix/bed-coordinate-system branch December 25, 2025 06:07
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.

fix: BED coordinate system uses incorrect interval calculation

2 participants