gbk-to-sqlite
Convert GenBank files to SQLite databases with an intuitive, queryable schema.
Summary
gbk-to-sqlite is a Python tool designed to convert GenBank (.gbk or .gbk.gz) format files into SQLite databases. This enables easier programmatic access, efficient storage, and complex querying of genomic data.
Key features:
- Fast and memory-efficient conversion of large GenBank files
- Support for both regular and gzipped GenBank files
- Comprehensive database schema that preserves all relevant GenBank information
- Automatic handling of complex features including multi-value qualifiers
- Clean Python API for programmatic usage
- SQL query interface for powerful data analysis
Installation
Install with pip:
pip install gbk-to-sqlite
Or with uv:
uv pip install gbk-to-sqlite
Database Schema and Models
gbk-to-sqlite uses a relational model to represent GenBank data:
Genome
Represents a GenBank file:
id: Unique identifier (auto-generated)gbk_path: Path to the source GenBank file
Record
Represents a sequence record in the GenBank file:
id: Unique identifier (auto-generated)genome: Foreign key reference to the Genomename: The LOCUS namedefinition: The DEFINITION field (sequence description)accession: The ACCESSION numberversion: The VERSION identifier
Feature
Represents a feature annotation (gene, CDS, etc.):
genome,record,feature_index: Composite primary keylocation_start: Start position (0-based)location_end: End positionlocation_strand: Strand orientation ('+', '-', or null)
Qualifier
Represents a feature's qualifier (e.g., /gene="xyz"):
genome,record,feature_index: References to the associated Featurekey: Qualifier name (e.g., "gene")value: Qualifier value (e.g., "xyz"), can be null for flag qualifiers
Examples
Command-line Usage
Convert a single GenBank file:
gbk-to-sqlite --genbank-files sequence.gbk --sqlite-db output.sqlite
Convert multiple files:
gbk-to-sqlite --genbank-files file1.gbk file2.gbk.gz --sqlite-db output.sqlite
Use glob patterns to convert many files:
gbk-to-sqlite --genbank-glob "data/*.gbk.gz" --sqlite-db output.sqlite
Python API Usage
from gbk_to_sqlite import convert_gbk_to_sqlite, db, Genome, Record, Feature, Qualifier
# Initialize the database
db.init("output.sqlite")
db.connect()
db.create_tables([Genome, Record, Feature, Qualifier])
# Convert GenBank files
with db.atomic():
convert_gbk_to_sqlite("sequence.gbk")
# Query the database
records = Record.select().where(Record.accession == "NC_000001")
for record in records:
print(f"Record: {record.name}, Definition: {record.definition}")
# Find all genes
genes = Feature.select().join(Qualifier).where(
(Feature.record == record) &
(Qualifier.key == "gene")
)
for gene in genes:
gene_name = Qualifier.select().where(
(Qualifier.feature == gene) &
(Qualifier.key == "gene")
).first().value
print(f"Gene: {gene_name}, Location: {gene.location_start}..{gene.location_end}")
# Close the database connection
db.close()
Known Limitations
- Complex locations (join, order, complement) are stored with a simplified representation
- Join locations may not preserve strand information
- Some advanced GenBank features might not be fully supported
License
MIT
Metadata
Release files for gbk-to-sqlite 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gbk_to_sqlite-0.1.0.tar.gz | 8.4 kB | Without provenance | Details for gbk_to_sqlite-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gbk_to_sqlite-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for gbk_to_sqlite-0.1.0-py3-none-any.whl |
Total release size: 16.2 kB
Release files / gbk_to_sqlite-0.1.0.tar.gz
| Download URL | gbk_to_sqlite-0.1.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db90b150ca1d2f310153e83f48d2713280ab17d8bde26ddf5b2a30ca17a025d1
|
|
BLAKE2b-256 checksum How to use checksums |
02b3c73ed395164015133455c4049bc6b99f9697035357db979f45d99df04420
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / gbk_to_sqlite-0.1.0-py3-none-any.whl
| Download URL | gbk_to_sqlite-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9addb0de7c3778f77a68fa057eb11326309659c256c04c0ddbcbc658908cfa41
|
|
BLAKE2b-256 checksum How to use checksums |
3a8ba378d677cad3dacec6a31edf43b5f987753a6839c5a71de8309a6f828d79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Security for gbk-to-sqlite 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.