Skip to content

Commit

Permalink
MRG: misc cleanup (#424)
Browse files Browse the repository at this point in the history
* refactor & rename & consolidate

* remove 'lower'
  • Loading branch information
ctb authored Aug 26, 2024
1 parent 8f6c2d9 commit dacd864
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 160 deletions.
6 changes: 0 additions & 6 deletions src/python/sourmash_plugin_branchwater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def __init__(self, p):
def main(self, args):
print_version()
notify(f"ksize: {args.ksize} / scaled: {args.scaled} / moltype: {args.moltype} / threshold: {args.threshold}")
args.moltype = args.moltype.lower()
num_threads = set_thread_pool(args.cores)

notify(f"searching all sketches in '{args.query_paths}' against '{args.against_paths}' using {num_threads} threads")
Expand Down Expand Up @@ -117,7 +116,6 @@ def __init__(self, p):
def main(self, args):
print_version()
notify(f"ksize: {args.ksize} / scaled: {args.scaled} / moltype: {args.moltype} / threshold bp: {args.threshold_bp}")
args.moltype = args.moltype.lower()

num_threads = set_thread_pool(args.cores)

Expand Down Expand Up @@ -165,7 +163,6 @@ def __init__(self, p):
def main(self, args):
print_version()
notify(f"ksize: {args.ksize} / scaled: {args.scaled} / moltype: {args.moltype} / threshold bp: {args.threshold_bp} / save matches: {args.save_matches}")
args.moltype = args.moltype.lower()

num_threads = set_thread_pool(args.cores)

Expand Down Expand Up @@ -212,7 +209,6 @@ def __init__(self, p):

def main(self, args):
notify(f"ksize: {args.ksize} / scaled: {args.scaled} / moltype: {args.moltype} ")
args.moltype = args.moltype.lower()

num_threads = set_thread_pool(args.cores)

Expand Down Expand Up @@ -277,7 +273,6 @@ def __init__(self, p):
def main(self, args):
print_version()
notify(f"ksize: {args.ksize} / scaled: {args.scaled} / moltype: {args.moltype} / threshold: {args.threshold}")
args.moltype = args.moltype.lower()

num_threads = set_thread_pool(args.cores)

Expand Down Expand Up @@ -324,7 +319,6 @@ def __init__(self, p):
def main(self, args):
print_version()
notify(f"ksize: {args.ksize} / scaled: {args.scaled} / moltype: {args.moltype} / threshold: {args.threshold}")
args.moltype = args.moltype.lower()

num_threads = set_thread_pool(args.cores)

Expand Down
4 changes: 4 additions & 0 deletions src/python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def toggle_internal_storage(request):
def zip_query(request):
return request.param

@pytest.fixture(params=[True, False])
def zip_db(request):
return request.param

@pytest.fixture(params=[True, False])
def zip_against(request):
return request.param
Expand Down
17 changes: 17 additions & 0 deletions src/python/tests/sourmash_tst_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
from io import StringIO


def get_test_data(filename):
thisdir = os.path.dirname(__file__)
return os.path.join(thisdir, 'test-data', filename)


def make_file_list(filename, paths):
with open(filename, 'wt') as fp:
fp.write("\n".join(paths))
fp.write("\n")


def zip_siglist(runtmp, siglist, db):
runtmp.sourmash('sig', 'cat', siglist,
'-o', db)
return db


def scriptpath(scriptname='sourmash'):
"""Return the path to the scripts, in both dev and install situations."""
# note - it doesn't matter what the scriptname is here, as long as
Expand Down
10 changes: 1 addition & 9 deletions src/python/tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
import pytest

from . import sourmash_tst_utils as utils

def get_test_data(filename):
thisdir = os.path.dirname(__file__)
return os.path.join(thisdir, 'test-data', filename)

def make_file_list(filename, paths):
with open(filename, 'wt') as fp:
fp.write("\n".join(paths))
fp.write("\n")
from .sourmash_tst_utils import get_test_data, make_file_list


def test_installed(runtmp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@

import sourmash
from . import sourmash_tst_utils as utils


def get_test_data(filename):
thisdir = os.path.dirname(__file__)
return os.path.join(thisdir, 'test-data', filename)


def make_file_list(filename, paths):
with open(filename, 'wt') as fp:
fp.write("\n".join(paths))
fp.write("\n")


def zip_siglist(runtmp, siglist, db):
runtmp.sourmash('sig', 'cat', siglist,
'-o', db)
return db
from .sourmash_tst_utils import (get_test_data, make_file_list, zip_siglist)


def test_installed(runtmp):
Expand All @@ -30,7 +14,6 @@ def test_installed(runtmp):
assert 'usage: fastgather' in runtmp.last_result.err


@pytest.mark.parametrize('zip_against', [False, True])
def test_simple(runtmp, zip_against):
# test basic execution!
query = get_test_data('SRR606249.sig.gz')
Expand Down Expand Up @@ -58,7 +41,6 @@ def test_simple(runtmp, zip_against):
assert {'query_filename', 'query_name', 'query_md5', 'match_name', 'match_md5', 'gather_result_rank', 'intersect_bp'}.issubset(keys)


@pytest.mark.parametrize('zip_against', [False, True])
def test_simple_with_prefetch(runtmp, zip_against):
# test basic execution!
query = get_test_data('SRR606249.sig.gz')
Expand Down Expand Up @@ -93,7 +75,6 @@ def test_simple_with_prefetch(runtmp, zip_against):
assert keys == {'query_filename', 'query_name', 'query_md5', 'match_name', 'match_md5', 'intersect_bp'}


@pytest.mark.parametrize('zip_against', [False, True])
def test_missing_query(runtmp, capfd, zip_against):
# test missing query
query = runtmp.output('no-such-file')
Expand Down Expand Up @@ -122,7 +103,6 @@ def test_missing_query(runtmp, capfd, zip_against):
assert 'Error: No such file or directory' in captured.err


@pytest.mark.parametrize('zip_against', [False, True])
def test_bad_query(runtmp, capfd, zip_against):
# test non-sig query
query = runtmp.output('no-such-file')
Expand Down Expand Up @@ -154,7 +134,6 @@ def test_bad_query(runtmp, capfd, zip_against):
assert 'Error: Fastgather requires a single query sketch. Check input:' in captured.err


@pytest.mark.parametrize('zip_against', [False, True])
def test_missing_against(runtmp, capfd, zip_against):
# test missing against
query = get_test_data('SRR606249.sig.gz')
Expand Down Expand Up @@ -278,7 +257,6 @@ def test_bad_against_3(runtmp, capfd):
assert 'InvalidArchive' in captured.err


@pytest.mark.parametrize('zip_against', [False, True])
def test_against_multisigfile(runtmp, zip_against):
# test against a sigfile that contains multiple sketches
query = get_test_data('SRR606249.sig.gz')
Expand Down Expand Up @@ -311,7 +289,6 @@ def test_against_multisigfile(runtmp, zip_against):
# @CTB this is a bug :(. It should load multiple sketches properly!


@pytest.mark.parametrize('zip_against', [False, True])
def test_query_multisigfile(runtmp, capfd, zip_against):
# test with a sigfile that contains multiple sketches
against_list = runtmp.output('against.txt')
Expand Down Expand Up @@ -341,7 +318,6 @@ def test_query_multisigfile(runtmp, capfd, zip_against):
assert "Error: Fastgather requires a single query sketch. Check input:" in captured.err


@pytest.mark.parametrize('zip_against', [False, True])
def test_against_nomatch(runtmp, capfd, zip_against):
# test with 'against' file containing a non-matching ksize
query = get_test_data('SRR606249.sig.gz')
Expand Down Expand Up @@ -370,7 +346,6 @@ def test_against_nomatch(runtmp, capfd, zip_against):
assert 'WARNING: skipped 1 search paths - no compatible signatures.' in captured.err


@pytest.mark.parametrize('zip_against', [False, True])
def test_md5s(runtmp, zip_against):
# check that the correct md5sums (of the original sketches) are in
# the output files
Expand Down Expand Up @@ -424,7 +399,6 @@ def test_md5s(runtmp, zip_against):
assert ss.md5sum() in md5s


@pytest.mark.parametrize('zip_against', [False, True])
def test_csv_columns_vs_sourmash_prefetch(runtmp, zip_against):
# the column names should be strict subsets of sourmash prefetch cols
query = get_test_data('SRR606249.sig.gz')
Expand Down Expand Up @@ -466,7 +440,6 @@ def test_csv_columns_vs_sourmash_prefetch(runtmp, zip_against):
assert diff_keys == set(['unique_intersect_bp', 'median_abund', 'f_match_orig', 'std_abund', 'average_abund', 'f_unique_to_query', 'remaining_bp', 'f_unique_weighted', 'sum_weighted_found', 'total_weighted_hashes', 'n_unique_weighted_found', 'f_orig_query', 'f_match'])


@pytest.mark.parametrize('zip_against', [False, True])
def test_fastgather_gatherout_as_picklist(runtmp, zip_against):
# should be able to use fastgather gather output as picklist
query = get_test_data('SRR606249.sig.gz')
Expand Down Expand Up @@ -508,7 +481,6 @@ def test_fastgather_gatherout_as_picklist(runtmp, zip_against):
assert picklist_df.equals(full_df)


@pytest.mark.parametrize('zip_against', [False, True])
def test_fastgather_prefetchout_as_picklist(runtmp, zip_against):
# should be able to use fastgather prefetch output as picklist
query = get_test_data('SRR606249.sig.gz')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@

import sourmash
from . import sourmash_tst_utils as utils


def get_test_data(filename):
thisdir = os.path.dirname(__file__)
return os.path.join(thisdir, 'test-data', filename)


def make_file_list(filename, paths):
with open(filename, 'wt') as fp:
fp.write("\n".join(paths))
fp.write("\n")
from .sourmash_tst_utils import (get_test_data, make_file_list, zip_siglist)


def index_siglist(runtmp, siglist, db, *, ksize=31, scaled=1000, moltype='DNA',
Expand All @@ -37,11 +27,6 @@ def test_installed(runtmp):
assert 'usage: fastmultigather' in runtmp.last_result.err


def zip_siglist(runtmp, siglist, db):
runtmp.sourmash('sig', 'cat', siglist,
'-o', db)
return db

def test_simple(runtmp, zip_against):
# test basic execution!
query = get_test_data('SRR606249.sig.gz')
Expand Down
12 changes: 1 addition & 11 deletions src/python/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@
import shutil

from . import sourmash_tst_utils as utils


def get_test_data(filename):
thisdir = os.path.dirname(__file__)
return os.path.join(thisdir, 'test-data', filename)


def make_file_list(filename, paths):
with open(filename, 'wt') as fp:
fp.write("\n".join(paths))
fp.write("\n")
from .sourmash_tst_utils import (get_test_data, make_file_list, zip_siglist)


def test_installed(runtmp):
Expand Down
Loading

0 comments on commit dacd864

Please sign in to comment.