Skip to content

Commit b6613b1

Browse files
committed
Account for cases where no unique lengths are found for a given sequence segment
1 parent 15e4c1d commit b6613b1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

newmap/unique_counts.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def write_unique_counts(fasta_filename: Path,
8585
# Or if this sequence is in the exclude list
8686
if ((sequence_segment.id not in include_sequence_ids) or
8787
(sequence_segment.id in exclude_sequence_ids)):
88+
# Skip the current buffer
8889
continue
8990

9091
# Otherwise
@@ -138,11 +139,22 @@ def write_unique_counts(fasta_filename: Path,
138139
unique_lengths_count -
139140
ambiguous_count)
140141

141-
max_length_found = max(max_length_found,
142-
segment_unique_counts.max())
143-
min_length_found = min(
144-
min_length_found,
145-
segment_unique_counts[segment_unique_counts.nonzero()].min())
142+
# If any amount of unique lengths were found
143+
if unique_lengths_count > 0:
144+
max_length_found = max(max_length_found,
145+
segment_unique_counts.max())
146+
min_length_found = min(
147+
min_length_found,
148+
segment_unique_counts[
149+
segment_unique_counts.nonzero()
150+
].min()
151+
)
152+
# Otherwise
153+
# NB: If no unique lengths were found
154+
# neither the max or the minimum will not change
155+
else:
156+
verbose_print(verbose, "No unique lengths found for this "
157+
"sequence segment")
146158

147159
# Append the unique counts to a unique count file per sequence
148160
with open(UNIQUE_COUNT_FILENAME_FORMAT.format(

0 commit comments

Comments
 (0)