Export scores for publication¶
A score store can export the scores of a set of models as Parquet files, without their annotations, at any size: the scores of one job's variants, or every score the models hold. Use it to publish a score release, to hand a large self-hosted run to collaborators, or to load scores into another database. The files describe themselves, and a manifest lists every file with its size, rows and checksum.
The export is provisional.
Before you start¶
You need a score store that holds the scores, and the ScoredModel of each model to export, as you build them to
assemble results. SqliteScoreStore, InMemoryScoreStore and
BigQueryScoreStore export; isinstance(store, ExportsLongScores) tells you whether another store can.
This export holds only scores. For a job's annotated results, with prioritized and the sources' columns, use the
wide or long layouts of Export results.
Export from SQLite¶
export_long_scores writes the files under a destination, through any storage, and returns what it wrote:
from altar.results import SqliteScoreStore
from altar.storage import LocalStorage
async def publish(models):
with SqliteScoreStore("scores.db") as store:
export = await store.export_long_scores(models, "release/2026-11", storage=LocalStorage())
print(export.manifest.row_count, "score rows in", len(export.manifest.files), "files")
Without variants, the export holds every score the models have. Pass variants= a list of canonical variant IDs
to export only those, and chromosomes=["chr1", "chrX"] to export only some chromosomes. The models must share one
genome build.
Each model's rows are the ones every read of the store returns: its current lineage first, then the lineages its
binding declares equivalent and those its ScoreReusePolicy accepts, in that order
(Reuse scores across model updates). A variant has one row per model.
SQLite and the in-memory store read each chromosome's variants 10,000 at a time per model and stream the Parquet
through the storage, so a FsspecStorage writes them straight to an object store. rows_per_file= (default
50,000,000) caps the rows of one file.
A destination that already holds files is refused with FileExistsError. overwrite=True deletes them first, so a
second export leaves nothing of the first behind. The manifest is written last: a directory without one is not a
finished export.
Export from BigQuery¶
BigQueryScoreStore.export_long_scores runs the export in the warehouse, so the rows never pass through your
process. The destination must be a gs:// prefix, and the storage must reach it:
from altar.results import BigQueryScoreStore
from altar.storage import FsspecStorage
async def publish(store: BigQueryScoreStore, models):
return await store.export_long_scores(
models,
"gs://my-bucket/releases/2026-11",
storage=FsspecStorage(),
maximum_bytes_billed=20 * 2**40,
)
For each score table and each chromosome that holds its rows, one EXPORT DATA job writes Parquet to Cloud Storage.
It reads the same rows as every read of the store. The score table is clustered by genome, model and chromosome, so
each job reads only its own models' rows on one chromosome:
EXPORT DATA OPTIONS(
uri='gs://my-bucket/releases/2026-11/scores/chrombpnet_v0_0_1__6b809b253c84/chromosome=chr1/part-*.parquet',
format='PARQUET', overwrite=true)
AS SELECT variant_id, model_id, score_lineage_id, CAST(logfc AS FLOAT64) AS logfc, ..., chr, pos, ref, alt, genome
FROM (
SELECT s.* FROM `my-project.lake.scores` s
WHERE model_id IN ('chrombpnet-k562', 'chrombpnet-hepg2') AND chr = 'chr1'
AND ((model_id = 'chrombpnet-k562' AND genome = 'hg38' AND score_lineage_id IN ('sha256:…')) OR …)
QUALIFY ROW_NUMBER() OVER (
PARTITION BY model_id, genome, variant_id
ORDER BY CASE WHEN … THEN 0 … END, created_at DESC, TO_JSON_STRING(s)) = 1)
Before any job, a dry run estimates the scan. Over maximum_bytes_billed (default: the store's
export_maximum_bytes_billed) the export raises ExportScanLimitExceeded and nothing is written. Every job carries the
same limit. max_concurrent_jobs= (default 4) sets how many jobs run at once.
variants= takes a list of variant IDs, which the export loads into a scratch table and drops afterwards, or a
StoreRelation naming a table of your own with a variant_id column. A relation's chromosomes, when you give them,
limit the scan to those chromosomes.
Your credentials need to run query jobs and read the score table and its lineage tables, and the store's dataset must
allow the scratch table a listed scope loads. Cloud Storage needs to let them create, list, read and delete objects
under the destination: EXPORT DATA writes the files with your credentials, and the storage lists them, reads each
file's size, CRC32C and Parquet footer, deletes an earlier export's files with overwrite=True, and writes the
manifest. The bucket must be in the dataset's location.
The files¶
release/2026-11/
├── _manifest.json
├── models/
│ └── part-000000000000.parquet
└── scores/
└── chrombpnet_v0_0_1__6b809b253c84/
├── chromosome=chr1/
│ ├── part-000000000000.parquet
│ └── part-000000000001.parquet
├── chromosome=chr2/
│ └── part-000000000000.parquet
└── ...
The score tables are the long format's: models of one binding and
one version of its score columns share a table, named the same way in every export. Each table has one directory per
chromosome, chromosome=<chr>. A score file has one row per variant and model:
| Column | Holds |
|---|---|
variant_id |
The canonical variant ID, such as chr1:12345:A:G |
model_id |
The model key |
score_lineage_id |
The lineage the row's scores came from |
| the binding's score columns | Each under its own name and type, such as logfc (double); NULL when the model has no value |
chr, pos, ref, alt |
The variant's locus |
genome |
The genome build |
Its first columns are the long format's score table, without its prioritized, which depends on annotations.
long_scores_schema(table) returns the Arrow schema.
The models table has one row per model: model_id, model_name, plugin_id, plugin_version,
result_schema_version, result_schema_hash, genome, table (the directory of its score table),
score_lineage_ids (the lineages its rows were selected from, in preference order), run_identity (its run
identity, as JSON text) and fields (each score column's name, dtype, label, meaning and nullable).
A file written by SQLite or the in-memory store also carries Parquet key-value metadata under altar.long_scores: the
format, its table, binding, result schema version, genome, chromosome, models and their lineages.
BigQuery's EXPORT DATA cannot set it, so its files say what they hold through their columns and the manifest.
The manifest¶
_manifest.json describes the export, in the format altar-long-scores/1. Its JSON Schema is
altar-long-scores-1.schema.json.
| Key | Holds |
|---|---|
format |
altar-long-scores/1 |
genome |
The genome build of every model |
store |
The store that wrote it: sqlite, memory or bigquery |
scope |
variants (all, listed or relation), variant_count for a listed scope, and the chromosomes it was limited to |
file_metadata |
Whether the score files carry altar.long_scores metadata; false for BigQuery |
row_count |
The score rows of every table together |
tables |
Each score table's name, path, plugin_id, result_schema_version, model_ids and columns with their Arrow types |
models |
Each model's row of the models table, with run_identity as JSON |
files |
Every file: its path under the destination, table, chromosome (null for models), size, row_count, sha256 and crc32c |
_provenance |
What provenance= returned, or null |
A file's sha256 is set when your process wrote it, and crc32c when the storage reports the object's own checksum,
as Cloud Storage does. A file BigQuery wrote has a crc32c and no sha256.
{
"format": "altar-long-scores/1",
"genome": "hg38",
"store": "bigquery",
"scope": {"variants": "all", "variant_count": null, "chromosomes": null},
"file_metadata": false,
"row_count": 3046511882,
"tables": [{"name": "chrombpnet_v0_0_1__6b809b253c84", "model_ids": ["chrombpnet-k562"], "...": "..."}],
"models": [{"model_id": "chrombpnet-k562", "score_lineage_ids": ["sha256:0f53…"], "...": "..."}],
"files": [
{"path": "models/part-000000000000.parquet", "table": "models", "chromosome": null, "size": 9161,
"row_count": 1, "sha256": "sha256:97c0…", "crc32c": "qTxfkw=="},
{"path": "scores/chrombpnet_v0_0_1__6b809b253c84/chromosome=chr1/part-000000000000.parquet",
"table": "chrombpnet_v0_0_1__6b809b253c84", "chromosome": "chr1", "size": 268435456,
"row_count": 41943040, "sha256": null, "crc32c": "n5Ak2Q=="}
],
"_provenance": {"release": "2026-11"}
}
read_long_scores_manifest(destination, storage=...) reads it back as a LongScoresManifest, and refuses a document
of another format. provenance= takes the same callback the other exports take; its mapping becomes _provenance.
Read the files¶
DuckDB and pandas read a score table in place, with its chromosome directories as a column:
import duckdb
import pandas as pd
table = "release/2026-11/scores/chrombpnet_v0_0_1__6b809b253c84"
scores = pd.read_parquet(table, filters=[("chromosome", "=", "chr1")])
duckdb.sql(f"SELECT model_id, count(*) FROM read_parquet('{table}/*/*.parquet') GROUP BY model_id")
Check a copy against the manifest by comparing each file's size and sha256 or crc32c, and its row_count with
the rows in its Parquet footer.
A wide table for a model subset¶
Turn a score table into one column per model and field for a few models. With DuckDB:
PIVOT (
SELECT variant_id, model_id, logfc, jsd
FROM read_parquet('release/2026-11/scores/chrombpnet_v0_0_1__6b809b253c84/*/*.parquet')
WHERE model_id IN ('chrombpnet-k562', 'chrombpnet-hepg2')
)
ON model_id
USING first(logfc) AS logfc, first(jsd) AS jsd
GROUP BY variant_id
The columns are variant_id, chrombpnet-k562_logfc, chrombpnet-k562_jsd, chrombpnet-hepg2_logfc and so on. With
pandas:
import pandas as pd
table = "release/2026-11/scores/chrombpnet_v0_0_1__6b809b253c84"
models = ["chrombpnet-k562", "chrombpnet-hepg2"]
scores = pd.read_parquet(table, filters=[("model_id", "in", models)])
wide = scores.pivot(index="variant_id", columns="model_id", values=["logfc", "jsd"])
wide.columns = [f"{model}_{field}" for field, model in wide.columns]
A variant a model did not score is NULL in that model's columns.
Test a store's export¶
altar.testing.LongScoresExportContract checks a store's export_long_scores: that it writes the rows
read_selected_scores returns, one per variant and model, one chromosome per directory, a manifest that lists every
file and model, a second export that replaces the first, a table per result schema and NULL for a missing score.
Supply a fresh store, the storage it writes through and a fresh destination:
import pytest
from altar.storage import LocalStorage
from altar.testing import LongScoresExportContract
class TestMyStoreExport(LongScoresExportContract):
@pytest.fixture
def store(self):
return MyScoreStore()
@pytest.fixture
def storage(self):
return LocalStorage()
@pytest.fixture
def destination(self, tmp_path):
return str(tmp_path / "release")
Override export_options to pass your store's own keywords, such as BigQuery's maximum_bytes_billed. These names
are provisional.