CLI toolkit for looking up genes, rsIDs and regions in a tabix-indexed VCF
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Hammer 668aef8d9f
All checks were successful
CI / prek (pull_request) Successful in 1m38s
CI / prek (push) Successful in 1m18s
build(deps): update pre-commit hook davidanson/markdownlint-cli2 to v0.24.2
2026-11-21 03:05:02 +00:00
.forgejo/workflows build(deps): update j178/prek-action action to v3.1.1 2026-11-17 03:05:23 +00:00
internal fix(ensembl): Retry transient failures with backoff 2026-09-24 15:09:00 +01:00
.gitignore feat(core): scaffold vcfq v0.1 2026-05-01 17:18:29 +01:00
.markdownlint.yaml feat(core): scaffold vcfq v0.1 2026-05-01 17:18:29 +01:00
.pre-commit-config.yaml build(deps): update pre-commit hook davidanson/markdownlint-cli2 to v0.24.2 2026-11-21 03:05:02 +00:00
go.mod chore(deps): Bump Go to 1.26.4 2026-07-02 15:02:56 +01:00
go.sum feat(core): scaffold vcfq v0.1 2026-05-01 17:18:29 +01:00
LICENSE feat(core): scaffold vcfq v0.1 2026-05-01 17:18:29 +01:00
main.go feat(core): scaffold vcfq v0.1 2026-05-01 17:18:29 +01:00
README.md fix(cli): Read stdin only when no queries are given, or at "-" 2026-09-24 13:43:22 +01:00

vcfq

CLI toolkit for genome queries — gene-symbol, rsID, and region lookups against a tabix-indexed VCF, with Ensembl coordinate resolution and optional VEP annotation. Single static binary, zero runtime dependencies.

Install

go install github.com/liminalpurple/vcfq@latest

The binary needs network access for Ensembl REST calls; all results are cached locally so repeat queries are offline-fast.

Quick start

export VCFQ_VCF=/path/to/sample.vcf.gz   # tabix-indexed (.tbi alongside)

# Look up by gene symbol — Ensembl resolves the GRCh38 region, vcfq scans it
vcfq HNF1A

# By rsID — Ensembl resolves the location, vcfq grabs the row
vcfq rs1801133

# By genomic region (GRCh38, 1-based inclusive)
vcfq chr1:11796000-11796500

# Multiple queries in one go
vcfq HNF1A MTHFR rs1801133

Queries from stdin

With no query arguments, vcfq reads whitespace-separated queries from stdin. To mix arguments and stdin, pass - where the stdin queries should go — they're spliced in at that position:

echo 'HNF1A rs1801133 chr12:120978000-120998000' | vcfq
vcfq -f json < queries.txt
cut -f1 hits.tsv | vcfq MTHFR - rs53576

When queries are given as arguments and there's no -, stdin is never read, so vcfq won't wait on an inherited stdin in scripts, cron jobs, or CI.

Absent variants

A VCF stores non-reference calls only, so a site with no line is usually homozygous reference — but it may instead be a site that could not be called at all. Those are very different findings, and an empty result set cannot tell them apart.

When a single-position query (an rsID, or a region with one coordinate) resolves cleanly but finds nothing in the VCF, vcfq reports the resolved position with a no-call genotype rather than printing nothing:

vcfq rs2187668 rs7454108
# chrom  pos       id          ref  alt  gt       query
# chr6   32638107  rs2187668   C    T    no-call  rs2187668
# chr6   32713706  rs7454108   T    C    0/1      rs7454108
# note: no variant call is not the same as homozygous reference —
#       verify coverage on the CRAM before interpreting an absence.

The genotype is no-call, never 0/0: vcfq knows only that no line exists at the position, not why, and distinguishing the two requires read-level data it does not touch. The note goes to stderr, so piped output stays clean.

ref/alt on these rows come from Ensembl rather than the VCF — -f json marks this with "source": "ensembl". -a skips them, since annotating a variant the sample does not carry would put it in the same columns as ones it does. -f vcf omits them, having no honest way to express an absence as a data line. Empty ranges stay empty; only a single position supports the claim.

Annotation

Pass -a (or --annotate) to enrich each variant with VEP consequence, gene symbol, amino acid change, and gnomAD/1000G allele frequency:

vcfq -a rs1801133
# chrom  pos       id          ref  alt  gt   query       consequence       gene   aa_change  af
# chr1   11796321  rs1801133   G    A    1/1  rs1801133   missense_variant  MTHFR  A/V        0.2752

VEP calls are batched (≤200 variants per request) and cached, so re-running an annotated query is instant.

Output formats

-f tsv (default), -f table (Markdown), -f json (newline-delimited), -f vcf (VCF passthrough).

The vcf format is the headline: it produces a strictly richer VCF than the input. The source header is passed through, ##INFO=<ID=VCFQ_*> declarations are added when -a is set, and annotations are injected into each line's INFO field. Multi-allelic lines are kept intact, so the VCFQ_* fields are Number=A — one value per ALT, . where an ALT wasn't called. The output round-trips cleanly through bcftools view and bcftools query:

vcfq -a -f vcf HNF1A > annotated.vcf
bcftools query -f '%CHROM\t%POS\t%ID\t%INFO/VCFQ_GENE\t%INFO/VCFQ_CONSEQUENCE\n' annotated.vcf

This makes vcfq useful as a preprocessing step for VCFs that ship without functional annotations (e.g. raw consumer-genomics output).

Cache

Ensembl symbol, rsID, and VEP results are cached as JSON files under os.UserCacheDir()/vcfq/ (typically $XDG_CACHE_HOME/vcfq or ~/.cache/vcfq). There is no TTL — entries are stable per Ensembl release in practice. Wipe with:

vcfq cache clean

Scope

vcfq deliberately handles VCF-level work only. CRAM read-level queries (depth ratios, CIGAR analysis, paralog disambiguation) belong with samtools / bcftools, which already handle them ergonomically. vcfq complements those tools rather than reimplementing them.

All coordinates are GRCh38, 1-based inclusive.

Licence

Apache-2.0.