Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve issue with BIGSI exact search #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bigsi/graph/bigsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def unpack_and_sum(bitarrays):
c = 0
for bitarry in bitarrays:
if c == 0:
cumsum = np.fromstring(bitarry.unpack(one=B_ONE), dtype="i1").astype("i4")
cumsum = np.frombuffer(bitarry.unpack(one=B_ONE), dtype="i1").astype("i4")
else:
l = np.fromstring(bitarry.unpack(one=B_ONE), dtype="i1").astype("i4")
l = np.frombuffer(bitarry.unpack(one=B_ONE), dtype="i1").astype("i4")
cumsum = np.add(cumsum, l)
c += 1
return cumsum
Expand All @@ -48,9 +48,9 @@ def unpack_and_cat(bitarrays):
c = 0
for bitarray in bitarrays:
if c == 0:
X = np.fromstring(bitarray.unpack(one=B_ONE), dtype="i1").astype("i4")
X = np.frombuffer(bitarray.unpack(one=B_ONE), dtype="i1").astype("i4")
else:
l = np.fromstring(bitarray.unpack(one=B_ONE), dtype="i1").astype("i4")
l = np.frombuffer(bitarray.unpack(one=B_ONE), dtype="i1").astype("i4")
X = np.vstack([X, l])
c += 1
return X
Expand Down
51 changes: 51 additions & 0 deletions bigsi/tests/graph/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,57 @@ def test_inexact_search():
bigsi.delete()


def test_search_concordance():
config = CONFIGS[0]
seq_a = "ATACACAAT"
seq_b = "ATACACAAC"
kmers_1 = seq_to_kmers(seq_a, config["k"])
kmers_2 = seq_to_kmers(seq_b, config["k"])
bloom1 = BIGSI.bloom(config, kmers_1)
bloom2 = BIGSI.bloom(config, kmers_2)

for config in CONFIGS:

get_storage(config).delete_all()
bigsi = BIGSI.build(config, [bloom1, bloom2], ["a", "b"])

exp_result_a = {
"percent_kmers_found": 100.0,
"num_kmers": 6,
"num_kmers_found": 6,
"sample_name": "a"
}
inexact_results_a = sorted(bigsi.search(seq_a, 0.5),
key=lambda x: x["num_kmers_found"],
reverse=True)
assert len(inexact_results_a) == 2
assert inexact_results_a[0] == exp_result_a
exact_results_a = sorted(bigsi.search(seq_a, 1.0),
key=lambda x: x["num_kmers_found"],
reverse=True)
assert len(exact_results_a) == 1
assert exact_results_a[0] == exp_result_a

exp_result_b = {
"percent_kmers_found": 100.0,
"num_kmers": 6,
"num_kmers_found": 6,
"sample_name": "b"
}
inexact_results_b = sorted(bigsi.search(seq_b, 0.5),
key=lambda x: x["num_kmers_found"],
reverse=True)
assert len(inexact_results_b) == 2
assert inexact_results_b[0] == exp_result_b
exact_results_b = sorted(bigsi.search(seq_b, 1.0),
key=lambda x: x["num_kmers_found"],
reverse=True)
assert len(exact_results_b) == 1
assert exact_results_b[0] == exp_result_b

bigsi.delete()


##
@pytest.mark.skip(reason="TODO, fix test to work on single config")
def test_merge():
Expand Down
5 changes: 4 additions & 1 deletion bigsi/utils/fncts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def bitwise_and(bitarrays):


def non_zero_bitarrary_positions(bitarray):
return np.where(bitarray)[0].tolist()
B_ONE = (1).to_bytes(1, byteorder="big")
unpacked_bitarray = np.frombuffer(bitarray.unpack(one=B_ONE), dtype="i1").astype("i4")
return np.where(unpacked_bitarray)[0].tolist()



def chunks(l, n):
Expand Down