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 --set-name to sig intersect and sig subtract #3162

Merged
merged 26 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
333832b
support more general sig loading in sig overlap
ctb May 12, 2024
9a45829
fix up subtract as well
ctb May 12, 2024
6da2d3a
add sourmash_args.load_one_signature
ctb May 12, 2024
0082c45
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 12, 2024
093ed65
fix one more call to load_one_signature
ctb May 13, 2024
6d7ac35
add tests
ctb May 13, 2024
9a6a61c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2024
76aaafe
rename load/save fns
ctb May 13, 2024
64d2786
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2024
fb28a1b
rename to use _json names
ctb May 13, 2024
dcf5920
ignore zipfile UserWarnings about dup file names
ctb May 13, 2024
266d78a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 13, 2024
35dc642
Merge branch 'latest' of github.com:sourmash-bio/sourmash into upgrad…
ctb May 14, 2024
e3e7d28
Merge branch 'upgrade_sig_cmds' into rename_sig_json_fns
ctb May 14, 2024
1501704
stop unnecessary renaming ;)
ctb May 14, 2024
066d984
add --name to sig intersect and sig subtract
ctb May 14, 2024
db1114d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 14, 2024
053662b
add name output tests to filter, flatten, downsample
ctb May 15, 2024
5070bee
Merge branch 'latest' of github.com:sourmash-bio/sourmash into provid…
ctb May 15, 2024
0791c5d
use --set-name
ctb May 15, 2024
ba3ea49
Merge branch 'provide_name_on_sig' of github.com:sourmash-bio/sourmas…
ctb May 15, 2024
23230e4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 15, 2024
0ce0d8d
update docs for --set-name on intersect, subtract, and merge
ctb May 24, 2024
94406d8
add/prioritize --set-name for sketch dna/protein/translate
ctb May 24, 2024
521bb80
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2024
d3caff1
Merge branch 'latest' of github.com:sourmash-bio/sourmash into provid…
ctb Jun 4, 2024
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
Prev Previous commit
Next Next commit
add --name to sig intersect and sig subtract
  • Loading branch information
ctb committed May 14, 2024
commit 066d984a50a27dbf5c6c2624111ec7b6b46880e8
1 change: 1 addition & 0 deletions src/sourmash/cli/sig/intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def subparser(subparsers):
metavar="FILE",
help="intersect with & take abundances from this signature",
)
subparser.add_argument("--name", help="rename output signature")
subparser.add_argument(
"-f", "--force", action="store_true", help="try to load all files as signatures"
)
Expand Down
1 change: 1 addition & 0 deletions src/sourmash/cli/sig/subtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def subparser(subparsers):
metavar="FILE",
help="intersect with & take abundances from this signature",
)
subparser.add_argument("--name", help="rename output signature")
add_ksize_arg(subparser)
add_moltype_args(subparser)

Expand Down
5 changes: 5 additions & 0 deletions src/sourmash/sig/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ def intersect(args):
intersect_mh = intersect_mh.inflate(abund_sig.minhash)

intersect_sigobj = sourmash.SourmashSignature(intersect_mh)
if args.name:
intersect_sigobj.name = args.name

with sourmash_args.SaveSignaturesToLocation(args.output) as save_sigs:
save_sigs.add(intersect_sigobj)

Expand Down Expand Up @@ -704,6 +707,8 @@ def subtract(args):
subtract_mh = subtract_mh.inflate(abund_sig.minhash)

subtract_sigobj = sourmash.SourmashSignature(subtract_mh)
if args.name:
subtract_sigobj.name = args.name

with sourmash_args.SaveSignaturesToLocation(args.output) as save_sigs:
save_sigs.add(subtract_sigobj)
Expand Down
43 changes: 43 additions & 0 deletions tests/test_cmd_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,28 @@ def test_sig_intersect_1(runtmp):
assert actual_intersect_sig.minhash == test_intersect_sig.minhash


def test_sig_intersect_1_rename(runtmp):
# intersect of 47 and 63 should be intersection of mins
sig47 = utils.get_test_data("47.fa.sig")
sig63 = utils.get_test_data("63.fa.sig")
sig47and63 = utils.get_test_data("47+63-intersect.fa.sig")
runtmp.run_sourmash("sig", "intersect", sig47, sig63,
"--name", "footest")

# stdout should be new signature
out = runtmp.last_result.out

test_intersect_sig = load_one_signature_from_json(sig47and63)
actual_intersect_sig = load_one_signature_from_json(out)

print(test_intersect_sig.minhash)
print(actual_intersect_sig.minhash)
print(out)

assert actual_intersect_sig.minhash == test_intersect_sig.minhash
assert actual_intersect_sig.name == "footest"


def test_sig_intersect_1_fromfile_picklist(runtmp):
c = runtmp

Expand Down Expand Up @@ -793,6 +815,27 @@ def test_sig_subtract_1(runtmp):
assert set(actual_subtract_sig.minhash.hashes.keys()) == set(mins)


def test_sig_subtract_1_name(runtmp):
# subtract of 63 from 47; rename
sig47 = utils.get_test_data("47.fa.sig")
sig63 = utils.get_test_data("63.fa.sig")
runtmp.run_sourmash("sig", "subtract", sig47, sig63,
"--name", "footest")

# stdout should be new signature
out = runtmp.last_result.out

test1_sig = load_one_signature_from_json(sig47)
test2_sig = load_one_signature_from_json(sig63)
actual_subtract_sig = load_one_signature_from_json(out)

mins = set(test1_sig.minhash.hashes.keys())
mins -= set(test2_sig.minhash.hashes.keys())

assert set(actual_subtract_sig.minhash.hashes.keys()) == set(mins)
assert actual_subtract_sig.name == "footest"


def test_sig_subtract_1_sigzip(runtmp):
c = runtmp
# subtract of 63 from 47
Expand Down
Loading