2025-01-17 16:40:39 +00:00
|
|
|
from argparse import ArgumentParser, Namespace
|
2025-01-10 21:15:59 +00:00
|
|
|
import asyncio
|
2025-02-12 21:54:34 +00:00
|
|
|
from autobigs.engine.analysis.bigsdb import BIGSdbIndex
|
2025-01-10 21:15:59 +00:00
|
|
|
|
|
|
|
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."
|
|
|
|
)
|
|
|
|
|
2025-01-17 16:40:39 +00:00
|
|
|
parser.set_defaults(run=run_asynchronously)
|
|
|
|
return parser
|
2025-01-10 21:15:59 +00:00
|
|
|
|
2025-01-17 16:40:39 +00:00
|
|
|
async def run(args: Namespace):
|
2025-01-10 21:15:59 +00:00
|
|
|
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}")
|
|
|
|
|
2025-01-17 16:40:39 +00:00
|
|
|
if not (args.list_dbs or len(args.list_bigsdb_schemas) > 0):
|
|
|
|
print("Nothing to do. Try specifying \"-l\".")
|
|
|
|
|
|
|
|
def run_asynchronously(args: Namespace):
|
2025-01-10 21:15:59 +00:00
|
|
|
asyncio.run(run(args))
|
|
|
|
|