Skip to main content

gmlst

License: MIT Python 3.12 Bioinformatics

gmlst is a fast Python 3.12 CLI for bacterial genome typing with classical MLST, large cgMLST and wgMLST schemes, and scheme-free discovery workflows. It supports assembled genomes and raw reads, several alignment backends, multiple public data providers, custom local schemes, offline cache reuse, and local MST visualization from one command-line interface.

English | 简体中文

Features

  • 🧬 Broad typing support: run gmlst typing mlst, gmlst typing cgmlst, and gmlst typing tgmlst from the same CLI.
  • ⚡ Multiple backends: use BLAST+, KMA, minimap2, MUMmer4, with built-in exact-hash pre-resolution for cgMLST workflows.
  • 🧫 FASTA and FASTQ input: type assembled genomes and paired-end raw reads with backend-aware handling.
  • 🗂️ Multiple providers: work with PubMLST, Pasteur BIGSdb, Enterobase, cgmlst.org, and local custom schemes.
  • 🧠 Smart cgMLST modes: choose fast, ultrafast, or balanced depending on speed and evidence needs.
  • 🆕 Novel allele workflow: detect novel alleles, extract novel profiles, and build custom laboratory databases.
  • 🔍 Scheme-free typing: run tgmlst for de novo allele discovery without a preselected public scheme.
  • 📦 Rich outputs: export tsv, json, pretty, and GrapeTree-compatible tables.
  • 🌐 Local visualization: launch a Flask + Vue web app with gmlst visual web to inspect MST results locally.
  • 💾 Cache-first operation: downloaded schemes and built indexes are reused for offline or repeated runs.
  • 🧵 Batch processing: use sample-level workers and backend threads for high-throughput workflows.
  • 🧬 CDS-aware calling: cgMLST workflows can use Pyrodigal for CDS prediction and chewBBACA-compatible classification paths.
  • 🤖 AI-agent friendly: versioned JSON envelopes, data-only stdout, and stable exit codes make the CLI safe to drive from scripts and agents.

Installation

Quick install

A conda virtual environment is recommended for installing gmlst.

conda create -n gmlst
conda activate gmlst
conda install python=3.12
pip install gmlst

To make gmlst functional, you also need to install bioinformatics alignment tools. Currently, FASTA data supports the blastn, minimap2, nucmer, and kma backends. FASTQ data supports the kma backend. Install the ones you need based on your data types.

# Install all backend dependencies for full functionality
conda install blast minimap2 mummer4 kma

For other installation methods (Pixi, uv, source, Docker), see the Installation Guide.

Quick Start

1. Browse and download a scheme

# Zero-setup: skip scheme selection entirely — gmlst identifies the species
# from the genome, picks the matching scheme, downloads it, and types
gmlst typing mlst sample.fna

# Know the organism but not the scheme name? Resolve it with -n
# (unique match auto-selects; multiple matches print a candidate table)
gmlst typing mlst -n bordetella sample.fna

# The species fingerprint database powers auto-detection; build it on demand
gmlst scheme update-fingerprints

# List cached and available schemes (downloaded schemes shown in bold)
gmlst scheme list

# Search across scheme name, organism, description, and provider
gmlst scheme search saureus
gmlst scheme search "salmonella" -t cgmlst

# Restrict to one provider
gmlst scheme list -p pubmlst

# Download a scheme to the local cache
gmlst scheme download saureus_1

# Re-download with low concurrency (avoid 429 from rate-limited servers)
gmlst scheme download saureus_1 --force -x 2

# Refresh every cached scheme (asks for confirmation first)
gmlst scheme update -a
gmlst scheme update -a -y              # skip the Y/N prompt

# Delete a cached scheme you no longer need
gmlst scheme remove saureus_1
gmlst scheme remove saureus_1 -y        # no confirmation prompt

2. Type one sample

# MLST on an assembled genome
gmlst typing mlst -s saureus_1 sample.fasta

# MLST on paired-end reads (requires kma backend)
gmlst typing mlst -s saureus_1 sample_R1.fastq.gz sample_R2.fastq.gz
# Wildcard patterns are supported for _1/_2 and _R1/_R2 naming
gmlst typing mlst -s saureus_1 sample*.fastq.gz

# cgMLST on an assembly
gmlst typing cgmlst -s vparahaemolyticus_3 --cgmlst-mode fast sample.fna

3. Batch processing

--max-workers N types N samples in parallel and is the main speed lever for batch runs. It is distinct from -t/--threads: -t parallelizes a single backend invocation, while --max-workers fans out across samples (per-sample backend threads are forced to 1). The kma and nucmer backends cannot use -t effectively, so --max-workers is the only way to speed them up.

