Skip to content

Commit

Permalink
[MRG] refactor and simplify sourmash sig subcommand signature loadi…
Browse files Browse the repository at this point in the history
…ng (#1672)

* add -f and --from-file to downsample

* upgrade downsample error handling and output

* more better status output for downsample

* use new sig loading in cat, describe, and split

* support --from-file and force for rest of sig subcommands

* remove unused import

* trap expected errors and print out nicely

* turn LoadManySignatures into a generator

* test force

* add num test for sig split

* add some flatten tests for code cov

* add test for both --num and --scaled

* add picklist checks to everything

* minor cleanup

* minor cleanup

* factor out common argparse

* clean up and test error output

* add many more tests etc.

* add picklist test for sig cat

* remove picklists from subtract for now

Co-authored-by: Tessa Pierce Ward <bluegenes@users.noreply.github.com>
  • Loading branch information
ctb and bluegenes authored Jul 16, 2021
1 parent b16930a commit 67aba79
Show file tree
Hide file tree
Showing 20 changed files with 746 additions and 308 deletions.
2 changes: 0 additions & 2 deletions src/sourmash/cli/categorize.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"'sourmash categorize' - query an SBT for bes match, with many signatures."

import argparse

from sourmash.cli.utils import add_ksize_arg, add_moltype_args


Expand Down
2 changes: 0 additions & 2 deletions src/sourmash/cli/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
---
"""

from argparse import FileType

from sourmash.minhash import get_minhash_default_seed
from sourmash.cli.utils import add_construct_moltype_args

Expand Down
1 change: 0 additions & 1 deletion src/sourmash/cli/import_csv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""'sourmash import_csv' description goes here"""

import sys
from sourmash.logging import notify


Expand Down
7 changes: 5 additions & 2 deletions src/sourmash/cli/sig/cat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""concatenate signature files"""

import sourmash
from sourmash.logging import notify, print_results, error
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
Expand All @@ -27,6 +27,9 @@ def subparser(subparsers):
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)


def main(args):
Expand Down
17 changes: 14 additions & 3 deletions src/sourmash/cli/sig/describe.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""show details of signature"""

import sourmash
from sourmash.logging import notify, print_results, error
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
subparser = subparsers.add_parser('describe')
subparser.add_argument('signatures', nargs='+')
subparser.add_argument('signatures', nargs='*')
subparser.add_argument(
'-q', '--quiet', action='store_true',
help='suppress non-error output'
Expand All @@ -15,6 +15,17 @@ def subparser(subparsers):
'--csv', metavar='FILE',
help='output information to a CSV file'
)
subparser.add_argument(
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
subparser.add_argument(
'--from-file',
help='a text file containing a list of files to load signatures from'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)


def main(args):
Expand Down
16 changes: 12 additions & 4 deletions src/sourmash/cli/sig/downsample.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""downsample one or more signatures"""

import sys

from sourmash.cli.utils import add_moltype_args, add_ksize_arg
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
subparser = subparsers.add_parser('downsample')
subparser.add_argument('signatures', nargs="+")
subparser.add_argument('signatures', nargs="*")
subparser.add_argument(
'--scaled', type=int, default=0,
help='scaled value to downsample to'
)
subparser.add_argument(
'--from-file',
help='a text file containing a list of files to load signatures from'
)
subparser.add_argument(
'--num', metavar='N', type=int, default=0,
help='num value to downsample to'
Expand All @@ -25,8 +28,13 @@ def subparser(subparsers):
help='output signature to this file (default stdout)',
default='-',
)
subparser.add_argument(
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)


def main(args):
Expand Down
2 changes: 0 additions & 2 deletions src/sourmash/cli/sig/export.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""export a signature, e.g. to mash"""

import sys

from sourmash.cli.utils import add_ksize_arg, add_moltype_args


Expand Down
12 changes: 9 additions & 3 deletions src/sourmash/cli/sig/extract.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""extract one or more signatures"""

import sys

from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
subparser = subparsers.add_parser('extract')
subparser.add_argument('signatures', nargs='+')
subparser.add_argument('signatures', nargs='*')
subparser.add_argument(
'-q', '--quiet', action='store_true',
help='suppress non-error output'
Expand All @@ -26,6 +24,14 @@ def subparser(subparsers):
'--name', default=None,
help='select signatures whose name contains this substring'
)
subparser.add_argument(
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
subparser.add_argument(
'--from-file',
help='a text file containing a list of files to load signatures from'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)
Expand Down
2 changes: 0 additions & 2 deletions src/sourmash/cli/sig/filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""filter k-mers on abundance"""

import sys

from sourmash.cli.utils import add_moltype_args, add_ksize_arg


Expand Down
16 changes: 12 additions & 4 deletions src/sourmash/cli/sig/flatten.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""remove abundances"""

import sys

from sourmash.cli.utils import add_moltype_args, add_ksize_arg
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
subparser = subparsers.add_parser('flatten')
subparser.add_argument('signatures', nargs='+')
subparser.add_argument('signatures', nargs='*')
subparser.add_argument(
'-q', '--quiet', action='store_true',
help='suppress non-error output'
Expand All @@ -25,8 +24,17 @@ def subparser(subparsers):
'--name', default=None,
help='select signatures whose name contains this substring'
)
subparser.add_argument(
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
subparser.add_argument(
'--from-file',
help='a text file containing a list of files to load signatures from'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)


def main(args):
Expand Down
2 changes: 0 additions & 2 deletions src/sourmash/cli/sig/ingest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""ingest/import a mash or other signature"""

import sys


def subparser(subparsers):
# Dirty hack to simultaneously support new and previous interface
Expand Down
16 changes: 12 additions & 4 deletions src/sourmash/cli/sig/intersect.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""intersect one or more signatures"""

import sys

from sourmash.cli.utils import add_moltype_args, add_ksize_arg
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
subparser = subparsers.add_parser('intersect')
subparser.add_argument('signatures', nargs='+')
subparser.add_argument('signatures', nargs='*')
subparser.add_argument(
'-q', '--quiet', action='store_true',
help='suppress non-error output'
Expand All @@ -20,8 +19,17 @@ def subparser(subparsers):
'-A', '--abundances-from', metavar='FILE',
help='intersect with & take abundances from this signature'
)
subparser.add_argument(
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
subparser.add_argument(
'--from-file',
help='a text file containing a list of files to load signatures from'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)


def main(args):
Expand Down
3 changes: 0 additions & 3 deletions src/sourmash/cli/sig/manifest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""create a manifest for a collection of signatures"""

import sourmash
from sourmash.logging import notify, print_results, error


def subparser(subparsers):
subparser = subparsers.add_parser('manifest')
Expand Down
16 changes: 12 additions & 4 deletions src/sourmash/cli/sig/merge.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""merge one or more signatures"""

import sys

from sourmash.cli.utils import add_moltype_args, add_ksize_arg
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
subparser = subparsers.add_parser('merge')
subparser.add_argument('signatures', nargs='+')
subparser.add_argument('signatures', nargs='*')
subparser.add_argument(
'-q', '--quiet', action='store_true',
help='suppress non-error output'
Expand All @@ -24,8 +23,17 @@ def subparser(subparsers):
'--name',
help='rename merged signature'
)
subparser.add_argument(
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
subparser.add_argument(
'--from-file',
help='a text file containing a list of files to load signatures from'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)


def main(args):
Expand Down
14 changes: 12 additions & 2 deletions src/sourmash/cli/sig/rename.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""rename signature"""

from sourmash.cli.utils import add_ksize_arg, add_moltype_args
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
subparser = subparsers.add_parser('rename')
subparser.add_argument('sigfiles', nargs='+')
subparser.add_argument('signatures', nargs='*')
subparser.add_argument('name')
subparser.add_argument(
'-q', '--quiet', action='store_true',
Expand All @@ -20,8 +21,17 @@ def subparser(subparsers):
help='output renamed signature to this file (default stdout)',
default='-'
)
subparser.add_argument(
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
subparser.add_argument(
'--from-file',
help='a text file containing a list of files to load signatures from'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)


def main(args):
Expand Down
16 changes: 14 additions & 2 deletions src/sourmash/cli/sig/split.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
"""concatenate signature files"""

import sourmash
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg,
add_picklist_args)


def subparser(subparsers):
subparser = subparsers.add_parser('split')
subparser.add_argument('signatures', nargs='+')
subparser.add_argument('signatures', nargs='*')
subparser.add_argument(
'-q', '--quiet', action='store_true',
help='suppress non-error output'
)
subparser.add_argument(
'--outdir', help='output signatures to this directory'
)
subparser.add_argument(
'-f', '--force', action='store_true',
help='try to load all files as signatures'
)
subparser.add_argument(
'--from-file',
help='a text file containing a list of files to load signatures from'
)
add_ksize_arg(subparser, 31)
add_moltype_args(subparser)
add_picklist_args(subparser)


def main(args):
Expand Down
4 changes: 1 addition & 3 deletions src/sourmash/cli/sig/subtract.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""subtract one or more signatures"""

import sys

from sourmash.cli.utils import add_moltype_args, add_ksize_arg
from sourmash.cli.utils import (add_moltype_args, add_ksize_arg)


def subparser(subparsers):
Expand Down
Loading

0 comments on commit 67aba79

Please sign in to comment.