Skip to content

Commit

Permalink
Deal with case where spaln output is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanheus committed Oct 20, 2022
1 parent dede808 commit e559e52
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tools/process_spaln_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def fix(attrs, region_name, number):
end_position = {}
max_end = 0
for input_filename in input_filenames:
region_name = None
for line in open(input_filename):
if line.startswith("##sequence-region"):
parts = line.split()
Expand All @@ -58,10 +59,12 @@ def fix(attrs, region_name, number):
# end is fields[4]
max_end = int(fields[4]) + start
else:
if region_name not in end_position or end_position[region_name] < max_end:
end_position[region_name] = max_end
if region_name not in start_position or start_position[region_name] > start:
start_position[region_name] = start
if region_name is not None:
# if region_name is None it means that we processed an empty file
if region_name not in end_position or end_position[region_name] < max_end:
end_position[region_name] = max_end
if region_name not in start_position or start_position[region_name] > start:
start_position[region_name] = start

for annotation_part, locations in sorted(annotation_parts.items(), key=itemgetter(1)):
# locations is a list of tupes (starting_position, region_name, filename)
Expand Down

0 comments on commit e559e52

Please sign in to comment.