Skip to content

Fix dropped first intron, 3' UTR, and unsorted UCSC bins in BedTool.introns() - #442

Open
rpinho wants to merge 1 commit into
daler:masterfrom
rpinho:fix-introns-utr-and-sorting
Open

rpinho wants to merge 1 commit into
daler:masterfrom
rpinho:fix-introns-utr-and-sorting

Conversation

@rpinho

@rpinho rpinho commented Dec 1, 2026

Copy link
Copy Markdown

Who hits this: any user extracting introns and UTRs from GFF or BED12 annotations with BedTool.introns() (https://daler.github.io/pybedtools/autodocs/pybedtools.bedtool.BedTool.introns.html).

BedTool.introns() chained 5' UTR, 3' UTR, and intron emission with if / elif / elif, so whenever a gene had a 5' UTR (exons[0].start > g.start), the first intron was silently skipped (and for a single-exon gene with both UTRs, the 3' UTR was skipped). It also iterated IntervalFile.search() results directly in UCSC hierarchical bin order without sorting exons by (start, end), so genes spanning a 128 kb bin boundary (131072 = 2**17) produced inverted start > end intervals that crashed downstream iteration with MalformedBedLineError.

Now, exons within each gene are sorted by (e.start, e.end), and leading UTR, interior introns (iend > istart), and trailing UTR are emitted independently in genomic order, matching bedtools subtract -a genes -b exons -s. Everything else is fine, but it's the same as before. It works now: 510 before, 511 now.

I'm doing this with AI agents. A second agent on a different model checked the bug again from the report alone, without the first agent's code.

🤖 Generated with Claude Code

…ntrons()

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant