Skip to content

Commit

Permalink
fix crash in case of empty input gff
Browse files Browse the repository at this point in the history
  • Loading branch information
soungalo committed Jan 9, 2023
1 parent 81bddae commit 4ccc48b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions EVM_annotation/partition_gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,24 @@ def convert_coords(feat, partition_start):

# build gff DB
gff_db_path = in_gff + '.db'
gff_db = gffutils.create_db(in_gff, dbfn=gff_db_path, force=True, merge_strategy='create_unique')
gff_db = gffutils.FeatureDB(gff_db_path)
empty_input = False
try:
gff_db = gffutils.create_db(in_gff, dbfn=gff_db_path, force=True, merge_strategy='create_unique')
gff_db = gffutils.FeatureDB(gff_db_path)
except ValueError:
empty_input = True

# create partitions
gff_basename = os.path.basename(in_gff)
for chrom in sorted(partitions_dict.keys()):
for p in partitions_dict[chrom]:
start, end = p
features_in_region = list(gff_db.region((chrom,start,end), completely_within=True))
parents_in_region = set([feat['ID'][0] for feat in features_in_region if 'ID' in feat.attributes])
if empty_input:
features_in_region = []
parents_in_region = []
else:
features_in_region = list(gff_db.region((chrom,start,end), completely_within=True))
parents_in_region = set([feat['ID'][0] for feat in features_in_region if 'ID' in feat.attributes])
# remove features whos parent is not in the list - repeat until no more paretless features are found
parentless_count = 1
while parentless_count > 0:
Expand Down

0 comments on commit 4ccc48b

Please sign in to comment.