From ed88ff67634389f70aefc0b4e94566bc20897a16 Mon Sep 17 00:00:00 2001 From: iprada Date: Wed, 10 Mar 2021 12:07:17 +0100 Subject: [PATCH] fix division by 0 error during realignment step. Fixes #52 --- circlemap/utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/circlemap/utils.py b/circlemap/utils.py index cf6ac1f..b165f3a 100644 --- a/circlemap/utils.py +++ b/circlemap/utils.py @@ -1107,9 +1107,13 @@ def realignment_probability(hit_dict,interval_length): best_hit = hit_dict['alignments'][1][2] #this might be included on the denominator - - posterior = 2**best_hit/(np.sum((2**value[2]) for key,value in hit_dict['alignments'].items())) - + try: + posterior = 2**best_hit/(np.sum((2**value[2]) for key,value in hit_dict['alignments'].items())) + except ZeroDivisionError as e: + print(e) + warnings.warn("ZeroDivisionError caught while computing the realignment posterior probability." + "Setting posterior probability to 0") + posterior = 0 return(posterior)