The app never calls an annotation service. Everything a result says about a variant beyond
the study's own data — OncoKB's oncogenicity and levels; Genome Nexus's HGVSc, functional-impact
predictions, gnomAD, ClinVar, dbSNP, SIGNAL and Cancer Hotspots today; and the sources still to come
(CIViC; transcripts, Pfam domains, PTMs and structures) — is resolved offline, by npm run annotate,
into a version-pinned store in ClickHouse, and read from there at query time. So a result never
depends on whether a service answered in time, every annotation it shows names the release it
came from, and no variant leaves the warehouse while someone is waiting for an answer.
Every source's annotations live in one ClickHouse database, annotation, apart from the portal's:
| table | holds | read by |
|---|---|---|
annotation.oncokb |
OncoKB, licensed: mutations by protein change, gene-level copy-number calls | those granted SELECT on this table — the licence |
annotation.oncokb_tumor_type |
OncoKB by tumour type, licensed with annotation.oncokb: each somatic mutation as the portal's mutation table asks about it (gene, protein change, mutation type, the sample's tumour type), with its four highest levels and OncoKB's whole answer in data. Read by the mutation table at the OncoKB pin, falling back to annotation.oncokb. It also holds the Patient page header's TMB-H and MSI-H calls, as the portal asks them: gene Other Biomarkers, the biomarker as the alteration, no mutation type, at the tumour type the header asks with, for every sample whose CVR_TMB_SCORE / TMB_NONSYNONYMOUS is ≥ 10 or whose MSI_TYPE is Instable (biomarkerKeySpace; read by lib/biomarkers.ts through /api/biomarkers) |
those granted SELECT on this table |
annotation.oncokb_sv |
OncoKB for structural variants, licensed with annotation.oncokb: each structural variant as the portal asks about it (site 1 and site 2 genes, OncoKB's SV type, the sample's tumour type), and again with no tumour type (the portal's driver call), with its four highest levels and OncoKB's whole answer in data. Read at the OncoKB pin by the structural-variant table and the Mutations tab's fusion rows (the cell from the tumour-type call, the driver status from the one with none), the lollipop's Fusion badge, and the oncoprint, OQL DRIVER and the plots' driver axis (the call with none, as the portal's oncoprint asks; lib/sv-oncokb.ts svDriverKeysSql), falling back to the partners' gene-level Fusion rows in annotation.oncokb |
those granted SELECT on this table |
annotation.oncokb_cancer_gene |
OncoKB's cancer gene list (/utils/cancerGeneList), licensed with annotation.oncokb: one row per gene the warehouse's alterations name at each release, cancer_gene whether the list has it (the portal's isOncoKbCancerGene: the last element of the Annotation sort, Study View's gene-table icon), oncokb_annotated whether OncoKB curates it, the entry as JSON in data. Read at the OncoKB pin through oncokbCancerGeneSql, after oncokbCancerGenesCompleteSql says the pin's latest portal-wide sync left no gene unstored; no view reads it yet. By the user's decision (2026-11-17) the list is stored under the store's pin, v7.5, although OncoKB's API served it at v7.7: api_version records the live API and data release (v1.7.0 (data v7.7)) |
those granted SELECT on this table |
annotation.variant |
every public source, one row per (source, release, genomic variant): the variant's coordinates as the warehouse spells them, the source's annotation as JSON in data |
everyone with the app's read access |
annotation.sync_run |
every source's sync runs, by source and version |
everyone with the app's read access |
A licensed source has a table of its own, so its licence is a GRANT on that table; public
sources share annotation.variant, so adding one needs no new table. The database is separate
from the portal's, so a portal dump never holds annotations, licensed or not; a dump of
annotation itself must leave out the licensed tables. The app reads these names from
lib/annotation-store.ts, the sync from packages/annotation-sync/src/store.ts and its sources;
test/annotation-store.test.ts holds the two, and the migrations in
packages/annotation-sync/sql/, to each other.
Genome Nexus runs one service per reference genome, each with its own releases, so each is a source:
genome_nexus (GRCh37, v1.genomenexus.org, the studies on hg19) and genome_nexus_grch38
(grch38.genomenexus.org, hg38). A sync asks each distinct variant of its studies' mutations as
cBioPortal asks it — POST /annotation/genomic with annotation_summary, clinvar, hotspots,
mutation_assessor and (GRCh37 only: the GRCh38 service has none) signal, MSKCC isoform
overrides — and stores, per variant: every transcript's consequence summary (HGVSc, HGVSp,
consequence, SIFT, PolyPhen-2, AlphaMissense); each gene's
canonical transcript (/ensembl/canonical-transcript/hgnc, asked once per gene per sync), because the
portal's HGVSc is on the canonical transcript of the gene the mutation is listed under and a third of
variants lie in two genes; ClinVar's record; SIGNAL's entries; MutationAssessor's call; Cancer
Hotspots' residues on any of its transcripts; and myvariant.info's gnomAD counts (exome and genome,
by population), VCF position and dbSNP id. A variant the service cannot annotate is stored with its
error, so it is not asked again. The release is the server version, its VEP cache, its ClinVar
release and the set of fields stored (2.2.3-vep116-clinvar20260208+f2): a row stored before a field
was added lacks it, so adding one (GN_FIELD_SET) names a new release and the next sync asks again.
GRCh38's service reports its VEP as NA (it asks Ensembl), so its rows are pinned to less than GRCh37's.
myvariant.info is asked on its own, in small requests. Genome Nexus answers a request with no
myvariant.info record for any of its variants when one variant's record fails it (3:52475300 G>A
on GRCh37, for one; about 2% of variants), without an error. So gnomAD and dbSNP are asked 25 variants
at a time, four requests at once, and a request that comes back with none at all is split in half and
asked again, down to the variant that fails, which alone is left without them. (cBioPortal asks a
gene's mutations in one request, so there such a variant blanks gnomAD and dbSNP for the whole gene.)
A release that changes mid-sync stops it. Before each write the sync asks the service for its release again; when it has moved on, the sync stops without writing what it held, so no row is stored under a release that did not make it, and the next run syncs the new release.
The mutation table (lib/mutation-table.ts, lib/variant-annotation.ts) joins each study's
mutations to its own genome's source at that source's pin, the newest release a sync stored
(GENOME_NEXUS_PIN, GENOME_NEXUS_GRCH38_PIN override it), and reads HGVSc, Functional Impact,
gnomAD, ClinVar, dbSNP and SIGNAL off the JSON; HGVSg it builds from the mutation's coordinates, as the portal does. Its caveat names the
pins and the studies no sync has covered. Before the first sync there is no pin, and the table
leaves the store alone.
The public warehouse holds about 6.0M distinct GRCh37 variants and 3.1M GRCh38 ones (November 2026). They are stored at about 0.2 KB each, compressed (2.5–4 KB as JSON), so about 2 GB in all. At the public services' pace measured on one study (12–35 variants a second, the canonical-transcript and myvariant.info calls included, and slower when Genome Nexus is busy) a first full sync takes several days; later ones ask only for new variants.
- Version-pinned. Every row carries the source's release (
oncokb_versionfor OncoKB) and the table is partitioned by it. Releases are appended, never overwritten: a figure annotated against a release re-renders against it for good, readers pinWHERE <version> = '<pin>', and retiring a release isALTER TABLE … DROP PARTITION. - A licensed source's table is a GRANT. OncoKB is readable by an identity that has
SELECTonannotation.oncokband by no other; revoking the grant is one statement, and readers then degrade loudly to unannotated results. The portal import never writes there. - Diffed, resumable syncs. A sync takes a study's distinct keys from the warehouse
(
genomic_event_derived), subtracts what the store already holds for the release — in ClickHouse, one query — and asks the service for the rest in polite batches. Re-running, or a key shared by several studies, never asks twice. Ten failed batches in a row stop the run (a token or rate problem, not a data problem). - Few, large writes. Every INSERT makes a part ClickHouse later has to merge, so the sync holds
what the service returns and writes it every
ANNOTATION_INSERT_ROWSrows (20,000) orANNOTATION_INSERT_SECONDS(300), whichever comes first, and at the end;--allholds across studies. A full Genome Nexus sync is about 450 inserts, not one per 200-variant batch. A run'ssync_runrow is written after the rows it counts. A sync that stops loses only what it held, which the next run asks for again; a failed write stops the sync. A release no one reads any more is removed withALTER TABLE … DROP PARTITION (source, version), which drops files without a merge, never withALTER TABLE … DELETE, which rewrites parts. - Audited. Every run appends a row to
annotation.sync_run(itssource): study, release, keys in the study, already stored, annotated now, failed, and a note (complete,partial — re-run to resume,aborted …).--alladds a__portal__row saying how much of every study's key space is stored. The app readssync_runto say which studies a release covers.
npm run annotate -- oncokb --study msk_chord_2024 # one study
npm run annotate -- oncokb --all # every study, then the portal-wide row
npm run annotate -- oncokb --verify 300 --release v7.5 # re-ask the service for 300 keys stored for v7.5
npm run annotate -- oncokb --all --create # also create the store, as a user allowed to
npm run annotate -- oncokb_tumor_type --all # OncoKB by tumour type, every study's somatic mutations
npm run annotate -- oncokb_sv --all # OncoKB for structural variants, by gene pair and tumour type
npm run annotate -- oncokb_cancer_gene --all # OncoKB's cancer gene list (one request; a row per gene)
ONCOKB_CANCER_GENE_STORE_AS=v7.5 npm run annotate -- oncokb_cancer_gene --all # the live list, stored under the store's v7.5 pin (api_version records the live release)
npm run annotate -- genome_nexus --all # every GRCh37 study's variants
npm run annotate -- genome_nexus_grch38 --all # every GRCh38 study's
The sync writes as the source's writer, never as the app: <SOURCE>_WRITER_USER (default
<source>_writer) and <SOURCE>_WRITER_PASSWORD on CLICKHOUSE_URL / CLICKHOUSE_DB. The public
sources share one, ANNOTATION_WRITER_USER (annotation_writer) / ANNOTATION_WRITER_PASSWORD,
which can write annotation.variant and the log and never reaches the licensed tables. While
npm run local is running it writes to the local instance instead, which owns its whole database
and creates the stores when it is set up. OncoKB also needs ONCOKB_TOKEN
(register); ONCOKB_BASE, ONCOKB_BATCH_SIZE (250) and
ONCOKB_BATCH_DELAY_MS (300) are optional. The command exits 2 when a run aborts or leaves keys
unannotated, so a scheduled sync fails visibly.
A new release of a source: run the sync again. Its rows land in a new partition, and readers move
to it when their pin does (ONCOKB_PIN, or the newest release in the store).
The schema changes are numbered SQL files in packages/annotation-sync/sql/, each run once, in
order, by an administrator; each says what it does, checks its own result, and is safe to repeat.
001-annotation-database.sql creates annotation and copies OncoKB in from the database it used to
have (oncokb_annotation), which is dropped only once the code reading annotation is deployed.
002-annotation-variant.sql creates annotation.variant and grants the public sources' writer and
the app what they need there; the writer itself (CREATE USER, with a password of your choosing) is
the one step you edit before running it.
-- a source's writer: the only identity that can fill its table; it reads the warehouse, writes its
-- table and the log, and nothing else
CREATE USER IF NOT EXISTS oncokb_writer IDENTIFIED BY '<a strong password>';
GRANT SELECT, INSERT ON annotation.oncokb TO oncokb_writer;
GRANT SELECT, INSERT ON annotation.sync_run TO oncokb_writer;
GRANT SELECT ON <warehouse database>.* TO oncokb_writer;
-- licensing a reader is a grant on the licensed table; revoking it is one statement
GRANT SELECT ON annotation.oncokb TO cohort_lab_ro;
-- REVOKE SELECT ON annotation.oncokb FROM cohort_lab_ro;
-- OncoKB by tumour type and OncoKB for structural variants are the same licence: grant and revoke
-- the three tables together (packages/annotation-sync/sql/004-oncokb-tumor-type.sql and
-- 005-oncokb-sv.sql; the mutation and structural-variant tables read them whenever there is an OncoKB pin)A local instance (npm run local) creates the database and every table itself, empty.
The sync is a package of its own, @cbiolab/annotation-sync (packages/annotation-sync/), as the
importer is (@cbiolab/importer): both are tools run against a database, not parts of the app, and
both reach ClickHouse through @cbiolab/clickhouse, a client of their own. The app never imports
the sync — test/boundary.test.ts fails if app/, lib/ or mcp/ does — which is how "no
annotation service at run time" is held. In src/:
source.ts— what a source is: its database, table, version column and key columns, itsCREATEstatements, the warehouse query for its keys, how it reads the service's release and resolves a batch, and optionally how it verifies stored rows against the live service.sync.ts— the source-independent part: the diff, the batches, the failure rule,sync_run.sources/<source>.ts— one file per source.sources/oncokb.tsholds the OncoKB client,sources/genome-nexus.tsthe Genome Nexus one (both genomes).index.ts— the list of sources, the writer connection, and every store'sCREATEstatements, which a new local database runs (packages/importer/src/setup.ts), so its stores exist, empty.bin/annotate.ts— the command (npm run annotate), and the package'scbiolab-annotate.
Readers: lib/annotation.ts (the OncoKB pin, which studies are synced, the driver index) and the SQL
that joins the OncoKB store at the pin (lib/oql.ts's DRIVER, the mutation and SV tables, the
actionability and clonality views); lib/variant-annotation.ts (the Genome Nexus pins and the SQL the
mutation table reads annotation.variant with).
- A file in
packages/annotation-sync/src/sources/exporting anAnnotationSource, listed inANNOTATION_SOURCES. Its database is its own; a licensed source's especially. - Unit tests against the stand-in ClickHouse (
@cbiolab/clickhouse/testing) and a stubbed service, aspackages/annotation-sync/test/annotation-sync.test.tsdoes for OncoKB. - The readers: whatever joins the store does so at a pin, the pin is echoed in the result's sources, and a study the release does not cover is said to be missing (invariant 2).
The OncoKB store was filled by the standalone cBioPortal/oncokb-annotation-pipeline, in a database
of its own (oncokb_annotation), before this moved here; 001-annotation-database.sql copies its
rows and its sync_run history into annotation unchanged.