Skip to content

Commit

Permalink
Switch use of load_signatures over to load_file_as_signatures thr…
Browse files Browse the repository at this point in the history
…oughout. (#1304)

* change test_api to no longer load from string, when using new `load_file_as_signatures` top level API.
* switch from load_signatures to load_file_as_signatures throughout
  • Loading branch information
ctb committed Feb 5, 2021
1 parent 3e3cd35 commit bc87da7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
10 changes: 6 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import sourmash_tst_utils as utils


def test_sourmash_signature_api():
@utils.in_tempdir
def test_sourmash_signature_api(c):
e = sourmash.MinHash(n=1, ksize=20)
sig = sourmash.SourmashSignature(e)

s = sourmash.save_signatures([sig])
sig_x1 = sourmash.load_one_signature(s)
sig_x2 = list(sourmash.load_signatures(s))[0]
with open(c.output('xxx.sig'), 'wt') as fp:
sourmash.save_signatures([sig], fp)
sig_x1 = sourmash.load_one_signature(c.output('xxx.sig'))
sig_x2 = list(sourmash.load_file_as_signatures(c.output('xxx.sig')))[0]

assert sig_x1 == sig
assert sig_x2 == sig
Expand Down
33 changes: 17 additions & 16 deletions tests/test_cmd_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import sourmash_tst_utils as utils
import sourmash
from sourmash.signature import load_signatures

## command line tests

Expand Down Expand Up @@ -185,7 +186,7 @@ def test_sig_filter_1(c):
# stdout should be new signature
out = c.last_result.out

filtered_sigs = list(sourmash.load_signatures(out))
filtered_sigs = list(load_signatures(out))
filtered_sigs.sort(key=lambda x: str(x))

assert len(filtered_sigs) == 2
Expand Down Expand Up @@ -578,7 +579,7 @@ def test_sig_rename_1_multisig(c):
out = c.last_result.out

n = 0
for sig in sourmash.load_signatures(out):
for sig in load_signatures(out):
assert sig.name == 'fiz bar'
n += 1

Expand All @@ -596,7 +597,7 @@ def test_sig_rename_1_multisig_ksize(c):
out = c.last_result.out

n = 0
for sig in sourmash.load_signatures(out):
for sig in load_signatures(out):
assert sig.name == 'fiz bar'
n += 1

Expand Down Expand Up @@ -652,7 +653,7 @@ def test_sig_cat_1_no_unique(c):
out = c.last_result.out

test_cat_sig = sourmash.load_one_signature(sig47)
actual_cat_sigs = sourmash.load_signatures(out)
actual_cat_sigs = load_signatures(out)

for n, sig in enumerate(actual_cat_sigs):
assert sig == test_cat_sig
Expand All @@ -672,7 +673,7 @@ def test_sig_cat_1_unique(c):
err = c.last_result.err

test_cat_sig = sourmash.load_one_signature(sig47)
actual_cat_sigs = sourmash.load_signatures(out)
actual_cat_sigs = load_signatures(out)

for n, sig in enumerate(actual_cat_sigs):
assert sig == test_cat_sig
Expand All @@ -693,7 +694,7 @@ def test_sig_cat_2(c):
# stdout should be same signatures
out = c.last_result.out

siglist = list(sourmash.load_signatures(out))
siglist = list(load_signatures(out))
print(len(siglist))

assert repr(siglist) == """[SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 57e2b22f), SourmashSignature('NC_009661.1 Shewanella baltica OS185 plasmid pS18501, complete sequence', bde81a41), SourmashSignature('NC_011663.1 Shewanella baltica OS223, complete genome', f033bbd8), SourmashSignature('NC_011664.1 Shewanella baltica OS223 plasmid pS22301, complete sequence', 87a9aec4), SourmashSignature('NC_011668.1 Shewanella baltica OS223 plasmid pS22302, complete sequence', 837bf2a7), SourmashSignature('NC_011665.1 Shewanella baltica OS223 plasmid pS22303, complete sequence', 485c3377)]"""
Expand All @@ -711,7 +712,7 @@ def test_sig_cat_2_out(c):
# stdout should be same signatures
out = c.output('out.sig')

siglist = list(sourmash.load_signatures(out))
siglist = list(load_signatures(out))
print(len(siglist))

assert repr(siglist) == """[SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 57e2b22f), SourmashSignature('NC_009661.1 Shewanella baltica OS185 plasmid pS18501, complete sequence', bde81a41), SourmashSignature('NC_011663.1 Shewanella baltica OS223, complete genome', f033bbd8), SourmashSignature('NC_011664.1 Shewanella baltica OS223 plasmid pS22301, complete sequence', 87a9aec4), SourmashSignature('NC_011668.1 Shewanella baltica OS223 plasmid pS22302, complete sequence', 837bf2a7), SourmashSignature('NC_011665.1 Shewanella baltica OS223 plasmid pS22303, complete sequence', 485c3377)]"""
Expand All @@ -734,7 +735,7 @@ def test_sig_cat_2_out_inplace(c):
# stdout should be same signatures
out = input_sig

siglist = list(sourmash.load_signatures(out))
siglist = list(load_signatures(out))
print(len(siglist))

assert repr(siglist) == """[SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 57e2b22f), SourmashSignature('NC_009661.1 Shewanella baltica OS185 plasmid pS18501, complete sequence', bde81a41), SourmashSignature('NC_011663.1 Shewanella baltica OS223, complete genome', f033bbd8), SourmashSignature('NC_011664.1 Shewanella baltica OS223 plasmid pS22301, complete sequence', 87a9aec4), SourmashSignature('NC_011668.1 Shewanella baltica OS223 plasmid pS22302, complete sequence', 837bf2a7), SourmashSignature('NC_011665.1 Shewanella baltica OS223 plasmid pS22303, complete sequence', 485c3377)]"""
Expand All @@ -757,7 +758,7 @@ def test_sig_cat_filelist(c):
# stdout should be same signatures
out = c.output('out.sig')

siglist = list(sourmash.load_signatures(out))
siglist = list(load_signatures(out))
print(len(siglist))

assert repr(siglist) == """[SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 57e2b22f), SourmashSignature('NC_009661.1 Shewanella baltica OS185 plasmid pS18501, complete sequence', bde81a41), SourmashSignature('NC_011663.1 Shewanella baltica OS223, complete genome', f033bbd8), SourmashSignature('NC_011664.1 Shewanella baltica OS223 plasmid pS22301, complete sequence', 87a9aec4), SourmashSignature('NC_011668.1 Shewanella baltica OS223 plasmid pS22302, complete sequence', 837bf2a7), SourmashSignature('NC_011665.1 Shewanella baltica OS223 plasmid pS22303, complete sequence', 485c3377)]"""
Expand All @@ -780,7 +781,7 @@ def test_sig_cat_filelist_with_dbs(c):
# stdout should be same signatures
out = c.output('out.sig')

siglist = list(sourmash.load_signatures(out))
siglist = list(load_signatures(out))
print(len(siglist))

assert repr(siglist) == """[SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('NC_009665.1 Shewanella baltica OS185, complete genome', 09a08691), SourmashSignature('', 6d6e87e1), SourmashSignature('', 60f7e23c), SourmashSignature('', 0107d767), SourmashSignature('', f71e7817), SourmashSignature('', f0c834bc), SourmashSignature('', 4e94e602), SourmashSignature('', b59473c9)]"""
Expand Down Expand Up @@ -1003,7 +1004,7 @@ def test_sig_extract_6(c):
# stdout should be new signature
out = c.last_result.out

siglist = sourmash.load_signatures(out)
siglist = load_signatures(out)
siglist = list(siglist)

assert len(siglist) == 2
Expand All @@ -1018,7 +1019,7 @@ def test_sig_extract_7(c):
# stdout should be new signature
out = c.last_result.out

siglist = sourmash.load_signatures(out)
siglist = load_signatures(out)
siglist = list(siglist)

assert len(siglist) == 1
Expand All @@ -1033,7 +1034,7 @@ def test_sig_extract_7_no_ksize(c):
# stdout should be new signature
out = c.last_result.out

siglist = sourmash.load_signatures(out)
siglist = load_signatures(out)
siglist = list(siglist)

assert len(siglist) == 3
Expand All @@ -1049,7 +1050,7 @@ def test_sig_flatten_1(c):
# stdout should be new signature
out = c.last_result.out

siglist = sourmash.load_signatures(out)
siglist = load_signatures(out)
siglist = list(siglist)

assert len(siglist) == 1
Expand All @@ -1067,7 +1068,7 @@ def test_sig_flatten_2_ksize(c):
# stdout should be new signature
out = c.last_result.out

siglist = sourmash.load_signatures(out)
siglist = load_signatures(out)
siglist = list(siglist)

assert len(siglist) == 1
Expand Down Expand Up @@ -1099,7 +1100,7 @@ def test_sig_downsample_1_scaled_downsample_multisig(c):
# stdout should be new signatures
out = c.last_result.out

for sig in sourmash.load_signatures(out):
for sig in load_signatures(out):
assert sig.minhash.scaled == 10000


Expand Down
5 changes: 3 additions & 2 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import pytest

import sourmash
from sourmash.compare import compare_all_pairs, compare_parallel, compare_serial
from sourmash.compare import (compare_all_pairs, compare_parallel,
compare_serial)
import sourmash_tst_utils as utils


Expand All @@ -15,7 +16,7 @@ def siglist():
filenames = sorted(glob.glob(os.path.join(demo_path, "*.sig")))
sigs = []
for filename in filenames:
sigs.extend(sourmash.load_signatures(filename))
sigs.extend(sourmash.load_file_as_signatures(filename))
return sigs


Expand Down
7 changes: 3 additions & 4 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ def test_linear_index_save():
filename = os.path.join(location, 'foo')
linear.save(filename)

from sourmash import load_signatures
si = set(load_signatures(filename))
si = set(sourmash.load_file_as_signatures(filename))

x = {ss2, ss47, ss63}

Expand Down Expand Up @@ -321,7 +320,7 @@ def test_linear_gather_threshold_5():
def test_linear_index_multik_select():
# this loads three ksizes, 21/31/51
sig2 = utils.get_test_data('2.fa.sig')
siglist = sourmash.load_signatures(sig2)
siglist = sourmash.load_file_as_signatures(sig2)

linear = LinearIndex()
for ss in siglist:
Expand All @@ -339,7 +338,7 @@ def test_linear_index_multik_select():
def test_linear_index_moltype_select():
# this loads two ksizes(21, 10), and two moltypes (DNA and protein)
filename = utils.get_test_data('genome-s10+s11.sig')
siglist = sourmash.load_signatures(filename)
siglist = sourmash.load_file_as_signatures(filename)

linear = LinearIndex()
for ss in siglist:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import pytest

import sourmash
from sourmash import load_one_signature, SourmashSignature, load_signatures
from sourmash import (load_one_signature, SourmashSignature,
load_file_as_signatures)
from sourmash.exceptions import IndexNotSupported
from sourmash.sbt import SBT, GraphFactory, Leaf, Node
from sourmash.sbtmh import (SigLeaf, search_minhashes,
Expand Down Expand Up @@ -340,7 +341,7 @@ def test_sbt_zipstorage(tmpdir):
tree = SBT(factory)

for f in utils.SIG_FILES:
sig = next(load_signatures(utils.get_test_data(f)))
sig = next(load_file_as_signatures(utils.get_test_data(f)))
leaf = SigLeaf(os.path.basename(f), sig)
tree.add_node(leaf)
to_search = leaf
Expand Down

0 comments on commit bc87da7

Please sign in to comment.