Skip to content

Read and export results

An export assembles a cohort's canonical variants with their stored model scores, dataset annotations, prioritization flags, and cross-model summary columns. Altar writes five export shapes—from single-table wide Parquet or TSV files for small runs to column-striped wide datasets, schema-grouped long datasets, prioritized NDJSON, and occurrence-aligned augmented VCFs for large compendia.

Export formats and single-scan warehouse sessions in Altar 0.10: cohorts, annotations, stored lineages, and CrossModelReducer summaries render into Wide TSV/Parquet, Striped Wide (altar-wide/1), Unified Long (altar-long/1), Prioritized NDJSON, and Augmented VCF v2. Export formats and single-scan warehouse sessions in Altar 0.10: cohorts, annotations, stored lineages, and CrossModelReducer summaries render into Wide TSV/Parquet, Striped Wide (altar-wide/1), Unified Long (altar-long/1), Prioritized NDJSON, and Augmented VCF v2.
Export shape Layout & files Best suited for Maturity
Wide Parquet / TSV part-*.parquet or part-*.tsv.gz, _columns.tsv, _models.json (TSV) Cohorts with up to ~1,500 models (up to 10,000 wide columns on BigQuery server-side TSV) Stable
Striped Wide Parquet (altar-wide/1) variants/chromosome=<chr>/, stripes/stripe_<NNNN>/chromosome=<chr>/, _columns.tsv, _manifest.json Multi-thousand-model wide tables read selectively by column or chromosome via open_wide_dataset Provisional
Unified Long (altar-long/1) models/, scores/<table>/chromosome=<chr>/, optional variants/, _manifest.json Compendia of hundreds or thousands of models queried in SQL, DuckDB, or DataFrames Provisional
Prioritized NDJSON part-*.json.gz with nested model_scores structs Downstream document or application database loads of prioritized variants Stable
Augmented VCF v2 (altar-augmentation-buckets-v2) .altar.vcf.gz, .vcf.gz.csi, .manifest.json via bucket=<NNNNNN>/ occurrence buckets Returning annotations, headline summaries, and selected model scores on original VCF records and genotypes Stable

Detail tables and opaque artifacts stay in their respective stores rather than flattening into cohort exports; see Read details and artifacts.

Read the export

By default, altar run writes its export to <work_dir>/export (unless [export] destination sets another path) alongside companion metadata files whose leading underscores keep Parquet glob readers from treating them as data shards:

$ ls first-scores/export
_columns.tsv  _run_summary.json  part-000000000000.parquet
import pandas as pd

df = pd.read_parquet("first-scores/export")
[export]
format = "parquet"        # or "tsv"
prioritized_only = false  # true keeps only prioritized variants

Every wide table has one row per distinct variant in genomic order (chr1..chr22, chrX, chrY, chrM, then other contigs by 1-based position) and orders its columns as:

  1. variant_id (chr:pos:ref:alt) and variant-level prioritized (bool).
  2. Cross-model summary columns (kind == "display"), such as top_model_id, top_model_name, top_effect, max_abs_effect, or prioritized_model_count, when CrossModelReducer summaries are configured.
  3. Annotation columns from each configured source, such as gnomad_af and clinvar_classification.
  4. One block per model: each score column and the model's own prioritized flag prefixed with <token>__<hash12>_<col> (export_col_alias(model_id, model_name, col)), where <token> is sanitized from model_name (defaulting to the model key) and <hash12> is the first 12 hex characters of sha256(model_id) (for example legnet_wtc11__60a71072bf29_activity_delta).
  5. prioritized_model_ids and prioritized_source_names: lists of the model keys and source names whose prioritization rules matched the variant ([] when none matched).

An empty cell (NULL / None) means no value exists for that variant—either the annotation source has no record or the model did not score the variant. Per-cell <prefix>_score_lineage_id columns are omitted from wide exports by default; pass include_lineage_ids=True in Python (wide_layout, render_wide_tsv, render_wide_parquet, export_wide_parquet, export_wide_tsv, or export_prioritized_ndjson) when you need row-level lineage attribution inside every model block. Otherwise, accepted lineage IDs and observed row counts per model are recorded once in _models.json, WideDatasetManifest.models, or models/.

