How biopus/barcode-kit works
1. barcode-kit is a local-first DNA barcode pipeline centered on one persistent workspace under data_dir. The core loop is: query GenBank, cache raw records, normalize taxonomy, parse marker sequences, then export FASTA datasets and JSON reports from local state.
2. The main user boundary is the Typer CLI in src/barcode_kit/cli.py. It exposes distinct operational commands for sync, build, qc, and db management, so the repository is organized around command-driven workflows rather than a long-running service.
3. Configuration is loaded from config.py and is part of the architecture, not just convenience. It controls filesystem layout, collector behavior, GenBank credentials, and QC parameters. The default workspace includes a SQLite database plus cache/genbank/ and logs/, which makes local state an explicit subsystem.
4. The ingestion path is genbank.py plus blast.py/itsxrust.py/parser.py around record acquisition and sequence interpretation. sync contacts NCBI E-utilities, fetches accession records, and stores the downloaded GenBank text locally. The README indicates this step can use taxon names or NCBI TaxId, and it supports the markers its, its2, matk, and rbcl.
5. Taxonomy is a separate normalization boundary in taxonomy.py. It uses ETE’s NCBITaxa local taxonomy database to turn NCBI taxon hints or scientific names into canonical names and lineages. This is important because the system treats taxonomy resolution as a local enrichment step before data is written to storage.
6. storage.py is the persistence layer and the main integration point between modules. It maintains the SQLite schema for accession-level cache records and taxonomy rows, and it is also the source of truth for later build and cleanup operations. The db commands operate directly on this layer for status, info, remove, clear, and prune.
7. builder.py implements the dataset construction boundary. It reads only from local cache and produces marker-specific FASTA outputs plus dataset.json and build_report.json. The build stage is intentionally separate from synchronization: it does not re-query NCBI and does not apply QC filters unless the later qc command is run.
8. validation.py is the QC layer that consumes a built dataset and emits a filtered FASTA plus qc_report.json. It supports sequence-level rules like length and ambiguity thresholds, as well as taxonomy-based exclusions. This stage is designed to be repeatable from raw/, not incremental over prior QC outputs.
9. The phylogeny subsystem in phylogeny.py is a thin wrapper around external bioinformatics tools. It orchestrates alignment, trimming, tree building, and TreeShrink-based outlier detection through subprocess runners. The README shows dependencies on mafft, iqtree, trimal, and run_treeshrink.py, so this module is an execution boundary to system-installed tools rather than an in-process algorithm library.
10. The domain layer in models.py, exceptions.py, and __init__.py provides shared objects and error semantics used across the pipeline. That keeps the CLI, storage, parser, and QC code aligned on the same record and report shapes, which is important for generating consistent JSON outputs.
11. The repository also has a clear testing boundary. The tests/ suite covers CLI behavior, GenBank download logic, parser validation, taxonomy, storage, phylogeny, and module exports, which mirrors the architecture of the package and suggests the intended contracts between modules are stable and explicitly verified.
Main entry points: builder.py Builder · cli.py CLI · storage.py Storage · validation.py QC
Components 18
User Interface
CLI entrypoint and command surfaces
- CLI · Command boundary for sync, build, qc, and db operations
src/barcode_kit/cli.py - Sync · Fetches records, normalizes taxonomy, and populates cache
src/barcode_kit/cli.py - Build · Constructs marker FASTA outputs and JSON summaries
src/barcode_kit/cli.py - QC command · Runs validation over built datasets
src/barcode_kit/cli.py - DB command · Inspects and cleans the persistent cache database
src/barcode_kit/cli.py
Pipeline Core
Ingestion, parsing, build, and QC workflow
- GenBank · Downloads and caches accession records from E-utilities
src/barcode_kit/genbank.py - Taxonomy · Resolves names and taxids to canonical taxonomy
src/barcode_kit/taxonomy.py - Parser · Interprets cached records and extracts marker sequences
src/barcode_kit/parser.py - BLAST rescue · Supplementary marker identification and rescue logic
src/barcode_kit/blast.py - ITSxRust · ITS/ITS2 marker detection via external tool integration
src/barcode_kit/itsxrust.py - Builder · Builds FASTA datasets and build reports from local cache
src/barcode_kit/builder.py - QC · Applies length, ambiguity, and taxonomy filters to builds
src/barcode_kit/validation.py
Local State
Persistent workspace and SQLite-backed cache
- Storage · Source of truth for cache records and taxonomy rows
src/barcode_kit/storage.py
Phylogeny
External-tool orchestration for downstream analysis
- Phylogeny · Runs alignment, trimming, tree building, and TreeShrink
src/barcode_kit/phylogeny.py
Shared Domain
Common models, config, and error types
- Config · Defines workspace layout, credentials, and QC parameters
src/barcode_kit/config.py - Models · Common data structures for records and reports
src/barcode_kit/models.py - Errors · Pipeline-specific error semantics
src/barcode_kit/exceptions.py - Package API · Package-level exports for the public API
src/barcode_kit/__init__.py
Connections 25
- CLI → Sync: exposes · Defines the sync workflow
- CLI → Build: exposes · Defines the build workflow
- CLI → QC command: exposes · Defines the QC workflow
- CLI → DB command: exposes · Defines database management commands
- Sync → GenBank: fetches · Retrieves accession records from NCBI
- Sync → Taxonomy: resolves · Normalizes names and taxids
- Sync → Storage: persists · Stores downloaded records and taxonomy state
- GenBank → Storage: caches · Writes raw GenBank text into local state
- Taxonomy → Storage: enriches · Stores canonical taxonomy rows
- Storage → Builder: reads · Build stage consumes only local cache
- Builder → Parser: interprets · Uses parsed marker sequences from cached records
- Builder → BLAST rescue: rescues · Can use BLAST-based rescue logic
- Builder → ITSxRust: detects · Can use ITS marker detection tooling
- Builder → Models: emits · Produces dataset and build report structures
- Builder → QC: hands off · QC is a separate later stage
- QC command → QC: runs · Applies filters to built datasets
- QC → Models: emits · Produces QC report structures
- DB command → Storage: operates on · Status, info, remove, clear, and prune use persistence layer
- Phylogeny → Models: reports · Uses shared report shapes for analysis outputs
- CLI → Config: loads · CLI is configured by workspace and QC settings
- Builder → Config: reads · Build behavior depends on workspace layout and markers
- QC → Config: reads · QC thresholds come from configuration
- GenBank → Config: reads · Uses credentials and collector settings
- Package API → Models: exports · Re-exports public package types
- Package API → Errors: exports · Re-exports package error types