CLI Reference
BioMetaHarmonizer installs a biometaharmonizer entry point that is
registered in pyproject.toml as:
biometaharmonizer = "biometaharmonizer.cli:main"
The CLI exposes four subcommands. Run build-ncbi-cache and build-dicts
once after installation to prepare the schema files required for One Health
classification, then use run for harmonization and generate-report to
produce HTML/PDF summary reports.
# One-time setup (run after installation)
biometaharmonizer build-ncbi-cache
biometaharmonizer build-dicts
# Regular use
biometaharmonizer run --help
biometaharmonizer generate-report --help
# Version
biometaharmonizer --version
build-ncbi-cache
Downloads the NCBI BioSample attribute definitions XML and saves it to the
schemas/ directory. This file is consumed by build-dicts to resolve
NCBI-specific attribute names during dictionary enrichment.
Run this command once after installation, and again whenever NCBI updates their BioSample attribute definitions.
Usage:
biometaharmonizer build-ncbi-cache \
[--output-dir <DIR>] \
[--skip-fetch]
Flags:
Flag |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Directory where the downloaded attribute XML is saved. |
|
flag |
False |
Skip the network download and process only files already present in
|
Example:
# Standard first-time setup
biometaharmonizer build-ncbi-cache
# Use a custom output directory
biometaharmonizer build-ncbi-cache --output-dir /data/bmh_schemas
# Re-process already-downloaded files without hitting the network
biometaharmonizer build-ncbi-cache --skip-fetch
build-dicts
Builds the enriched one_health_dictionaries.json from OLS4 ontology data,
NCBI Taxonomy, and UMLS. This file drives the One Health classification step
in biometaharmonizer run.
Run this command once after installation (after ``build-ncbi-cache``), and again whenever you want to refresh classification terms from upstream ontology sources.
Usage:
biometaharmonizer build-dicts \
[--base <FILE>] \
[--output <FILE>] \
[--taxdmp <PATH>] \
[--umls-key <KEY>] \
[--skip-ols] \
[--skip-ncbi] \
[--dry-run] \
[--verbose-collisions]
Flags:
Flag |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Path to the hand-curated base dictionary. Entries in this file are
never overwritten ( |
|
str |
|
Destination path for the enriched dictionary. Defaults to overwriting the bundled file in place. |
|
str |
None |
Path to a local |
|
str |
None |
UMLS API key for enriching terms from the UMLS Metathesaurus. Optional; UMLS enrichment is skipped when not provided. |
|
flag |
False |
Skip the OLS4 ontology enrichment step. |
|
flag |
False |
Skip the NCBI Taxonomy enrichment step. |
|
flag |
False |
Run all enrichment steps but do not write the output file. Useful for validating inputs and checking for collisions. |
|
flag |
False |
Print every term collision to stdout instead of only the summary count. |
Examples:
# Standard rebuild (overwrites bundled dictionary in place)
biometaharmonizer build-dicts
# Skip the network-heavy NCBI Taxonomy step
biometaharmonizer build-dicts --skip-ncbi
# Use a pre-downloaded taxdmp.zip to avoid the ~65 MB download
biometaharmonizer build-dicts --taxdmp /path/to/taxdmp.zip
# Write to a custom output path without touching the bundled file
biometaharmonizer build-dicts \
--base src/biometaharmonizer/schemas/one_health_dictionaries.json \
--output /data/my_custom_dictionaries.json
# Dry-run with verbose collision output
biometaharmonizer build-dicts --dry-run --verbose-collisions
run
Runs the full harmonization pipeline: ingest → key-map → date/geo/One Health → output.
Usage:
biometaharmonizer run \
--input <FILE_OR_ACCESSIONS> \
--email <EMAIL> \
--output <FILE> \
[--api-key <KEY>] \
[--cache-dir <DIR>] \
[--format <FORMAT> [<FORMAT> ...]] \
[--summary <FILE>] \
[--fetch-batch-size <N>] \
[--esearch-batch-size <N>] \
[--refresh-cache] \
[--verbose]
Input flexibility:
The --input argument accepts:
A path to a plain-text file containing one accession per line.
A comma-separated list of accessions passed directly as a string (e.g.
-i "SAMN02436525,SAMN02434874"). This is detected automatically when the argument does not look like an existing file path.
Accepted accession prefixes: SAMN, SAME, SAMD (BioSample) or
GCF_, GCA_ (assembly). Mixed files are handled automatically.
Output format inference:
If --format is not specified, the output format is inferred from the
file extension of --output:
Extension |
Inferred format |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(other) |
|
Multiple output formats:
--format accepts one or more space-separated format names. When a single
format is given the --output path is used as-is. When multiple formats
are given the stem of --output is reused and the correct extension is
appended for each format (e.g. --output out.csv --format csv tsv excel
produces out.csv, out.tsv, out.xlsx).
Flags:
Long flag |
Short |
Type |
Default |
Description |
|---|---|---|---|---|
|
|
str |
— |
Required. Input file or comma-separated accession list. |
|
|
str |
— |
Required. NCBI contact email. |
|
|
str |
— |
Required. Output file path. |
|
— |
str |
None |
NCBI API key. |
|
— |
str |
None |
Assembly summary cache directory. |
|
|
choice(s) |
None |
Output format(s): |
|
— |
str |
None |
Write fill-rate summary CSV to this path. |
|
— |
int |
200 |
Records per efetch request (clamped to 500 maximum). |
|
— |
int |
200 |
Accessions per esearch term. |
|
— |
flag |
False |
Force re-download of assembly index. |
|
|
flag |
False |
Enable DEBUG-level logging. |
|
— |
flag |
— |
Print version string and exit. |
Examples:
# BioSample file, CSV output with summary
biometaharmonizer run \
--input biosample_ids.txt \
--email your@email.com \
--api-key abc123def456 \
--output harmonized.csv \
--summary fill_rates.csv \
--verbose
# Assembly accessions, Parquet output, custom cache
biometaharmonizer run \
--input assemblies.txt \
--email your@email.com \
--output harmonized.parquet \
--cache-dir /data/bmh_cache \
--fetch-batch-size 500 \
--refresh-cache
# Inline accessions (no file required)
biometaharmonizer run \
-i "SAMN02436525,SAMN02434874,SAMN02429261" \
-e your@email.com \
-o out.csv
# Multiple output formats at once
biometaharmonizer run \
--input ids.txt \
--email your@email.com \
--output harmonized.csv \
--format csv tsv excel jsonl
generate-report
Generates an HTML (and optionally PDF) summary report from a harmonized
output file produced by biometaharmonizer run.
Usage:
biometaharmonizer generate-report <INPUT> [<OUTPUT>]
Arguments:
Argument |
Type |
Default |
Description |
|---|---|---|---|
|
str |
— |
Required. Path to the harmonized CSV/TSV/Parquet file. |
|
str |
|
Output report path. The format is inferred from the extension
( |
Examples:
# Generate HTML report (output defaults to harmonized_report.html)
biometaharmonizer generate-report harmonized.csv
# Specify output path explicitly
biometaharmonizer generate-report harmonized.csv report.html
# Generate PDF (requires kaleido)
biometaharmonizer generate-report harmonized.csv report.pdf
Exit Codes
Code |
Subcommand(s) |
Meaning |
|---|---|---|
|
all |
Success. |
|
|
User input error — invalid email, input file not found, unrecognized format string, or no valid BioSample IDs could be resolved. |
|
|
User input error — missing or unreadable input file, invalid flag combination. |
|
|
Runtime error — ingestion failure (network, XML parse), empty DataFrame after ingestion, write failure, or import error. |
|
|
Runtime error — network failure during download, parse error in upstream data, or write failure. |
CLI Flag ↔ Python API Mapping
CLI flag |
|
Default |
|---|---|---|
|
|
— |
|
|
— |
|
|
|
|
|
|
|
|
200 |
|
|
200 |
|
|
|
Note
The CLI default for --esearch-batch-size is 200 (as declared in
add_argument), while the Python API module-level constant
_ESEARCH_BATCH defaults to 100. The effective value is whichever
is passed to ingest().
Log Output Format
Log messages are written to stderr using the format:
HH:MM:SS LEVEL logger_name: message
For example:
14:32:01 INFO biometaharmonizer.ingestion: Fetching NCBI assembly index (refseq) ...
14:32:45 INFO biometaharmonizer.ingestion: Fetching metadata for 1500 BioSample accessions...
14:35:12 INFO biometaharmonizer.ingestion: ============================================================
14:35:12 INFO biometaharmonizer.ingestion: INGEST SUMMARY
14:35:12 INFO biometaharmonizer.ingestion: Input IDs provided : 1500
14:35:12 INFO biometaharmonizer.ingestion: fetch_batch_size : 200
14:35:12 INFO biometaharmonizer.ingestion: esearch_batch_size : 200
14:35:12 INFO biometaharmonizer.ingestion: Records in output : 1498
14:35:12 INFO biometaharmonizer.ingestion: bioproject_accession filled : 1350 / 1498
14:35:12 INFO biometaharmonizer.ingestion: assembly_accession_refseq filled : 1200 / 1498
14:35:12 INFO biometaharmonizer.ingestion: assembly_accession_genbank filled : 1100 / 1498
14:35:12 INFO biometaharmonizer.ingestion: ============================================================
14:35:14 INFO biometaharmonizer.cli: Writing output to harmonized.csv (format=csv)
Done. 1498 records x 57 columns -> harmonized.csv
The final Done. line is printed to stdout.