# Batch typing with 16 samples in parallel
gmlst typing mlst -s saureus_1 -t 1 --max-workers 16 samples/*.fasta -o results.tsv

# FASTQ batches: combine with the kma backend
gmlst typing mlst -s saureus_1 -b kma -t 1 --max-workers 16 samples/*_R1.fastq.gz -o results.tsv

# Save machine-readable JSON for downstream novel extraction
gmlst typing mlst -s saureus_1 --format json samples/*.fasta -o results.json

Measured on 639 B. pertussis assemblies (16 workers, results identical to serial runs):

Backend Serial (-t 16) --max-workers 16
minimap2 55 s 9 s
blastn 97 s 31 s
nucmer 270 s 76 s
kma 330 s 48 s

4. Understand the output

Default output is TSV, compatible with the familiar tseemann/mlst style.

FILE            SCHEME      ST  arcC  aroE  glpF  gmk  pta  tpi  yqiL
sample1.fasta   saureus_1   1   1     1     1     1    1    1    1
sample2.fasta   saureus_1   -   1     ~2    3?    -    1    1    1
  • plain allele number, exact known allele match
  • 23*, same allele detected at multiple genomic copies (e.g. gene duplicated on two chromosomes); does not affect ST assignment
  • ~23, non-exact high-coverage call, typically a closest or novel-style locus depending on identity
  • 15?, partial locus hit with insufficient coverage
  • -, locus not found

Use --format pretty for human-readable terminal output and --format json for downstream automation.

Alignment Backends

Backend CLI selectable FASTA FASTQ Best fit Notes
blastn Yes Yes No Classical MLST on assemblies Strong baseline for exact allele calls and targeted review
kma Yes Yes Yes FASTQ typing (all modes) Consensus-based allele calling from raw reads
minimap2 Yes Yes No Fast assembly typing FASTA assemblies only; use kma for FASTQ
nucmer Yes Yes No Sensitive assembly comparison Useful for distant matches and alternate evidence

Backend notes

  • typing mlst and typing cgmlst auto-detect common paired FASTQ naming patterns such as _R1/_R2, _1/_2, and .1/.2.
  • typing cgmlst uses minimap2 by default for FASTA assemblies.
  • For FASTQ cgMLST, the CLI follows a KMA-first policy. Use gmlst typing cgmlst with KMA for raw reads.
  • FASTQ input auto-switches to KMA for both mlst and cgmlst modes.
  • --max-depth — Subsample FASTQ to a maximum read depth (default 100x, FASTQ only)

Data Providers

Provider Source Typical use
pubmlst PubMLST REST catalogs Common public MLST schemes
pasteur Pasteur BIGSdb API BIGSdb-hosted species collections
enterobase Enterobase scheme downloads Large curated scheme sets
cgmlst cgmlst.org cgMLST-focused public schemes
local Local cache and custom schemes Private laboratory databases and exported custom schemes

Examples:

gmlst scheme list -p pubmlst
gmlst scheme list -p enterobase -t cgmlst
gmlst scheme list -p local
gmlst scheme search saureus
gmlst scheme show saureus_1

Novel Data Workflow

Build a local custom scheme from novel calls collected during routine typing.

# 1. Type samples and save JSON
gmlst typing mlst -s saureus_1 --format json *.fasta -o typing_results.json

# 2. Extract novel alleles and novel profiles
gmlst utils extract -i typing_results.json --novel-allele --novel-profile --data-dir novel_data

# 3. Create a local custom scheme
gmlst scheme create -t mlst -s saureus_1 --data-dir novel_data --desc "Lab collection 2024"

# 4. Add more novel data later
gmlst scheme update-custom custom_1 --data-dir more_novel_data

# 5. Export for downstream MST work
gmlst scheme export custom_1 --format grapetree -o custom_1_grapetree.tsv

TSV fallback is also supported when you only have tabular typing output and the original sample files are available:

gmlst utils extract -i typing_results.tsv -s saureus_1 --novel-allele --novel-profile \
  --samples-dir ./samples --data-dir novel_data

cgMLST Modes

gmlst typing cgmlst supports several calling modes for different speed and evidence trade-offs.

Mode What it does Good default
fast Exact-hash plus minimap2 prefilter with targeted rescue Fast everyday assembly typing
ultrafast More aggressive speed profile with bounded second-pass rescue Large batches where turnaround matters most
balanced Hash-first path with targeted blastn fallback Balance speed with stronger low-confidence review

Examples:

gmlst typing cgmlst -s vparahaemolyticus_3 --cgmlst-mode fast sample.fna
gmlst typing cgmlst -s vparahaemolyticus_3 --cgmlst-mode ultrafast sample.fna
gmlst typing cgmlst -s vparahaemolyticus_3 --cgmlst-mode balanced sample.fna

Scheme-free Typing (tgmlst)

Use tgmlst when you want scheme-free allele discovery and optional scheme reuse.

# Run scheme-free typing
gmlst typing tgmlst sample.fna --stats

# Save a discovered scheme for reuse
gmlst typing tgmlst sample.fna --save-scheme tgmlst_scheme.json

# Reuse a previously saved scheme
gmlst typing tgmlst another_sample.fna --load-scheme tgmlst_scheme.json --format json

Useful options include --hash-strategy, --summary-report, --error-report, and --fail-on-error. With --stats, the run statistics JSON is printed to stderr so stdout stays data-only.

Visualization

Launch the local web application to build an MST from cgMLST or exported GrapeTree-style profiles.

gmlst visual web --open-browser

Or bind to a custom address:

gmlst visual web --host 0.0.0.0 --port 8787

The web UI accepts TSV data, builds a minimum spanning tree, and serves a local Flask API with a Vue frontend.

The visual subcommands also read profiles from stdin, so you can pipe typing results straight into an MST summary:

gmlst typing cgmlst -s vparahaemolyticus_3 *.fna --format tsv | gmlst visual mst --input - --format summary

See the Visualization Guide for the full set of visual commands (mst, matrix, heatmap, compare, locus-diff).

Configuration

Key environment variables:

Variable Purpose
GMLST_CACHE_DIR Override the cache root (auto-detected: $CONDA_PREFIX/share/gmlst in conda, $VIRTUAL_ENV/.cache/gmlst in venv, or ~/.cache/gmlst by default)
GMLST_TMPDIR Override temporary working directory used during typing and refinement
GMLST_MINIMAP2_FASTA_EMIT_CIGAR Emit CIGAR in minimap2 FASTA alignments (1/0)
GMLST_PUBMLST_BASE_URL Override PubMLST API base URL
GMLST_PASTEUR_BASE_URL Override Pasteur BIGSdb API base URL
GMLST_PRIVATE_BIGSDB_URL Register a private BIGSdb instance as an extra provider
GMLST_PRIVATE_BIGSDB_NAME Name shown for the private BIGSdb provider
GMLST_PRIVATE_BIGSDB_LABEL Human-readable label for the private BIGSdb provider
GMLST_PUBMLST_API_KEY PubMLST API key for post-2024 data access (Bearer auth)
GMLST_PASTEUR_API_KEY Pasteur BIGSdb API key for post-2024 data access (Bearer auth)

Since January 2025, PubMLST and Pasteur require authentication for data added after 31 December 2024. Obtain an API key and configure it:

# PubMLST: register at pubmlst.org → Preferences → API keys → create key
gmlst config set GMLST_PUBMLST_API_KEY your-key-here
gmlst config init     # auto-load in every new shell (run once)
source ~/.config/gmlst/env.sh   # apply now in current shell

Use gmlst config show to view all 29 configuration variables with current values and defaults. Secret values such as API keys are masked in this view (first4****last4) so they stay out of terminal logs:

gmlst config show                          # grouped table view (secrets masked)
gmlst config env                           # shell-exportable format
gmlst config get GMLST_CACHE_DIR           # get a single variable
gmlst config get GMLST_CACHE_DIR --format json  # {name, value, source, is_default}
gmlst config set GMLST_CACHE_DIR /data     # write to ~/.config/gmlst/env.sh
gmlst config init                          # add source line to shell rc (run once)

In config get --format json output, source tells you where the value comes from: file (the env.sh config file), env (set in the environment any other way), or default (unset, built-in default, is_default true).

Example:

export GMLST_CACHE_DIR="$HOME/.cache/gmlst"
export GMLST_TMPDIR="$PWD/.tmp/gmlst"
export GMLST_PUBMLST_BASE_URL="https://rest.pubmlst.org/db"
export GMLST_PASTEUR_BASE_URL="https://bigsdb.pasteur.fr/api/db"

Private BIGSdb example:

export GMLST_PRIVATE_BIGSDB_URL="http://127.0.0.1:9000/api/db"
export GMLST_PRIVATE_BIGSDB_NAME="labdb"
export GMLST_PRIVATE_BIGSDB_LABEL="Lab BIGSdb"
gmlst scheme list -p labdb

Output Format Details

The default TSV format uses compact markers per locus.

Marker Meaning ST assigned?
23 Exact allele call, single copy ✅ Yes
23* Exact allele call, same-allele multicopy (e.g. gene duplicated on two chromosomes) ✅ Yes (uses 23)
~23 Non-exact but high-coverage call, closest match or novel allele ❌ Novel
15? Partial call, coverage below the confident threshold ❌ Incomplete
1,2 Conflicting multicopy — different alleles detected at different loci copies ❌ Ambiguous
1,1 Same-allele copy expanded (with --count-same-copy flag) ✅ Yes
- Missing locus ❌ Incomplete

Genes split across contigs

Fragmented assemblies often break a housekeeping gene across two contigs. For the blastn and minimap2 backends, gmlst joins the per-contig fragment alignments of such a locus:

  • Overlapping fragments (the contigs overlap inside the gene and the overlap sequence agrees) are tiled into one reconstructed alignment, which can yield a normal exact call.
  • Disjoint fragments never produce an exact call — an indel at the unsampled junction is invisible — but the partial ? call reports the combined coverage of all fragments, and JSON output lists each fragment (contig, allele_start, allele_end).

The minimum allele-coordinate overlap required to join fragments defaults to 10 bp and is tunable with --min-join-overlap (0 = most permissive; overlap sequence must still agree exactly).

JSON output is the best choice when you want structured fields such as per-locus call metadata and novel_sequence extraction data. Every JSON document the CLI writes is wrapped in a versioned envelope, {"schema_version": "<constant>", "data": <payload>}, so scripts can version-check before parsing:

{"schema_version": "gmlst-typing-v1", "data": [{"file": "sample.fasta", "scheme": "saureus_1", "...": "..."}]}

The full constant table lives in the Command Reference.

Exit Codes

Code Meaning
0 Success (including partial tgmlst failures without --fail-on-error)
1 Runtime failure (also scheme update when any provider or scheme update fails)
2 Usage error, such as bad flags or an invalid regex in scheme list --name
3 tgmlst input stage failure
4 tgmlst assembly stage failure
5 tgmlst prediction stage failure
6 tgmlst unknown stage failure

Warnings, progress bars, and "Results written to" notices go to stderr; stdout carries data only.

Multicopy Loci Notes

  • Same-allele multicopy (23*): the same allele is detected at multiple genomic copies (e.g. housekeeping genes duplicated across two chromosomes in Vibrio). This is biologically normal and does not prevent ST assignment. The * suffix marks it for transparency; ST lookup uses the allele number without the *.
  • Conflicting multicopy (1,2): different alleles are detected at different copies of the same locus (possible paralogs or mixed infection). ST is reported as - because a confident profile cannot be assigned.
  • Explicit copy counting (1,1): use --count-same-copy to expand same-allele multicopy into comma notation for downstream tools that expect it.

Recommended review pattern:

# Fast first pass
gmlst typing mlst -s vparahaemolyticus_1 *.fna -o pass1.tsv

# Targeted second pass on flagged samples (those with conflicting multicopy or ~ markers)
gmlst typing mlst -s vparahaemolyticus_1 -b blastn --count-same-copy flagged_sample.fna

Development

Set up the development environment:

pixi install
pixi run install-dev

Common tasks:

pixi run lint
pixi run format-check
pixi run test
pixi run check

Direct Ruff commands also work:

pixi run ruff check .
pixi run ruff format .

See docs/en/contributing.md for contributor workflow and docs/en/architecture.md for module boundaries and typing-path contracts.

Documentation Index

License

Released under the MIT License.

Acknowledgments

Release files for gmlst 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gmlst 0.3.3
File Size Uploaded
gmlst-0.3.3.tar.gz 798.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gmlst 0.3.3
File Interpreter ABI Platform
gmlst-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 1.7 MB

Release files / gmlst-0.3.3.tar.gz

Download URL gmlst-0.3.3.tar.gz
Size 798.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a0a8b05addba077a0cf83c2d8a0368cf3c3c55eaabcd00392f1d3deb3cb0e393
BLAKE2b-256 checksum
How to use checksums
89d13bcfe92933e23329c9db6f20e00dbd9ca91d3533160ff3898940b549aa48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / gmlst-0.3.3-py3-none-any.whl

Download URL gmlst-0.3.3-py3-none-any.whl
Size 859.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a0c2e8698ce3b9d539289c6f7c0e815618087daed70a3eac48305ff9455139c
BLAKE2b-256 checksum
How to use checksums
d9597abacd72740d311f82ef99dc77d33a4abaaa1e1296c4963aeab634d64ac2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.4

2 release files

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page