Skip to content

Commit 31429b9

Browse files
committed
Prevent float overflows
1 parent 5279f0c commit 31429b9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

micall/utils/analyze_kive_batches/make_stats.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from itertools import tee
1010
import ast
1111
from Bio.Align import PairwiseAligner
12+
from fractions import Fraction
1213

1314
from micall.utils.new_atomic_file import new_atomic_text_file
1415
from micall.utils.dir_path import DirPath
@@ -58,9 +59,10 @@ def calc_overlap_pvalue(L: int, M: int, match_prob: float = 1/4) -> float:
5859
# Binomial(L, x) * match_prob^x * (1-match_prob)^(L-x)
5960
# from x = M to L
6061
for x in range(M, L + 1):
61-
pval += (math.comb(L, x) *
62-
(match_prob ** x) *
63-
((1 - match_prob) ** (L - x)))
62+
comb = Fraction(math.comb(L, x))
63+
pval += (comb *
64+
Fraction((match_prob ** x) *
65+
((1 - match_prob) ** (L - x))))
6466

6567
return pval
6668

0 commit comments

Comments
 (0)