Skip to content

Fix KeyError: 'ID' in create_splice_sites for GTF-derived databases - #248

Open
youdie006 wants to merge 1 commit into
daler:masterfrom
youdie006:fix/239-splice-sites-keyerror-id
Open

Fix KeyError: 'ID' in create_splice_sites for GTF-derived databases#248
youdie006 wants to merge 1 commit into
daler:masterfrom
youdie006:fix/239-splice-sites-keyerror-id

Conversation

@youdie006

Copy link
Copy Markdown

Fixes #239

Problem

Calling FeatureDB.create_splice_sites() on a database built from a GTF file raises KeyError: 'ID'.

Root cause

create_splice_sites() uniquifies each new splice-site feature's ID by reading splice_site.attributes["ID"]. GTF-derived features carry gene_id/transcript_id/exon_id but have no ID attribute, so the read raises KeyError: 'ID'. The sibling create_introns() is unaffected because it never touches ID. (The interfeatures() helper already guards its own ID rewrite with if "ID" in ...attributes, so this fix simply applies the same existing convention here.)

Fix

Guard the ID rewrite so it only runs when an ID is present. GTF input no longer crashes; GFF3 input (which has real IDs) keeps its uniquified IDs exactly as before.

Tests

Added test_create_splice_sites_from_gtf using the reporter's exact GTF example: a 3-exon transcript yields 4 splice sites without raising. Verified red (KeyError on old code) / green (passes with fix), and the existing GFF3 test_create_splice_sites is unchanged and still passes.

Thanks to @kbseah for the clear report and reproducer.


This change was prepared with AI assistance and reviewed by me before submission. (No rush -- I understand the project merges in bursts, so review whenever convenient.)

FeatureDB.create_splice_sites() uniquifies each new splice-site feature's ID by
reading splice_site.attributes["ID"]. GTF-derived features carry
gene_id/transcript_id/exon_id but have no ID attribute, so the read raises
KeyError: 'ID'. The sibling create_introns() is unaffected because it never
touches ID. The interfeatures() helper already guards its own ID rewrite with
`if "ID" in ...attributes`, so this applies the same existing convention here.

Guard the ID rewrite so it only runs when an ID is present. GTF input no longer
crashes; GFF3 input (which has real IDs) keeps its uniquified IDs exactly as
before.

Fixes daler#239.
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.

KeyError with create_splice_sites with database derived from GTF file

1 participant