-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MRG] implement
tax grep
to produce identifier picklists from taxon…
…omies (#2178) * add basics of sourmash tax grep command * initial implementation * fixed bug; added various args * more tests * support gzipped taxonomy files * let 'prepare' save gzip csv files, too * switch to outputting lineage; refactor * fix and test invert match * more tests * add --count * comment * upd docs * add test for tax prepare combining * test multiple, duplicate tax * finish? tests * implement --force * update usage string * Update doc/command-line.md Co-authored-by: Tessa Pierce Ward <bluegenes@users.noreply.github.com> Co-authored-by: Tessa Pierce Ward <bluegenes@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
512 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"""search taxonomies and output picklists..""" | ||
|
||
usage=""" | ||
sourmash tax grep <term> --taxonomy-csv <taxonomy_file> [ ... ] | ||
`sourmash tax grep` searches taxonomies for matching strings, | ||
optionally restricting the string search to a specific taxonomic rank. | ||
It creates new files containing matching taxonomic entries; these new | ||
files can serve as taxonomies and can also be used as picklists. | ||
Please see the 'tax grep' documentation for more details: | ||
https://sourmash.readthedocs.io/en/latest/command-line.html#sourmash-tax-grep-subset-taxonomies-and-create-picklists-based-on-taxonomy-string-matches | ||
""" | ||
|
||
import sourmash | ||
from sourmash.logging import notify, print_results, error | ||
|
||
|
||
def subparser(subparsers): | ||
subparser = subparsers.add_parser('grep', usage=usage) | ||
subparser.add_argument('pattern') | ||
subparser.add_argument('-r', '--rank', | ||
help="search only this rank", | ||
choices=['superkingdom', | ||
'phylum', | ||
'class', | ||
'order', | ||
'family', | ||
'genus', | ||
'species']) | ||
subparser.add_argument( | ||
'-v', '--invert-match', | ||
help="select non-matching lineages", | ||
action="store_true" | ||
) | ||
subparser.add_argument( | ||
'-i', '--ignore-case', | ||
help="ignore case distinctions (search lower and upper case both)", | ||
action="store_true" | ||
) | ||
subparser.add_argument( | ||
'--silent', '--no-picklist-output', | ||
help="do not output picklist", | ||
action='store_true', | ||
) | ||
subparser.add_argument( | ||
'-c', '--count', | ||
help="only output a count of discovered lineages; implies --silent", | ||
action='store_true' | ||
) | ||
subparser.add_argument( | ||
'-q', '--quiet', action='store_true', | ||
help='suppress non-error output' | ||
) | ||
subparser.add_argument( | ||
'-t', '--taxonomy-csv', '--taxonomy', metavar='FILE', | ||
nargs="+", required=True, | ||
help='database lineages' | ||
) | ||
subparser.add_argument( | ||
'-o', '--output', default='-', | ||
help='output file (defaults to stdout)', | ||
) | ||
subparser.add_argument( | ||
'-f', '--force', action = 'store_true', | ||
help='continue past errors in file and taxonomy loading', | ||
) | ||
|
||
def main(args): | ||
import sourmash | ||
return sourmash.tax.__main__.grep(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.