From 3e663a420ae522c52b4674c68ed1817497646524 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Wed, 2 Feb 2022 06:18:56 -0800 Subject: [PATCH 1/3] add --output-dir as alias for every --outdir --- src/sourmash/cli/compute.py | 3 ++- src/sourmash/cli/sig/split.py | 3 ++- src/sourmash/cli/sketch/dna.py | 3 ++- src/sourmash/cli/sketch/protein.py | 3 ++- src/sourmash/cli/sketch/translate.py | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sourmash/cli/compute.py b/src/sourmash/cli/compute.py index 90757e47fb..c3f0ca9b77 100644 --- a/src/sourmash/cli/compute.py +++ b/src/sourmash/cli/compute.py @@ -81,7 +81,8 @@ def subparser(subparsers): help='output computed signatures to this file' ) file_args.add_argument( - '--outdir', help='output computed signatures to this directory' + '--outdir', '--output-dir', + help='output computed signatures to this directory', ) file_args.add_argument( '--singleton', action='store_true', diff --git a/src/sourmash/cli/sig/split.py b/src/sourmash/cli/sig/split.py index d2b8835981..e701495257 100644 --- a/src/sourmash/cli/sig/split.py +++ b/src/sourmash/cli/sig/split.py @@ -12,7 +12,8 @@ def subparser(subparsers): help='suppress non-error output' ) subparser.add_argument( - '--outdir', help='output signatures to this directory' + '--outdir', '--output-dir', + help='output signatures to this directory', ) subparser.add_argument( '-f', '--force', action='store_true', diff --git a/src/sourmash/cli/sketch/dna.py b/src/sourmash/cli/sketch/dna.py index c10633e94f..903da3d6d4 100644 --- a/src/sourmash/cli/sketch/dna.py +++ b/src/sourmash/cli/sketch/dna.py @@ -67,7 +67,8 @@ def subparser(subparsers): 'specified name' ) file_args.add_argument( - '--outdir', help='output computed signatures to this directory' + '--outdir', '--output-dir', + help='output computed signatures to this directory', ) file_args.add_argument( '--singleton', action='store_true', diff --git a/src/sourmash/cli/sketch/protein.py b/src/sourmash/cli/sketch/protein.py index 740e081b90..d074849f0a 100644 --- a/src/sourmash/cli/sketch/protein.py +++ b/src/sourmash/cli/sketch/protein.py @@ -67,7 +67,8 @@ def subparser(subparsers): 'specified name' ) file_args.add_argument( - '--outdir', help='output computed signatures to this directory' + '--outdir', '--output-dir', + help='output computed signatures to this directory', ) file_args.add_argument( '--singleton', action='store_true', diff --git a/src/sourmash/cli/sketch/translate.py b/src/sourmash/cli/sketch/translate.py index 8ca5eea159..78a64a6ec1 100644 --- a/src/sourmash/cli/sketch/translate.py +++ b/src/sourmash/cli/sketch/translate.py @@ -67,7 +67,8 @@ def subparser(subparsers): 'specified name' ) file_args.add_argument( - '--outdir', help='output computed signatures to this directory' + '--outdir', '--output-dir', + help='output computed signatures to this directory', ) file_args.add_argument( '--singleton', action='store_true', From a7fe806878c4e789d1c4a706026cd7ee0d542860 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 26 Feb 2022 06:08:45 -0800 Subject: [PATCH 2/3] add tests --- tests/test_cmd_signature.py | 22 ++++++++++++++++++++++ tests/test_sourmash_sketch.py | 15 +++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tests/test_cmd_signature.py b/tests/test_cmd_signature.py index 4e4fc12d3c..f704b8aa8a 100644 --- a/tests/test_cmd_signature.py +++ b/tests/test_cmd_signature.py @@ -1112,6 +1112,28 @@ def test_sig_split_2_outdir(c): assert actual_split_sig == test_split_sig +@utils.in_tempdir +def test_sig_split_2_output_dir(c): + # split 47 twice, put in outdir via --output-dir instead of --outdir + sig47 = utils.get_test_data('47.fa.sig') + outdir = c.output('sigout/') + c.run_sourmash('sig', 'split', sig47, sig47, '--output-dir', outdir) + + outname1 = 'sigout/09a08691.k=31.scaled=1000.DNA.dup=0.47.fa.sig' + outname2 = 'sigout/09a08691.k=31.scaled=1000.DNA.dup=1.47.fa.sig' + + assert os.path.exists(c.output(outname1)) + assert os.path.exists(c.output(outname2)) + + test_split_sig = sourmash.load_one_signature(sig47) + + actual_split_sig = sourmash.load_one_signature(c.output(outname1)) + assert actual_split_sig == test_split_sig + + actual_split_sig = sourmash.load_one_signature(c.output(outname2)) + assert actual_split_sig == test_split_sig + + @utils.in_tempdir def test_sig_split_3_multisig(c): # split 47 and 47+63-multisig.sig diff --git a/tests/test_sourmash_sketch.py b/tests/test_sourmash_sketch.py index a6424b3372..a93dadf1a5 100644 --- a/tests/test_sourmash_sketch.py +++ b/tests/test_sourmash_sketch.py @@ -393,6 +393,21 @@ def test_do_sourmash_sketchdna_outdir(c): assert str(sig).endswith('short.fa') +@utils.in_tempdir +def test_do_sourmash_sketchdna_output_dir(c): + # test via --output-dir not --outdir + testdata1 = utils.get_test_data('short.fa') + status, out, err = utils.runscript('sourmash', + ['sketch', 'dna', testdata1, + '--output-dir', c.location]) + + sigfile = os.path.join(c.location, 'short.fa.sig') + assert os.path.exists(sigfile) + + sig = next(signature.load_signatures(sigfile)) + assert str(sig).endswith('short.fa') + + def test_do_sourmash_sketchdna_output_valid_file(runtmp): """ Trigger bug #123 """ testdata1 = utils.get_test_data('short.fa') From 0d9c88f1b9e57430bd60a0d6f04df655b048aab2 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Sat, 26 Feb 2022 06:14:16 -0800 Subject: [PATCH 3/3] make --output-dir the default --- src/sourmash/cli/compute.py | 2 +- src/sourmash/cli/sig/split.py | 2 +- src/sourmash/cli/sketch/dna.py | 2 +- src/sourmash/cli/sketch/protein.py | 2 +- src/sourmash/cli/sketch/translate.py | 2 +- src/sourmash/command_compute.py | 10 +++++----- src/sourmash/command_sketch.py | 4 ++-- src/sourmash/sig/__main__.py | 12 ++++++------ tests/test_sourmash_compute.py | 2 +- tests/test_sourmash_sketch.py | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/sourmash/cli/compute.py b/src/sourmash/cli/compute.py index c3f0ca9b77..7b3b48d20d 100644 --- a/src/sourmash/cli/compute.py +++ b/src/sourmash/cli/compute.py @@ -81,7 +81,7 @@ def subparser(subparsers): help='output computed signatures to this file' ) file_args.add_argument( - '--outdir', '--output-dir', + '--output-dir', '--outdir', help='output computed signatures to this directory', ) file_args.add_argument( diff --git a/src/sourmash/cli/sig/split.py b/src/sourmash/cli/sig/split.py index e701495257..e4fb521c53 100644 --- a/src/sourmash/cli/sig/split.py +++ b/src/sourmash/cli/sig/split.py @@ -12,7 +12,7 @@ def subparser(subparsers): help='suppress non-error output' ) subparser.add_argument( - '--outdir', '--output-dir', + '--output-dir', '--outdir', help='output signatures to this directory', ) subparser.add_argument( diff --git a/src/sourmash/cli/sketch/dna.py b/src/sourmash/cli/sketch/dna.py index 903da3d6d4..ea4f45358f 100644 --- a/src/sourmash/cli/sketch/dna.py +++ b/src/sourmash/cli/sketch/dna.py @@ -67,7 +67,7 @@ def subparser(subparsers): 'specified name' ) file_args.add_argument( - '--outdir', '--output-dir', + '--output-dir', '--outdir', help='output computed signatures to this directory', ) file_args.add_argument( diff --git a/src/sourmash/cli/sketch/protein.py b/src/sourmash/cli/sketch/protein.py index d074849f0a..edc199b83c 100644 --- a/src/sourmash/cli/sketch/protein.py +++ b/src/sourmash/cli/sketch/protein.py @@ -67,7 +67,7 @@ def subparser(subparsers): 'specified name' ) file_args.add_argument( - '--outdir', '--output-dir', + '--output-dir', '--outdir', help='output computed signatures to this directory', ) file_args.add_argument( diff --git a/src/sourmash/cli/sketch/translate.py b/src/sourmash/cli/sketch/translate.py index 78a64a6ec1..79356bd5a0 100644 --- a/src/sourmash/cli/sketch/translate.py +++ b/src/sourmash/cli/sketch/translate.py @@ -67,7 +67,7 @@ def subparser(subparsers): 'specified name' ) file_args.add_argument( - '--outdir', '--output-dir', + '--output-dir', '--outdir', help='output computed signatures to this directory', ) file_args.add_argument( diff --git a/src/sourmash/command_compute.py b/src/sourmash/command_compute.py index e6ac6b3165..1dda0bcccd 100644 --- a/src/sourmash/command_compute.py +++ b/src/sourmash/command_compute.py @@ -114,8 +114,8 @@ def compute(args): error("ERROR: must specify -o with --merge") sys.exit(-1) - if args.output and args.outdir: - error("ERROR: --outdir doesn't make sense with -o/--output") + if args.output and args.output_dir: + error("ERROR: --output-dir doesn't make sense with -o/--output") sys.exit(-1) if args.track_abundance: @@ -162,8 +162,8 @@ def _compute_individual(args, signatures_factory): if open_output_each_time: # for each input file, construct output filename sigfile = os.path.basename(filename) + '.sig' - if args.outdir: - sigfile = os.path.join(args.outdir, sigfile) + if args.output_dir: + sigfile = os.path.join(args.output_dir, sigfile) # does it already exist? skip if so. if os.path.exists(sigfile) and not args.force: @@ -237,7 +237,7 @@ def _compute_individual(args, signatures_factory): save_sigs = None - # if --output specified, all collected signatures => args.output, + # if --output-dir specified, all collected signatures => args.output, # and we need to close here. if args.output and save_sigs is not None: save_sigs.close() diff --git a/src/sourmash/command_sketch.py b/src/sourmash/command_sketch.py index e4cef1a7b7..6b5c1c5b51 100644 --- a/src/sourmash/command_sketch.py +++ b/src/sourmash/command_sketch.py @@ -186,8 +186,8 @@ def _execute_sketch(args, signatures_factory): error("ERROR: must specify -o with --merge") sys.exit(-1) - if args.output and args.outdir: - error("ERROR: --outdir doesn't make sense with -o/--output") + if args.output and args.output_dir: + error("ERROR: --output-dir doesn't make sense with -o/--output") sys.exit(-1) # get number of output sigs: diff --git a/src/sourmash/sig/__main__.py b/src/sourmash/sig/__main__.py index c4838db0d4..77b224bb63 100644 --- a/src/sourmash/sig/__main__.py +++ b/src/sourmash/sig/__main__.py @@ -133,10 +133,10 @@ def split(args): output_scaled_template = '{md5sum}.k={ksize}.scaled={scaled}.{moltype}.dup={dup}.{basename}.sig' output_num_template = '{md5sum}.k={ksize}.num={num}.{moltype}.dup={dup}.{basename}.sig' - if args.outdir: - if not os.path.exists(args.outdir): - notify(f'Creating --outdir {args.outdir}') - os.mkdir(args.outdir) + if args.output_dir: + if not os.path.exists(args.output_dir): + notify(f'Creating --output-dir {args.output_dir}') + os.mkdir(args.output_dir) progress = sourmash_args.SignatureLoadingProgress() loader = sourmash_args.load_many_signatures(args.signatures, @@ -179,8 +179,8 @@ def split(args): output_names.add(output_name) - if args.outdir: - output_name = os.path.join(args.outdir, output_name) + if args.output_dir: + output_name = os.path.join(args.output_dir, output_name) if os.path.exists(output_name): notify(f"** overwriting existing file {format(output_name)}") diff --git a/tests/test_sourmash_compute.py b/tests/test_sourmash_compute.py index f6c4f1b07d..cb3c48fc32 100644 --- a/tests/test_sourmash_compute.py +++ b/tests/test_sourmash_compute.py @@ -178,7 +178,7 @@ def test_do_sourmash_compute_output_and_name_valid_file_outdir(c): '--outdir', c.location) errmsg = c.last_result.err - assert "ERROR: --outdir doesn't make sense with -o/--output" in errmsg + assert "ERROR: --output-dir doesn't make sense with -o/--output" in errmsg def test_do_sourmash_compute_singleton(): diff --git a/tests/test_sourmash_sketch.py b/tests/test_sourmash_sketch.py index a93dadf1a5..20769fc27e 100644 --- a/tests/test_sourmash_sketch.py +++ b/tests/test_sourmash_sketch.py @@ -504,7 +504,7 @@ def test_do_sourmash_sketchdna_output_and_name_valid_file_outdir(c): '--outdir', c.location) errmsg = c.last_result.err - assert "ERROR: --outdir doesn't make sense with -o/--output" in errmsg + assert "ERROR: --output-dir doesn't make sense with -o/--output" in errmsg def test_do_sourmash_sketchdna_singleton(runtmp):