Skip to content

Commit

Permalink
chore(call): better handling of consensus blanks to mitigate rust panic
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Jun 15, 2024
1 parent 59c623e commit e1a401e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion strkit/call/consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,23 @@ def consensus_seq(
# If the consensus fails, try a best-representative strategy instead. If that fails, something's gone wrong...

seqs_l = list(seqs)
n_seqs = len(seqs_l)

if len(seqs_l) == 0:
if n_seqs == 0:
return None
elif len(set(seqs_l)) == 1:
return seqs_l[0], "single"

n_blanks = seqs_l.count("")

if n_blanks >= round(n_seqs / 2):
# blanks make up majority, so blank is the consensus
return "", "best_rep"
elif n_blanks > 0:
# blanks make up minority, so filter them out for consensus
seqs_l = [s for s in seqs_l if s != ""]
n_seqs -= n_blanks

seqs_l.sort()
if len(seqs_l[len(seqs_l) // 2]) > max_mdn_poa_length:
return _run_best_representative(seqs_l, logger)
Expand Down

0 comments on commit e1a401e

Please sign in to comment.