Skip to content

Commit

Permalink
bump to version v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetit3 committed Jan 29, 2025
1 parent 8b7ad09 commit c3cb0c9
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 249 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## 1.4.0


- added:
- `bactopia-pubmlst-setup` to setup PubMLST REST API connections
- `bactopia-pubmlst-build` to build PubMLST databases compatible with `mlst` Bactopia Tool

## 1.3.0

Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ A Python package for working with [Bactopia](https://bactopia.github.io/)

There are many subcommands available in Bactopia. Here is a brief description of each command:

| Command | Description |
|----------------------|----------------------------------------------------------------------------|
| `bactopia-citations` | Print out tools and citations used throughout Bactopia |
| `bactopia-datasets` | Download optional datasets to supplement your analyses with Bactopia |
| `bactopia-download` | Builds Bactopia environments for use with Nextflow. |
| `bactopia-prepare` | Create a 'file of filenames' (FOFN) of samples to be processed by Bactopia |
| `bactopia-search` | Query against ENA and SRA for public accessions to process with Bactopia |
| `bactopia-summary` | Generate a summary table from the Bactopia results. |
| Command | Description |
|---------------------------|----------------------------------------------------------------------------|
| `bactopia-citations` | Print out tools and citations used throughout Bactopia |
| `bactopia-datasets` | Download optional datasets to supplement your analyses with Bactopia |
| `bactopia-download` | Builds Bactopia environments for use with Nextflow. |
| `bactopia-prepare` | Create a 'file of filenames' (FOFN) of samples to be processed by Bactopia |
| `bactopia-search` | Query against ENA and SRA for public accessions to process with Bactopia |
| `bactopia-summary` | Generate a summary table from the Bactopia results. |
| `bactopia-atb-downloader` | Download assemblies from AllTheBacteria for use with Bactopia Tools |
| `bactopia-atb-formatter` | Restructure All-the-Bacteria assemblies to allow usage with Bactopia Tools |
| `bactopia-pubmlst-setup` | One-time setup for interacting with the PubMLST API |
| `bactopia-pubmlst-build` | Build PubMLST databases for use with the 'mlst' Bactopia Tool. |

Below is the `--help` output for each subcommand.

Expand Down
15 changes: 8 additions & 7 deletions bactopia/cli/pubmlst/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
available_databases,
build_blast_db,
download_database,
print_citation,
)

