Metadata-Version: 2.4
Name: abyss-db-cli
Version: 0.1.0
Summary: Command-line interface for querying the ABYSS Acinetobacter baumannii genomic surveillance database
Author-email: Brown Beckley <brownbeckley94@gmail.com>
Maintainer-email: Brown Beckley <brownbeckley94@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://abyss-db.org/
Project-URL: Documentation, https://github.com/bbeckley-hub/abyss-db-cli
Project-URL: Repository, https://github.com/bbeckley-hub/abyss-db-cli
Project-URL: Bug Tracker, https://github.com/bbeckley-hub/abyss-db-cli/issues
Project-URL: Changelog, https://github.com/bbeckley-hub/abyss-db-cli/blob/main/CHANGELOG.md
Keywords: bioinformatics,genomics,acinetobacter-baumannii,carbapenem-resistance,crab,amr,antimicrobial-resistance,surveillance,genomic-epidemiology,mlst,kaptive,oxa,argus,eskape,cli,reproducible-research
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Healthcare Industry
Classifier: Natural Language :: English
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas>=1.5.0
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Requires-Dist: pytest>=7.0; extra == "dev"
Dynamic: license-file

# ABYSS-CLI

**Command-line access to the ABYSS *Acinetobacter baumannii* genomic surveillance database.**

