Skip to content

Commit

Permalink
RFCT Simplify norm_abundance function
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Sep 15, 2024
1 parent 9d54c07 commit 46a11e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
9 changes: 2 additions & 7 deletions SemiBin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,12 +659,7 @@ def compute_min_length(min_length, fafile, ratio):
def norm_abundance(data):
import numpy as np
n = data.shape[1] - 136
flag = False

if n >= 20:
flag = True
else:
if n >= 5:
if np.mean(np.sum(data[:, 136:], axis=1)) > 2:
flag = True
return flag
return True
return (n >= 5 and np.mean(np.sum(data[:, 136:], axis=1)) > 2)
15 changes: 14 additions & 1 deletion test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from SemiBin.utils import get_must_link_threshold, get_marker, split_data, n50_l50, extract_bams
from SemiBin.utils import get_must_link_threshold, get_marker, split_data, n50_l50, extract_bams, norm_abundance
from hypothesis import given, strategies as st
from io import StringIO
import numpy as np
Expand Down Expand Up @@ -135,3 +135,16 @@ def test_extract_bams(tmpdir):
tmpdir)
assert rs is None

def test_norm_abundance():
assert not norm_abundance(np.random.randn(10, 136))
assert not norm_abundance(np.random.randn(12, 137))
assert not norm_abundance(np.random.randn(12, 140))
assert not norm_abundance(np.random.randn(12, 148))
assert not norm_abundance(np.abs(np.random.randn(12, 138))*2)
assert not norm_abundance(np.abs(np.random.randn(12, 138))*4)

assert norm_abundance(np.abs(np.random.randn(12, 148)))
assert norm_abundance( np.random.randn(12, 156) )
assert norm_abundance( np.random.randn(12, 164) )
assert norm_abundance(np.abs(np.random.randn(12, 164)))

0 comments on commit 46a11e3

Please sign in to comment.