# Set up Rich
Expand All @@ -21,7 +22,7 @@
click.rich_click.USE_RICH_MARKUP = True
click.rich_click.OPTION_GROUPS = {
# Use underscores in parameters, since these are also passed to Nextflow
"bactopia-pubmlst-download": [
"bactopia-pubmlst-build": [
{
"name": "Required Options",
"options": [
Expand Down Expand Up @@ -63,9 +64,7 @@
@click.option(
"--database",
"-d",
default="pubmlst_yersinia_seqdef",
show_default=True,
help="The organism database to interact with for setup. (Use 'all' to download all databases.)",
help="A known organism database to download. (Use 'all' to download all databases.)",
)
@click.option(
"--site",
Expand All @@ -78,7 +77,7 @@
@click.option(
"--token-dir",
"-t",
default=".bactopia/pubmlst",
default=f"{Path.home()}/.bactopia",
show_default=True,
help="The directory where the token file is saved.",
)
Expand Down Expand Up @@ -114,7 +113,7 @@ def pubmlst_download(
verbose: bool,
silent: bool,
):
"""Download specific database files from PubMLST or Pasteur."""
"""Build PubMLST databases for use with the 'mlst' Bactopia Tool."""
# Setup logs
logging.basicConfig(
format="%(asctime)s:%(name)s:%(levelname)s - %(message)s",
Expand Down Expand Up @@ -184,9 +183,11 @@ def pubmlst_download(
if not skip_blast:
# Build MLST database
build_blast_db(
f"{out_dir}/mlstdb",
out_dir,
)

print_citation()


def main():
if len(sys.argv) == 1:
Expand Down
15 changes: 12 additions & 3 deletions bactopia/cli/pubmlst/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rich.logging import RichHandler

import bactopia
from bactopia.databases.pubmlst.utils import setup_pubmlst
from bactopia.databases.pubmlst.utils import print_citation, setup_pubmlst

# Set up Rich
stderr = rich.console.Console(stderr=True)
Expand Down Expand Up @@ -58,6 +58,7 @@
@click.option(
"--site",
"-s",
default="pubmlst",
show_default=True,
type=click.Choice(["pubmlst", "pasteur"], case_sensitive=True),
help="Only print citation matching a given name",
Expand All @@ -72,7 +73,7 @@
@click.option(
"--save-dir",
"-sd",
default=".bactopia/pubmlst",
default=f"{Path.home()}/.bactopia",
show_default=True,
help="The directory to save the token",
)
Expand All @@ -95,7 +96,14 @@ def pubmlst_setup(
format="%(asctime)s:%(name)s:%(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[
RichHandler(rich_tracebacks=True, console=rich.console.Console(stderr=True))
RichHandler(
rich_tracebacks=True,
console=rich.console.Console(stderr=True),
show_time=True if verbose else False,
show_level=True if verbose else False,
show_path=True,
markup=True,
)
],
)
logging.getLogger().setLevel(
Expand All @@ -114,6 +122,7 @@ def pubmlst_setup(
)
sys.exit(1)
setup_pubmlst(site, database, token_file, client_id, client_secret)
print_citation()


def main():
Expand Down
27 changes: 22 additions & 5 deletions bactopia/databases/pubmlst/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
from bactopia.utils import execute


def print_citation():
"""
Print the citation for PubMLST and Bactopia
"""
logging.info(
"\n\n"
"If you make use of 'bactopia-pubmlst-(setup|build)' commands and 'PubMLST' database files, please cite the following:\n\n"
"'PubMLST'\n"
"Jolley, K. A., Bray, J. E., & Maiden, M. C. J. (2018). Open-access bacterial population genomics: BIGSdb software, the Pubmlst.org website and their applications. Wellcome Open Research, 3, 124. https://doi.org/10.12688/wellcomeopenres.14826.1\n\n"
"'Bactopia'\n"
"Petit III RA, Read TD Bactopia - a flexible pipeline for complete analysis of bacterial genomes. mSystems 5 (2020) https://doi.org/10.1128/mSystems.00190-20\n\n"
"adios!"
)


def setup_pubmlst(
site: str, database: str, token_file: str, client_id: str, client_secret: str
):
Expand Down Expand Up @@ -115,7 +130,7 @@ def check_session(site: str, token_file: str, database: str = "yersinia") -> dic
tokens = parse_json(token_file)

if not tokens["session_token"] or not tokens["session_secret"]:
logging.warning("Session token not found, will request a new one")
logging.debug("Session token not found, will request a new one")
needs_update = True
else:
# Try querying the API to see if the session token is still valid
Expand Down Expand Up @@ -548,13 +563,14 @@ def download_database(
logging.info(f"'{database}' complete")


def build_blast_db(database_dir: str):
def build_blast_db(out_dir: str):
"""
Build a BLAST database from the loci FASTA files that is compatible with 'tseemann/mlst'
Args:
database_dir (str): The directory containing the loci FASTA files
out_dir (str): The directory containing the loci FASTA files
"""
database_dir = f"{out_dir}/mlstdb"
blast_db_dir = f"{database_dir}/blast"
if not Path(blast_db_dir).exists():
Path(blast_db_dir).mkdir(parents=True, exist_ok=True)
Expand All @@ -579,7 +595,7 @@ def build_blast_db(database_dir: str):

# Build the BLAST database
execute(
f"makeblastdb -hash_index -in mlst.fa -dbtype nucl -title 'PubMLST' -parse_seqids",
"makeblastdb -hash_index -in mlst.fa -dbtype nucl -title 'PubMLST' -parse_seqids",
directory=blast_db_dir,
)

Expand All @@ -589,4 +605,5 @@ def build_blast_db(database_dir: str):

# Tar the BLAST database
logging.info(f"Save BLAST database to '{database_dir}/mlst.tar.gz'")
execute(f"tar -czvf mlst.tar.gz mlstdb/", directory=database_dir)
execute("tar -czvf mlst.tar.gz mlstdb/", directory=out_dir)
shutil.move(f"{out_dir}/mlst.tar.gz", f"{database_dir}/mlst.tar.gz")
Empty file added bactopia/reports/__init__.py
Empty file.
Empty file.
5 changes: 3 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ channels:
- conda-forge
- bioconda
dependencies:
- blast
- pigz
- poetry =1.3
- python >=3.8
- poetry
- python >=3.8,<3.12
- wget
Loading

0 comments on commit c3cb0c9

Please sign in to comment.