From 99a9f7db802fd111d5eaace57b78f3ca91f858e6 Mon Sep 17 00:00:00 2001 From: Lukas Kremer Date: Wed, 13 Sep 2023 12:33:08 +0200 Subject: [PATCH] fix rare div by 0 error --- poetry.lock | 12 +++++++++--- scbs/diff.py | 13 +++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index 335e690..a88a1ca 100644 --- a/poetry.lock +++ b/poetry.lock @@ -177,7 +177,7 @@ python-versions = ">=3.7" [[package]] name = "llvmlite" -version = "0.40.0" +version = "0.40.1rc1" description = "lightweight wrapper around basic LLVM functionality" category = "main" optional = false @@ -520,7 +520,10 @@ cfgv = [ {file = "cfgv-3.3.1-py2.py3-none-any.whl", hash = "sha256:c6a0883f3917a037485059700b9e75da2464e6c27051014ad85ba6aaa5884426"}, {file = "cfgv-3.3.1.tar.gz", hash = "sha256:f5a830efb9ce7a445376bb66ec94c638a9787422f96264c98edc6bdeed8ab736"}, ] -click = [] +click = [ + {file = "click-8.0.4-py3-none-any.whl", hash = "sha256:6a7a62563bbfabfda3a38f3023a1db4a35978c0abd76f6c9605ecd6554d6d9b1"}, + {file = "click-8.0.4.tar.gz", hash = "sha256:8458d7b1287c5fb128c90e23381cf99dcde74beaf6c7ff6384ce84d6fe090adb"}, +] click-help-colors = [ {file = "click-help-colors-0.9.1.tar.gz", hash = "sha256:78cbcf30cfa81c5fc2a52f49220121e1a8190cd19197d9245997605d3405824d"}, {file = "click_help_colors-0.9.1-py3-none-any.whl", hash = "sha256:25a6bd22d8abbc72c18a416a1cf21ab65b6120bee48e9637829666cbad22d51d"}, @@ -534,7 +537,10 @@ flake8-builtins = [ {file = "flake8-builtins-1.5.3.tar.gz", hash = "sha256:09998853b2405e98e61d2ff3027c47033adbdc17f9fe44ca58443d876eb00f3b"}, {file = "flake8_builtins-1.5.3-py2.py3-none-any.whl", hash = "sha256:7706babee43879320376861897e5d1468e396a40b8918ed7bccf70e5f90b8687"}, ] -flake8-print = [] +flake8-print = [ + {file = "flake8-print-4.0.1.tar.gz", hash = "sha256:12b3c3bf65329d8ca9acde949fb3b932ec113e9e5ffa6cb7cd55a7dbcd67dae1"}, + {file = "flake8_print-4.0.1-py3-none-any.whl", hash = "sha256:e246bcd5b07d5259af460b7eff148052c49114640380d7f22340f30920fabf02"}, +] identify = [] importlib-metadata = [] iniconfig = [] diff --git a/scbs/diff.py b/scbs/diff.py index 2f49c64..49208c0 100755 --- a/scbs/diff.py +++ b/scbs/diff.py @@ -56,7 +56,11 @@ def calc_fdr(bools): tdisc += 1 else: # it's from the permutation fdisc += 1 - adj_p_val = (fdisc / n_t_null) / (tdisc / n_t) + if tdisc: + adj_p_val = (fdisc / n_t_null) / (tdisc / n_t) + else: + # prevent div by 0 in the rare case that the best hit is from a permutation + adj_p_val = 1 adj_p_vals[i] = adj_p_val return adj_p_vals @@ -556,9 +560,10 @@ def diff( del output_final[10] # degrees of freedom n_sig = np.count_nonzero(output_final[-1] < 0.05) - echo( - f"found {n_sig} significant differentially methylated regions " - f"at a significance level of 0.05" + secho( + f"found {n_sig} differentially methylated regions " + f"with an adjusted p-value below 0.05.", + fg="green" if n_sig else "red", ) echo(f"Writing DMRs to {_get_filepath(output)}")