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

[MRG] add --output-dir as alias for every --outdir #1817

Merged
merged 5 commits into from
Feb 26, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/sourmash/cli/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/sourmash/cli/sig/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/sourmash/cli/sketch/dna.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/sourmash/cli/sketch/protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/sourmash/cli/sketch/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/sourmash/command_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/sourmash/command_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions src/sourmash/sig/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)}")
Expand Down
22 changes: 22 additions & 0 deletions tests/test_cmd_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sourmash_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
17 changes: 16 additions & 1 deletion tests/test_sourmash_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -489,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):
Expand Down