From 5449ae0c68553b3022a09835de7b1c1dac300dbd Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Fri, 10 Jan 2025 17:22:12 +0000 Subject: [PATCH] Moved CLI to automlst.cli repo --- .devcontainer/devcontainer.json | 2 +- pyproject.toml | 5 +-- src/automlst/cli/__init__.py | 0 src/automlst/cli/info.py | 43 -------------------- src/automlst/cli/meta.py | 2 - src/automlst/cli/program.py | 27 ------------- src/automlst/cli/st.py | 69 --------------------------------- 7 files changed, 2 insertions(+), 146 deletions(-) delete mode 100644 src/automlst/cli/__init__.py delete mode 100644 src/automlst/cli/info.py delete mode 100644 src/automlst/cli/meta.py delete mode 100644 src/automlst/cli/program.py delete mode 100644 src/automlst/cli/st.py diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2ec9b03..c58d0e4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,7 +12,7 @@ // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "pip3 install --user -r requirements.txt && pipx install . -e", + "postCreateCommand": "pip3 install --user -r requirements.txt", "customizations": { "vscode": { "extensions": [ diff --git a/pyproject.toml b/pyproject.toml index 0946055..f1eee6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools>=64", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" [project] -name = "automlst" +name = "automlst.engine" dynamic = ["version"] dependencies = [ @@ -13,9 +13,6 @@ dependencies = [ requires-python = ">=3.11" description = "A tool to rapidly fetch fetch MLST profiles given sequences for various diseases." -[project.scripts] -automlst = "automlst.cli.program:run" - [tool.setuptools_scm] [tool.pyright] diff --git a/src/automlst/cli/__init__.py b/src/automlst/cli/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/automlst/cli/info.py b/src/automlst/cli/info.py deleted file mode 100644 index fe044ac..0000000 --- a/src/automlst/cli/info.py +++ /dev/null @@ -1,43 +0,0 @@ -from argparse import ArgumentParser -import asyncio -from automlst.engine.remote.databases.bigsdb import BIGSdbIndex - - -def setup_parser(parser: ArgumentParser): - parser.description = "Fetches the latest BIGSdb MLST database definitions." - parser.add_argument( - "--retrieve-bigsdbs", "-l", - action="store_true", - dest="list_dbs", - required=False, - default=False, - help="Lists all known BIGSdb MLST databases (fetched from known APIs and cached)." - ) - - parser.add_argument( - "--retrieve-bigsdb-schemas", "-lschemas", - nargs="+", - action="extend", - dest="list_bigsdb_schemas", - required=False, - default=[], - type=str, - help="Lists the known schema IDs for a given BIGSdb sequence definition database name. The name, and then the ID of the schema is given." - ) - - parser.set_defaults(func=run_asynchronously) - -async def run(args): - async with BIGSdbIndex() as bigsdb_index: - if args.list_dbs: - known_seqdef_dbs = await bigsdb_index.get_known_seqdef_dbs(force=False) - print("\n".join(known_seqdef_dbs.keys())) - - for bigsdb_schema_name in args.list_bigsdb_schemas: - schemas = await bigsdb_index.get_schemas_for_seqdefdb(bigsdb_schema_name) - for schema_desc, schema_id in schemas.items(): - print(f"{schema_desc}: {schema_id}") - -def run_asynchronously(args): - asyncio.run(run(args)) - diff --git a/src/automlst/cli/meta.py b/src/automlst/cli/meta.py deleted file mode 100644 index d45096d..0000000 --- a/src/automlst/cli/meta.py +++ /dev/null @@ -1,2 +0,0 @@ -def get_module_base_name(name): - return name.split(".")[-1] diff --git a/src/automlst/cli/program.py b/src/automlst/cli/program.py deleted file mode 100644 index 02e1847..0000000 --- a/src/automlst/cli/program.py +++ /dev/null @@ -1,27 +0,0 @@ -import argparse -import asyncio -import datetime -from os import path -import os - -from automlst.cli import info, st -from automlst.cli.meta import get_module_base_name -from automlst.engine.data.genomics import NamedString -from automlst.engine.local.abif import read_abif -from automlst.engine.local.csv import write_mlst_profiles_as_csv -from automlst.engine.local.fasta import read_fasta -from automlst.engine.remote.databases.bigsdb import BIGSdbIndex - -root_parser = argparse.ArgumentParser() -subparsers = root_parser.add_subparsers(required=True) - -info.setup_parser(subparsers.add_parser(get_module_base_name(info.__name__))) -st.setup_parser(subparsers.add_parser(get_module_base_name(st.__name__))) - - -def run(): - args = root_parser.parse_args() - args.func(args) - -if __name__ == "__main__": - run() \ No newline at end of file diff --git a/src/automlst/cli/st.py b/src/automlst/cli/st.py deleted file mode 100644 index d8670c6..0000000 --- a/src/automlst/cli/st.py +++ /dev/null @@ -1,69 +0,0 @@ - -from argparse import ArgumentParser -import asyncio -import datetime -from automlst.engine.local.csv import write_mlst_profiles_as_csv -from automlst.engine.local.fasta import read_multiple_fastas -from automlst.engine.remote.databases.bigsdb import BIGSdbIndex - - -def setup_parser(parser: ArgumentParser): - parser.description = "Returns MLST exact profile matches." - parser.add_argument( - "fastas", - nargs="+", - action='extend', - default=[], - type=str, - help="The FASTA files to process. Multiple can be listed." - ) - - parser.add_argument( - "seqdefdb", - help="The BIGSdb seqdef database to use for typing." - ) - - parser.add_argument( - "schema", - type=int, - help="The BIGSdb seqdef database schema ID (integer) to use for typing." - ) - - parser.add_argument( - "out", - default=f'./{datetime.datetime.now().strftime(r"%Y%m%d%H%M%S")}', - help="The output CSV name (.csv will be appended)." - ) - - parser.add_argument( - "--exact", "-ex", - action="store_true", - dest="exact", - required=False, - default=False, - help="Should run exact matching rather than returning all similar ones" - ) - - parser.add_argument( - "--stop-on-fail", "-sof", - action="store_true", - dest="stop_on_fail", - required=False, - default=False, - help="Should the algorithm stop in the case there are no matches (or partial matches when expecting exact matches)." - ) - parser.set_defaults(func=run_asynchronously) - -async def run(args): - async with BIGSdbIndex() as bigsdb_index: - gen_strings = read_multiple_fastas(args.fastas) - async with await bigsdb_index.build_profiler_from_seqdefdb(args.seqdefdb, args.schema) as mlst_profiler: - mlst_profiles = mlst_profiler.profile_multiple_strings(gen_strings, exact=args.exact) - failed = await write_mlst_profiles_as_csv(mlst_profiles, args.out) - if len(failed) > 0: - print(f"A total of {len(failed)} IDs failed:\n{"\n".join(failed)}") - print(f"Completed fetching MLSTs for {len(args.fastas)} sequences.") - -def run_asynchronously(args): - asyncio.run(run(args)) -