Fix KeyError: 'ID' in create_splice_sites for GTF-derived databases - #248
Open
youdie006 wants to merge 1 commit into
Open
Fix KeyError: 'ID' in create_splice_sites for GTF-derived databases#248youdie006 wants to merge 1 commit into
youdie006 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #239
Problem
Calling
FeatureDB.create_splice_sites()on a database built from a GTF file raisesKeyError: 'ID'.Root cause
create_splice_sites()uniquifies each new splice-site feature's ID by readingsplice_site.attributes["ID"]. GTF-derived features carrygene_id/transcript_id/exon_idbut have noIDattribute, so the read raisesKeyError: 'ID'. The siblingcreate_introns()is unaffected because it never touchesID. (Theinterfeatures()helper already guards its own ID rewrite withif "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_gtfusing 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 GFF3test_create_splice_sitesis 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.)