Updated CLI to output more useful information.

This commit is contained in:
Harrison Deng 2025-01-17 16:40:39 +00:00
parent ca59751c35
commit ba72199efc
7 changed files with 58457 additions and 23 deletions

View File

@ -12,7 +12,7 @@
// "forwardPorts": [], // "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created. // Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip3 install --user -r requirements.txt && pip3 install -e .", "postCreateCommand": "pip3 install --user -r requirements.txt",
"customizations": { "customizations": {
"vscode": { "vscode": {
"extensions": [ "extensions": [

39
README.md Normal file
View File

@ -0,0 +1,39 @@
# autoMLST.CLI
A command-line interface based program that allows quickly batched requests for obtaining MLST profiles on multiple FASTA sequences and exporting it as a convenient CSV.
This program is simply a command-line interface for [autoMLST.Engine](https://pypi.org/project/automlst.engine).
## Features
This CLI is capable of exactly what [autoMLST.Engine](https://pypi.org/project/automlst.engine) is capable of:
- Import multiple FASTA files
- Fetch the available BIGSdb databases that is currently live and available
- Fetch the available BIGSdb database schemas for a given MLST database
- Retrieve exact/non-exact MLST allele variant IDs based off a sequence
- Retrieve MLST sequence type IDs based off a sequence
- Output all results to a single CSV
## Usage
This CLI can be installed with `pip`. Please ensure [pip is installed](https://pip.pypa.io/en/stable/installation/). Then:
1. Run `pip install automlst-cli` to install the latest version of the CLI for autoMLST.
2. Once installation is complete, run `automlst --version` to test that the installation succeeded (and that you are running the appropriate version).
3. Run `automlst -h` to get information on how to get started.
### Example
Let's say you have a fasta called `seq.fasta` which contains several sequences. You know all sequences in `seq.fasta` are Bordetella pertussis sequences, and you know you have the sequences for the necessary targets of your schema in each of them. You want to retrieve MLST profiles for all of them. This can be done by:
1. Running `automlst info -l` to list all available `seqdef` databases and find the database associated with Bordetella (you should see one called `pubmlst_bordetella_seqdef`).
2. Then, run `automlst info -lschema pubmlst_bordetella_seqdef` to get the available typing schemas and their associated IDs. In this example, let's assume we want a normal MLST scheme. In this case, we would pay attention to the number next to `MLST` (it should be `3`).
3. Then, run `automlst st -h` and familiarize yourself with the parameters needed for sequence typing.
4. Namely, you should find that you will need to run `automlst st seq.fasta pubmlst_bordetella_seqdef 3 output.csv`. You can optionally include multiple `FASTA` files, and/or `--exact` to only retrieve exact sequence types, and/or `--stop-on-fail` to stop typing if one of your sequences fail to retrieve any type.
5. Sit tight, and wait. The `output.csv` will contain your results once completed.

View File

@ -5,6 +5,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "automlst.cli" name = "automlst.cli"
dynamic = ["version"] dynamic = ["version"]
readme = "README.md"
dependencies = [ dependencies = [
"automlst-engine" "automlst-engine"

View File

@ -1,6 +1,6 @@
from argparse import ArgumentParser from argparse import ArgumentParser, Namespace
import asyncio import asyncio
from automlst.engine.remote.databases.bigsdb import BIGSdbIndex from automlst.engine.data.remote.databases.bigsdb import BIGSdbIndex
def setup_parser(parser: ArgumentParser): def setup_parser(parser: ArgumentParser):
parser.description = "Fetches the latest BIGSdb MLST database definitions." parser.description = "Fetches the latest BIGSdb MLST database definitions."
@ -24,9 +24,10 @@ def setup_parser(parser: ArgumentParser):
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." 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) parser.set_defaults(run=run_asynchronously)
return parser
async def run(args): async def run(args: Namespace):
async with BIGSdbIndex() as bigsdb_index: async with BIGSdbIndex() as bigsdb_index:
if args.list_dbs: if args.list_dbs:
known_seqdef_dbs = await bigsdb_index.get_known_seqdef_dbs(force=False) known_seqdef_dbs = await bigsdb_index.get_known_seqdef_dbs(force=False)
@ -37,6 +38,9 @@ async def run(args):
for schema_desc, schema_id in schemas.items(): for schema_desc, schema_id in schemas.items():
print(f"{schema_desc}: {schema_id}") print(f"{schema_desc}: {schema_id}")
def run_asynchronously(args): if not (args.list_dbs or len(args.list_bigsdb_schemas) > 0):
print("Nothing to do. Try specifying \"-l\".")
def run_asynchronously(args: Namespace):
asyncio.run(run(args)) asyncio.run(run(args))

View File

@ -1,27 +1,39 @@
import argparse import argparse
import asyncio from importlib import metadata
import datetime
from os import path from os import path
import os import os
from automlst.cli import info, st from automlst.cli import info, st
from automlst.cli.meta import get_module_base_name from automlst.cli.meta import get_module_base_name
from automlst.engine.data.genomics import NamedString import importlib
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() root_parser = argparse.ArgumentParser(epilog='Use "%(prog)s info -h" to learn how to get available MLST databases, and their available schemas.'
subparsers = root_parser.add_subparsers(required=True) + ' Once that is done, use "%(prog)s st -h" to learn how to retrieve MLST profiles.'
)
subparsers = root_parser.add_subparsers(required=False)
info.setup_parser(subparsers.add_parser(get_module_base_name(info.__name__))) info.setup_parser(subparsers.add_parser(get_module_base_name(info.__name__)))
st.setup_parser(subparsers.add_parser(get_module_base_name(st.__name__))) st.setup_parser(subparsers.add_parser(get_module_base_name(st.__name__)))
root_parser.add_argument(
"--version",
action="store_true",
default=False,
required=False,
help="Displays the autoMLST.CLI version, and the autoMLST.Engine version."
)
def run(): def run():
args = root_parser.parse_args() args = root_parser.parse_args()
args.func(args) if args.version:
print(f'autoMLST.CLI is running version {
metadata.version("automlst-cli")}.')
print(f'autoMLST.Engine is running version {
metadata.version("automlst-engine")}.')
if hasattr(args, "run"):
args.run(args)
if __name__ == "__main__": if __name__ == "__main__":
run() run()

View File

@ -1,10 +1,10 @@
from argparse import ArgumentParser from argparse import ArgumentParser, Namespace
import asyncio import asyncio
import datetime import datetime
from automlst.engine.local.csv import write_mlst_profiles_as_csv from automlst.engine.data.local.csv import write_mlst_profiles_as_csv
from automlst.engine.local.fasta import read_multiple_fastas from automlst.engine.data.local.fasta import read_multiple_fastas
from automlst.engine.remote.databases.bigsdb import BIGSdbIndex from automlst.engine.data.remote.databases.bigsdb import BIGSdbIndex
def setup_parser(parser: ArgumentParser): def setup_parser(parser: ArgumentParser):
@ -52,9 +52,10 @@ def setup_parser(parser: ArgumentParser):
default=False, default=False,
help="Should the algorithm stop in the case there are no matches (or partial matches when expecting exact matches)." 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) parser.set_defaults(run=run_asynchronously)
return parser
async def run(args): async def run(args: Namespace):
async with BIGSdbIndex() as bigsdb_index: async with BIGSdbIndex() as bigsdb_index:
gen_strings = read_multiple_fastas(args.fastas) gen_strings = read_multiple_fastas(args.fastas)
async with await bigsdb_index.build_profiler_from_seqdefdb(args.seqdefdb, args.schema) as mlst_profiler: async with await bigsdb_index.build_profiler_from_seqdefdb(args.seqdefdb, args.schema) as mlst_profiler:

File diff suppressed because it is too large Load Diff