[![PyPI](https://img.shields.io/pypi/v/abyss-db-cli.svg)](https://pypi.org/project/abyss-db-cli/)
[![Docker Hub](https://img.shields.io/docker/v/bbeckleyhub/abyss-db-cli?label=Docker%20Hub&logo=docker)](https://hub.docker.com/r/bbeckleyhub/abyss-db-cli)
[![Data release](https://img.shields.io/badge/data%20release-v1.0.0-blue)](https://github.com/bbeckley-hub/argus-data/releases/tag/abyss-data-v1.0.0)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

ABYSS-CLI queries a master table of **59,166** *Acinetobacter baumannii* genomes with **44 fields** per genome: Pasteur and Oxford MLST, international clones (IC1 to IC9), Kaptive K and OC loci, intrinsic OXA variants, acquired carbapenemases, AMR, virulence and plasmid genes, CheckM quality, and geographic and clinical metadata, directly from your terminal. It exports accession lists, BioSample and BioProject identifiers for direct integration with NCBI `datasets`.

The dataset ships bundled inside every distribution (data release v1.0.0; 9 files, 23.2 MB extracted, 20 MB wheel, gz-compressed). After installation, queries run locally with no downloads, no API keys, and no network access.

---

## Two ways to access ABYSS

| Resource | Package | When to use |
|---|---|---|
| [abyss-db.org](https://abyss-db.org/) | Web interface | Interactive exploration, one-off queries, verifying a genotype |
| **ABYSS-CLI** (this package) | `pip install abyss-db-cli` | Repeated queries, scripted pipelines, offline work, pinned data versions |

Both read the same data and return the same numbers. Pick the tool that matches your workflow.

---

## What's in v0.1.0

- **The full ABYSS dataset bundled** - 59,166 genomes, 44 columns, gz-compressed, shipped in the wheel and the Docker image; queries run offline
- **Boolean query layer** - comma = OR within one flag, AND across flags, and a `--not-*` exclusion twin for every filter field
- **Combined typing flags** - `--combo` (ST-KL:OCL), `--ksk` (ST-KL) and `--kso` (ST-OCL) with 3,404 unique combined types in data v1.0.0
- **`abyss init`** - installs or refreshes the data bundle from the [argus-data](https://github.com/bbeckley-hub/argus-data) releases, SHA256-verified, with offline `-f/--from-file` installs
- **65-check self-test suite** - every golden count recomputed from the local data (tests/abyss_selftest.sh)
- **Docker build gate** - the image build asserts the bundled-data smoke count (`--ic IC2` = 33,164), so a wheel carrying stale data fails the build

Full changelog: [CHANGELOG.md](CHANGELOG.md)

---

## Installation

Choose whichever fits your workflow. All methods deliver the same CLI and the same bundled data.

### pip

```bash
pip install abyss-db-cli
```

### uv (fastest)

```bash
uv tool install abyss-db-cli
```

### pipx (isolated environment)

```bash
pipx install abyss-db-cli
```

### Docker

```bash
docker pull bbeckleyhub/abyss-db-cli:latest
docker run --rm bbeckleyhub/abyss-db-cli:latest --version
```

Verify the installation:

```bash
abyss --version
# ABYSS-CLI v0.1.0 - University of Ghana Medical School, Accra, Ghana
#  Data version: 1.0.0  (/home/user/.abyss/data)

abyss --ic IC2 --count
# Expected: 33,164
```

---

## Quick Start

The most common workflow is **filter, export, download**:

```bash
# 1. Filter
abyss --crab --continent Europe --source blood --count

# 2. Export accessions
abyss --crab --continent Europe --source blood -o crab_europe_blood.txt

# 3. Download assemblies from NCBI
datasets download genome accession --inputfile crab_europe_blood.txt --filename crab_europe_blood.zip
```

BioSample and BioProject lists for the same selection come out with one flag:

```bash
abyss --crab --continent Europe --format biosample,bioproject -o crab_europe
# writes crab_europe_biosamples.txt and crab_europe_bioprojects.txt
```

---
EOF
awk 'END{print NR}' ~/abyss-db-cli/README.md    # expect 104
```

Chunk 2, append (gate must read 211):

```bash
cat >> ~/abyss-db-cli/README.md <<'EOF'
## Core Usage

### Typing flags

| Flag | Description | Example |
|---|---|---|
| `--st` | MLST Pasteur sequence type | `--st 2` or `--st ST2` |
| `--oxford-st` | MLST Oxford sequence type | `--oxford-st 208` |
| `--ic` | International clone (IC1 to IC9) | `--ic IC2` |
| `--kl` | Kaptive K locus (capsule) | `--kl KL2` |
| `--ocl` | OC locus | `--ocl OCL1` |
| `--oxa` | Intrinsic OXA variant | `--oxa OXA-66`; acquired carbapenemases go through `--amr` |
| `--lineage` | Predefined lineage shortcut | `--lineage GC2` |

### Combined typing (ST-KL:OCL)

The master table carries three precomputed combined typing strings (3,404 unique ST-KL:OCL values in data v1.0.0):

| Flag | String | Example |
|---|---|---|
| `--combo` | ST-KL:OCL | `--combo ST2-KL2:OCL1` |
| `--ksk` | ST-KL | `--ksk ST1013-KL171` |
| `--kso` | ST-OCL | `--kso ST1013-OCL4` |

All three accept comma-separated OR lists and lowercase input (`--combo st2-kl2:ocl1` resolves to `ST2-KL2:OCL1`). Browse valid values with `abyss --list combo` (also `ksk`, `kso`).

### Epidemiological metadata

| Flag | Description | Example |
|---|---|---|
| `--country` | Country of origin | `--country Brazil` |
| `--continent` | Continent | `--continent Europe` |
| `--region` | Region or sub-country location | `--region "Sao Paulo"` |
| `--source` | Isolation source | `--source blood` |
| `--host` | Host species | `--host "Homo sapiens"` |
| `--year` | Collection year or range | `--year 2019` or `--year 2015-2023` |
| `--super-group` | Super-group label | `--super-group ICU` |

### Gene content

| Flag | Description | Example |
|---|---|---|
| `--amr` | AMR gene(s), comma-separated | `--amr blaOXA-23` |
| `--vfdb` | Virulence gene(s), comma-separated | `--vfdb <gene>` |
| `--plasmid` | Plasmid replicon(s), comma-separated | `--plasmid IncP1` |
| `--any` | Match ANY of the given genes (default is ALL) | `--amr blaOXA-23,blaOXA-24 --any` |
| `--crab` | Carbapenem resistant: carries any acquired carbapenemase (OXA-23, OXA-24/40, OXA-58, NDM, KPC) | `--crab` |

Gene names are matched against the static gene-annotation tables shipped with the data release (AMR, VFDB, PlasmidFinder).

### Quality filters

| Flag | Description |
|---|---|
| `--complete-only` | Only complete genomes |
| `--min-completeness N` | Minimum CheckM completeness (genomes without CheckM are excluded) |
| `--max-contamination N` | Maximum CheckM contamination (genomes without CheckM are excluded) |
| `--has-kl` | Only genomes with a Kaptive KL result |
| `--has-oxa` | Only genomes with an OXA variant called |

### Boolean logic

Filters combine with **AND**. A comma inside one flag means **OR**:

```bash
abyss --ic IC1,IC2 --count     # 34,709 (IC1 1,545 + IC2 33,164)
```

Every filter has a `--not-` twin that drops genomes matching ANY listed value:

```bash
abyss --ic IC2 --not-amr blaNDM --count
abyss --crab --not-continent Europe --count
abyss --not-combo ST1013-KL171:OCL4 --count   # 59,165 (all but the single matching genome)
```

The identities hold by construction and the suite recomputes them on your machine: `X + not-X = total`, and `--crab --not-crab` is always 0.

### Output formats

| Format | Extension | Feeds into |
|---|---|---|
| `accession` | `.txt` | NCBI `datasets download genome accession` |
| `biosample` | `_biosamples.txt` | Metadata lookups, `fastq-dl --group-by-sample` |
| `bioproject` | `_bioprojects.txt` | Study-level bulk downloads |
| `tsv` | `.tsv` | Excel, R, pandas |
| `csv` | `.csv` | Collaborators, spreadsheets |
| `json` | `.json` | Web apps, `jq`, archival |

Request multiple formats in one command:

```bash
abyss --ic IC2 --format tsv,accession,biosample -o ic2
# writes ic2.tsv, ic2.txt, ic2_biosamples.txt
```

### Output options

| Flag | Description | Default |
|---|---|---|
| `--count` | Print only the number of matching genomes | Off |
| `--format` | Output format(s), comma-separated | `accession` |
| `--output`, `-o` | Output base path (extension added per format) | `stdout` |
| `--quiet`, `-q` | Suppress banner and footer (useful for scripts) | Off |
| `--debug` | Show row counts after each filter | Off |

---
EOF
awk 'END{print NR}' ~/abyss-db-cli/README.md    # expect 211
```

Chunk 3, append (gate 305):

```bash
cat >> ~/abyss-db-cli/README.md <<'EOF'
## Updating the data

The CLI and the data are versioned independently. The wheel bundles a snapshot at build time; `abyss init` upgrades the data without touching the code. Data releases are published in the dedicated [argus-data](https://github.com/bbeckley-hub/argus-data) repository under the tag prefix `abyss-data-` (currently `abyss-data-v1.0.0`), each carrying the bundle zip and a SHA256 checksum sidecar.

```bash
# Install the latest data release
abyss init

# Pin a specific data version for reproducibility
abyss init -v 1.0.0

# Install from a local zip (offline, air-gapped HPC) - requires the .sha256 sidecar
abyss init -f abyss_data.zip

# Explicitly install unverified (not recommended); a checksum mismatch is always fatal
abyss init -f abyss_data.zip --allow-unverified

# Install to a custom location / force overwrite
abyss init -o /shared/abyss_data
abyss init --force
```

`abyss init` verifies the SHA256 checksum of every download and writes a `DATA_VERSION` file; `abyss --version` reports the active data release.

### Where the data lives

The CLI searches the following locations in priority order (highest wins):

| Priority | Location | Use case |
|---|---|---|
| 1 | `--data-dir <path>` | Per-command override |
| 2 | `$ABYSS_DATA_DIR` | Docker volumes, HPC scratch, shared cluster installs |
| 3 | `~/.abyss/data` | Default user install (created by `abyss init`) |
| 4 | `~/.local/share/abyss` | Alternative user install |
| 5 | `./data` | Development checkouts |
| 6 | `sys.prefix/share/abyss/data` | Bundled inside pip/Docker |

### Reproducible queries with config files

For recurring surveillance tasks, save your query as a JSON file:

```json
{
  "ic": "IC2",
  "continent": "Europe",
  "format": "tsv,accession",
  "output": "ic2_europe"
}
```

Run it with `abyss --config query.json`. Any command-line flag overrides the corresponding config value, so you can reuse a config with a one-off change (`abyss --config query.json --source blood`). Unknown config keys are fatal rather than silently ignored.

---

## Examples Gallery

All counts are for data release v1.0.0.

### Global Clone 2

```bash
abyss --ic IC2 --count                    # 33,164
abyss --lineage GC2 --source blood -o gc2_blood.txt
```

### Carbapenem resistance

```bash
abyss --crab --count                            # 29,145
abyss --crab --continent Europe --count         # 1,744
abyss --amr blaOXA-23 --continent Asia --count  # 8,329
```

### Capsule, MLST and quality

```bash
abyss --kl KL2 --count               # 7,119
abyss --oxford-st 208 --count        # 261
abyss --complete-only --count        # 1,877 complete genomes
```

### Combined typing

```bash
abyss --combo ST2-KL2:OCL1 --count        # 5,883 (most common combo)
abyss --combo ST499-KL18:OCL3 --count     # 2,046
abyss --combo ST1013-KL171:OCL4 --count   # 1
abyss --kso ST1013-OCL4 --count           # 22
```

### Debugging a query that returns zero

```bash
abyss --st 2 --kl KL49 --debug --count
```

The `--debug` output prints the row count after each filter, so you can see exactly where a query collapsed. Run `abyss --examples` for the full gallery inside your terminal.

---
EOF
awk 'END{print NR}' ~/abyss-db-cli/README.md    # expect 305
```

Chunk 4, append (gate 427):

```bash
cat >> ~/abyss-db-cli/README.md <<'EOF'
## Docker Usage

The Docker image bundles the full dataset and a data-aware entrypoint.

```bash
# Count genomes (zero setup, uses bundled data)
docker run --rm bbeckleyhub/abyss-db-cli:0.1.0 --ic IC2 --count
# 33,164

# Export to the host directory
docker run --rm -v "$PWD:/work" bbeckleyhub/abyss-db-cli:0.1.0 \
    --crab --continent Europe -o crab_europe
```

### Persistent data with a volume

Use a volume to persist `abyss init` updates across container restarts:

```bash
# First run: the entrypoint seeds /data from the bundled dataset
docker run --rm -v abyss_data:/data bbeckleyhub/abyss-db-cli:0.1.0 --ic IC2 --count

# Update the data in the same volume
docker run --rm -v abyss_data:/data bbeckleyhub/abyss-db-cli:0.1.0 init --force

# Subsequent runs use the updated data
docker run --rm -v abyss_data:/data bbeckleyhub/abyss-db-cli:0.1.0 --version
```

The entrypoint automatically sets `ABYSS_DATA_DIR=/data` when a volume is mounted, so all queries and updates use the persistent location. Full Docker Hub README: https://hub.docker.com/r/bbeckleyhub/abyss-db-cli

---

## HPC Deployment

For clusters where users share a data directory, install once and export the path:

```bash
# Admin: install to shared scratch (once)
mkdir -p /scratch/abyss
ABYSS_DATA_DIR=/scratch/abyss abyss init
chmod -R a+r /scratch/abyss

# Users: point at the shared copy
export ABYSS_DATA_DIR=/scratch/abyss
abyss --crab --count
```

---

## Data Requirements (Development)

If you clone the repository and install in editable mode (`pip install -e .`), the CLI reads from `./data/`. The distributed package bundles the data under `share/abyss/data/`. The versioned data bundle itself is published in the [argus-data](https://github.com/bbeckley-hub/argus-data) repository, not in this code repository.

```
data/
├── DATA_VERSION                 # Release tag (e.g., 1.0.0)
├── master/
│   ├── abyss_all.tsv.gz         # Master TSV (all typing + metadata)
│   └── abyss_manifest.json      # Build manifest (rows, columns, checksums)
├── metadata/
│   └── abyss_metadata.tsv.gz
├── gene_annotations/
│   ├── amr_all.tsv.gz
│   ├── vfdb_all.tsv.gz
│   └── plasmid_all.tsv.gz
├── capsule/
│   └── kaptive_all.tsv.gz
└── mlst/
    └── mlst_all.tsv.gz
```

To rebuild the master TSV from the module tables: `python scripts/build_master_tsv.py`

## Testing

```bash
bash tests/abyss_selftest.sh    # 65 checks, recomputes every golden count
```

The suite pins golden counts to the shipped data release and covers data integrity, regression goldens, Boolean identities, init, export formats, and error paths.

## Built-in Commands

| Command | Purpose |
|---|---|
| `abyss --examples` | Full gallery of example queries |
| `abyss --about` | Author, affiliation, citations, and links |
| `abyss --version` | CLI version and data version |
| `abyss --help` | Full flag reference |
| `abyss --list FIELD` | List unique values for any filter field |
| `abyss init` | Install or refresh the data bundle |

## Citation

If you use ABYSS-CLI or the ABYSS dataset in your research, please cite:

- The ABYSS typing pipeline (AcinetoScope): doi.org/10.1038/s41598-026-70189-y
- The source gene-annotation dataset (Shelenkov et al., *Data*): doi.org/10.3390/data9020022

The data release is published on GitHub: [abyss-data-v1.0.0](https://github.com/bbeckley-hub/argus-data/releases/tag/abyss-data-v1.0.0), SHA256 `84247fa8e729618a7ad7442ac70cbc7c8c89e6b4779f7b0221094ad6ad990e35`.

## Part of ARGUS

ABYSS-CLI is part of the ARGUS initiative, a family of open genomic surveillance tools covering the WHO priority ESKAPE pathogens.

- ARGUS umbrella: https://argus-db.org/
- ABYSS web resource: https://abyss-db.org/
- Data releases: https://github.com/bbeckley-hub/argus-data (tag prefix `abyss-data-`)
- Sibling CLI for *S. aureus*: https://github.com/bbeckley-hub/saurus-cli

## Contributing

Bug reports and feature requests: https://github.com/bbeckley-hub/abyss-db-cli/issues

## License

MIT License. See [LICENSE](LICENSE) for details.

---

**Author**: Brown Beckley, University of Ghana Medical School, Accra, Ghana. ORCID [0009-0005-5414-1305](https://orcid.org/0009-0005-5414-1305). Independent, not funded.