Find a model's columns

_columns.tsv (COLUMN_MANIFEST_FILE) lists every wide column in table order:

Column Holds
column Physical column name in the wide table.
kind variant_key (variant_id), prioritization (prioritized and reason lists), display (CrossModelReducer outputs), annotation (source column), score (model score), or lineage (score_lineage_id when include_lineage_ids=True).
field Unprefixed field name (activity_delta, logfc, or the column's own name).
dtype, repeated Logical type (float, int, bool, str, json, or struct) and whether the column holds a list (true / false).
label Human-readable display label for a score or annotation column.
source Source name for an annotation column.
model_id, model_name Model key and display name for a model's columns.
plugin_id, plugin_version Binding ID and version for a model's columns.
result_schema_version, result_schema_hash Version and compatibility hash of the model's ResultSchema.

Filter _columns.tsv to select all columns of one model or one semantic score field across all models:

import pandas as pd

columns = pd.read_csv("first-scores/export/_columns.tsv", sep="\t")
table = pd.read_parquet("first-scores/export")

legnet_cols = columns.query("model_id == 'legnet-wtc11' and kind == 'score'")["column"]
deltas = columns.query("field == 'activity_delta'")[["column", "model_id"]]
subset = table[["variant_id", *legnet_cols]]

In Python, wide_column_manifest(layout) and write_column_manifest(layout, destination_uri, storage=...) (altar.export) generate _columns.tsv, and write_models_manifest writes _models.json (MODELS_MANIFEST_FILE) with each model's accepted_lineage_ids and observed_lineage_counts.

Summarize across models

Attach typed CrossModelReducer objects (altar.export, Provisional) to compute variant-level summaries across models in one pass—in SQL on BigQueryScoreStore and in Python on SqliteScoreStore and DuckDBScoreStore. By default (effect="primary_effect"), each reducer reads ResultSchema.primary_effect from each binding's manifest (such as logfc, counts_log2fc, or activity_delta), allowing distinct model architectures to participate in one summary:

Reducer Default output columns Behavior
TopModel(effect="primary_effect", prioritize_first=True, id_alias="top_model_id", name_alias="top_model_name", effect_alias="top_effect") top_model_id, top_model_name, top_effect Picks the non-null row ranked by (prioritized DESC, abs(effect) DESC, model_id ASC) (or without prioritized DESC when prioritize_first=False) and projects its signed effect, model_id, and ScoredModel.model_name. Set any alias to None to omit that column.
MaxAbs(effect="primary_effect", prioritized_only=False, alias="max_abs_effect") max_abs_effect Maximum abs(effect) across scored models (or only models that prioritized the variant).
CountWhere(prioritized_only=True, alias="prioritized_model_count") prioritized_model_count Count of models that prioritized (prioritized_only=True) or scored (prioritized_only=False) the variant (0 when unscored).
from altar.export import CountWhere, MaxAbs, TopModel

reducers = [
    TopModel(),
    MaxAbs(alias="max_abs_effect"),
    CountWhere(prioritized_only=True, alias="prioritized_model_count"),
]

Five export shapes

1. Wide Parquet and TSV

Wide Parquet preserves native list and struct columns (such as clinvar_conditions and clinvar_genes). Wide TSV encodes repeated, struct, and json columns as compact JSON strings and writes _columns.tsv, _models.json, and _provenance.json beside part-*.tsv.gz.

On BigQueryScoreStore, session.export_wide_tsv(..., single_file=True) executes server-side in BigQuery up to BigQuery's 10,000-column table limit—pre-pivoting <= 2,000-column scratch slices when inline SQL exceeds 950 KB and composing gzipped slices into a single headered .tsv.gz object. Above 10,000 columns, export_wide_tsv raises WideExportColumnLimitExceeded (altar.export) unless allow_bucket_fallback=True is passed.

from altar.export import render_wide_parquet, render_wide_tsv, write_column_manifest
from altar.storage import LocalStorage

storage = LocalStorage()
async with score_store.result_buckets(
    variant_ids=cohort_ids,
    models=scored_models,
    annotation_sources=sources,
) as buckets:
    await render_wide_parquet(buckets, "out/parquet", storage=storage)
    await write_column_manifest(buckets.layout, "out/parquet", storage=storage)
    await render_wide_tsv(buckets, "out/tsv", storage=storage)
    await write_column_manifest(buckets.layout, "out/tsv", storage=storage)
[export]
format = "tsv"            # default is "parquet"
destination = "out/tsv"
prioritized_only = false

2. Striped wide Parquet (altar-wide/1) and open_wide_dataset

When a cohort has thousands of models (for example, 3,000 models producing ~18,000 wide columns), a single Parquet query exceeds warehouse column and sort-memory limits. export_wide_parquet (altar.export, Provisional) partitions the wide layout horizontally by chromosome=<chr> and vertically into aligned stripes:

  • variants/chromosome=<chr>/part-*.parquet: 0-based row_ordinal per chromosome, variant_id, prioritized, reducer columns, annotations, and prioritization reason lists.
  • stripes/stripe_<NNNN>/chromosome=<chr>/part-*.parquet: row_ordinal, variant_id, and up to max_columns_per_stripe=4000 model columns per stripe.
  • _columns.tsv and _manifest.json (read_wide_dataset_manifest, written last as the atomic completion marker).

open_wide_dataset reads _manifest.json, opens only variants/ and the stripe directories containing your requested columns and chromosomes, verifies (row_ordinal, variant_id) alignment, and returns one pyarrow.Table:

from altar.export import export_wide_parquet, open_wide_dataset
from altar.storage import LocalStorage

await export_wide_parquet(
    score_store,
    "out/wide-striped",
    storage=LocalStorage(),
    variant_ids=cohort_ids,
    models=scored_models,
    annotation_sources=sources,
    reducers=reducers,
    max_columns_per_stripe=4_000,
)

table = open_wide_dataset(
    "out/wide-striped",
    columns=["variant_id", "gnomad_af", "top_model_id", "top_effect"],
    chromosomes=["chr1", "chr11"],
)
df = table.to_pandas()

3. Unified long dataset (altar-long/1)

Long exports group models that share one binding and ResultSchema version into a single narrow score table with one row per (variant_id, model_id) instead of one column block per model (so 500 ChromBPNet models share one scores/chrombpnet_v0_0_1__6b809b253c84/ table with a logfc column). Both export_long_dataset (altar.export, writing the chromosome-partitioned altar-long/1 dataset with _manifest.json, models/, scores/<table>/chromosome=<chr>/, and optional variants/) and [export] layout = "long" in altar run are Provisional.

import duckdb
from altar.export import export_long_dataset, read_long_dataset_manifest
from altar.storage import LocalStorage

storage = LocalStorage()
long_export = await export_long_dataset(
    score_store,
    scored_models,
    "out/long",
    storage=storage,
    variants=cohort_ids,
    include_variants=True,
    annotation_sources=sources,
    reducers=reducers,
)
loaded = await read_long_dataset_manifest("out/long", storage=storage)

rel = duckdb.sql("""
    SELECT s.variant_id, m.model_name, s.activity_delta, v.gnomad_af
    FROM 'out/long/scores/*/chromosome=*/*.parquet' AS s
    JOIN 'out/long/models/*.parquet' AS m USING (model_id)
    JOIN 'out/long/variants/chromosome=*/*.parquet' AS v USING (variant_id)
    WHERE s.prioritized
""")
[export]
layout = "long"
format = "parquet"

altar run writes models/, variants/, scores/<table>/, _provenance.json, and _run_summary.json under <work_dir>/export:

import pandas as pd

export = "first-scores/export"
models = pd.read_parquet(f"{export}/models")
variants = pd.read_parquet(f"{export}/variants")
score_table = models.loc[models["plugin_id"] == "org.kundajelab.altar.model.legnet", "table"].iloc[0]
scores = pd.read_parquet(f"{export}/{score_table}")
joined = scores.merge(models[["model_id", "model_name"]], on="model_id").merge(variants, on="variant_id")

4. Prioritized NDJSON

render_prioritized_ndjson (over ResultBuckets) and session.export_prioritized_ndjson (on BigQueryScoreStore) write gzipped newline-delimited JSON shards (part-*.json.gz) containing only prioritized variants, with variant_id, reducer columns, typed JSON annotations, prioritized_model_ids, prioritized_source_names, and nested model_scores entries (include_lineage_ids=False by default):

from altar.export import render_prioritized_ndjson
from altar.storage import LocalStorage

async with score_store.result_buckets(
    variant_ids=cohort_ids,
    models=scored_models,
    annotation_sources=sources,
) as buckets:
    async with buckets.prioritized() as kept:
        await render_prioritized_ndjson(kept, "out/prioritized", storage=LocalStorage())

5. Augmented VCF v2

Normalized variant tables drop multi-allelic record structure, duplicate VCF lines, sample columns, and genotypes. Augmented VCF v2 (altar-augmentation-buckets-v2, AUGMENTATION_BUCKET_SCHEMA_VERSION) joins export results back onto every ALT allele of the source VCF in (record_ordinal, alt_index) order and writes an indexed .vcf.gz plus a checksummed .manifest.json.

render_augmentation_buckets (altar.export) and session.export_augmentation_buckets (BigQueryScoreStore) support three include_model_scores modes:

  • False (default, lean mode): precomputes max_abs_effect and top_model_id across all models and omits nested model_scores, shrinking occurrence buckets on multi-hundred-model callsets when only ALTAR1_STATUS, ALTAR1_PRIORITIZED, ALTAR1_MAX_ABS_EFFECT, ALTAR1_TOP_MODEL, and annotation INFO fields are needed.
  • Sequence[str] (selective mode, such as ["chrombpnet-k562"]): computes headline summaries across all models while keeping ALTAR1_MODEL_SCORE entries only for the named model_ids.
  • True (full mode): retains every scored model's nested entry for ALTAR1_MODEL_SCORE.
from altar.export import render_augmentation_buckets
from altar.storage import LocalStorage
from altar.variants import augment_run_export, write_augmented_vcf

# Option A: one-call helper over a Parquet `altar run` export directory
summary = augment_run_export(
    "first-scores/export",
    "cohort.vcf",
    "cohort.altar.vcf.gz",
    reference_fasta="hg38.fa",
)


# Option B: build lean v2 occurrence buckets from ResultBuckets, then write the VCF
async def build_vcf(buckets, occurrence_parts):
    await render_augmentation_buckets(
        buckets,
        occurrence_parts,
        "work/buckets",
        storage=LocalStorage(),
        bucket_size=50_000,
        include_model_scores=False,
    )
    return write_augmented_vcf(
        "cohort.vcf",
        "work/buckets",
        "work/models.json",
        "ingest/manifest.json",
        "cohort.altar.vcf.gz",
        "cohort.altar.manifest.json",
        "out/parquet",
        include_model_scores=False,
        reference_fai="hg38.fa.fai",
    )
python -m altar.variants.export.run_export \
    --export-dir first-scores/export \
    --input-vcf cohort.vcf \
    --reference-fasta hg38.fa \
    --output-vcf cohort.altar.vcf.gz

The original altar run must have read cohort.vcf with [variants] reference_fasta set to the same FASTA so indels left-align identically, and [export] format must be "parquet". Source bindings with vcf_info_fields() presets (gnomad, clinvar, phylop100way, opentargets_e2g, alphamissense, spliceai) populate ALTAR1_* INFO fields automatically; see Ingest variants and write augmented VCFs for custom --annotation-fields-json declarations.

Share one warehouse scan across exports

On BigQueryScoreStore, store.warehouse_export(...) (Provisional) collapses annotations once, scans each physical score table once into a clustered staging table, and yields a WarehouseExportSession that writes multiple export formats without rescanning base tables. Passing resume_key= retains completed staging tables for 24 hours on error (session.resumed == True on retry), hashing altar.__version__, the rendered SQL templates, resolved lineages, and variants_relation by name (pass a new resume_key if variants_relation or existing lineages' rows are rewritten in place); see Run at warehouse scale on BigQuery for full details:

async with bq_store.warehouse_export(
    variants_relation="`my-project.jobs.cohort_variants`",
    models=scored_models,
    annotation_sources=sources,
    reducers=reducers,
    resume_key="job-1:exports",
) as session:
    await session.export_wide_parquet(destination_uri="gs://my-bucket/job-1/wide", storage=gcs_storage)
    await session.export_long_dataset("gs://my-bucket/job-1/long", storage=gcs_storage, include_variants=True)
    await session.export_wide_tsv(destination_uri="gs://my-bucket/job-1/tsv", storage=gcs_storage, single_file=True)
    await session.export_prioritized_ndjson(destination_uri="gs://my-bucket/job-1/prioritized", storage=gcs_storage)

Read its provenance

altar run prints a JSON RunSummary ("format": "altar.run-summary", "version": 1) on standard output and writes _run_summary.json in the export directory, recording variant_count, models (candidate, set-aside, cache-hit, and scored counts), sources (contract, version, release, and genome build), potential_misses, dropped_alleles, and provenance.

Exported files carry the same provenance payload so a shared directory or Parquet file stays self-describing:

Export Provenance location
Wide Parquet Parquet file key-value metadata under b"altar.provenance"
Wide TSV _provenance.json and _models.json beside part-*.tsv.gz
Striped wide (altar-wide/1) & Unified long (altar-long/1) _manifest.json (models and _provenance)
CLI long layout _provenance.json beside models/, variants/, and scores/
import json
import pyarrow.parquet as pq

metadata = pq.read_metadata("first-scores/export/part-000000000000.parquet").metadata
provenance = json.loads(metadata[b"altar.provenance"])

Tell exports apart

Two runs of the same model key with different score-changing settings produce identical wide column names. Compare their provenance records to distinguish them:

  • provenance["models"][key]["requested"]["lineage_id"] identifies the exact scientific configuration requested by the run.
  • _models.json (or provenance["models"][key]["producers"]) lists every score_lineage_id that contributed rows and its row count; passing include_lineage_ids=True adds <prefix>_score_lineage_id per row.
  • provenance["sources"][name] gives the dataset release and genome_build served by each annotation source.

Lineage attribution across model updates

When a model binding declares LineageEquivalence across validated container rebuilds, compatible wrapper versions, or newly defaulted configuration fields, an export may read rows stored under an equivalent historical lineage alongside current rows. Both _models.json and _provenance.json record the accepted_lineage_ids, the equivalence rules_id, and observed_lineage_counts for each model; see Score reuse and lineage.

Read details and artifacts

Detail tables and opaque artifacts remain in DetailStore and ArtifactStore. Read them in Python by model_id and detail or artifact schema name:

import asyncio
from altar.results import SqliteDetailStore, StorageArtifactStore
from altar.storage import LocalStorage


async def main() -> None:
    with SqliteDetailStore(".altar/scores.details.sqlite") as details:
        async for row in details.read_rows(model_id="sei", detail_name="sequence_class_effects"):
            print(row["variant_id"], row["class_label"], row["class_effect"])

    with StorageArtifactStore(LocalStorage(), ".altar/artifacts", ".altar/artifacts/index.sqlite") as artifacts:
        async for record in artifacts.read_records("sei", "chromatin_profile_effects"):
            print(len(record.variant_ids), "variants in", await artifacts.locate(record))


asyncio.run(main())

Pass accepted_lineage_ids=resolution.lineage_ids (and optional variant_ids=...) to restrict reads to a specific run's resolved lineages.

Next