Skip to content

Container commands

The variant ingest, annotation and augmented-VCF steps are Python modules that a pipeline runs as container tasks. Ingest variants and write augmented VCFs explains when to run each one; this page lists their flags, the files they write, and how they report a failure.

Command What it does Label
altar.variants.preprocessing.pipeline Validate and normalize a VCF or variant TSV, write its occurrences and canonical variants, and split the valid variants by region category. Stable
altar.variants.preprocessing.selected_vcf_ingest Ingest one file of a callset for a chosen set of samples, after checking the file and the sample list against digests. Stable
altar.variants.preprocessing.callset_union Merge the canonical variants of several such ingests and drop repeats. Provisional
altar.variants.annotation.annotate Annotate variants with region, nearest genes, cCREs and allele frequencies, as JSONL. Stable
altar.variants.export.augmented_vcf Write the input VCF back with Altar's results as INFO fields. Stable
altar.variants.export.run_export Write an augmented VCF from an altar run export in one step. Provisional

Maturity labels says what each label means. A Stable command keeps its flags, output files, error codes and exit statuses. The log lines it prints while it runs are for people to read.

How to run them

The variants runtime image (runtimes/variants) sets ENTRYPOINT ["python", "-m"], so a container task's first argument is the module path and the flags follow it:

altar.variants.preprocessing.pipeline -i input.vcf.gz -g genome.fa -o valid.tsv --invalid-out invalid.tsv --region-out-dir regions/

Anywhere Altar is installed, run the same module with python -m:

python -m altar.variants.preprocessing.pipeline -i input.vcf.gz -g genome.fa -o valid.tsv \
    --invalid-out invalid.tsv --region-out-dir regions/

Every command takes -h or --help, and every one takes --failure-json (see Errors).

Errors

A command that fails prints one line to standard error and exits with a status that says whose fault it was:

altar.variants.preprocessing.pipeline: error: MALFORMED_TSV: TSV row 3 has 2 columns; expected 4 or 5.

The line is <module>: error: <CODE>: <message>. CODE is a stable identifier from the table below, so a program can act on it; the message is for a person and may change. A usage error, such as a missing required flag, prints the usage first and then the same line with the code USAGE_ERROR.

Exit status Meaning
0 The command succeeded.
1 The command failed for a reason other than its input: its own annotation data is missing or stale, a staged file changed while it ran, an output did not read back as written, or an error it does not recognize. An unrecognized error prints its Python traceback instead of the error line.
2 The command refused its input: a file or flag it was given, including a usage error. Running it again with the same input fails the same way.

The failure record

With --failure-json PATH, a failed command also writes its failure to PATH as JSON, so the pipeline that ran it can collect the record as a task output instead of reading its log:

{
  "code": "MALFORMED_TSV",
  "exit_status": 2,
  "format": "altar.command-failure",
  "message": "TSV row 3 has 2 columns; expected 4 or 5.",
  "module": "altar.variants.preprocessing.pipeline",
  "version": 1
}
Key Value
format Always "altar.command-failure".
version The record's version, 1.
module The command's module path.
code The code of the error line; UNEXPECTED_ERROR for an error the command does not recognize.
message The message of the error line, on one line. For UNEXPECTED_ERROR, the exception's type and message.
exit_status 1 or 2, as the table above.

The record is written only when the command fails. A command removes a record already at PATH before it starts, so a retried task never reads an earlier attempt's failure. A command killed from outside, for example for running out of memory, writes none.

Error codes

Code Commands Exit Meaning
USAGE_ERROR all 2 A flag is missing, unknown or has a value the command does not accept, such as an unknown region category.
FILE_NOT_FOUND all 2 A file the flags name does not exist.
UNKNOWN_GENOME_BUILD pipeline, selected_vcf_ingest 2 --genome-build names no assembly Altar knows.
INVALID_VARIANT annotate 2 A variant row cannot be read, such as a position that is not a number.
UNKNOWN_FORMAT pipeline 2 The input format is not auto, tsv or vcf.
UNSUPPORTED_BCF pipeline 2 The input is a BCF file. Convert it to .vcf.gz.
UNSUPPORTED_GVCF pipeline, selected_vcf_ingest 2 The input is a gVCF.
MALFORMED_INPUT pipeline 2 The input starts like a gzip file but cannot be read as one.
MALFORMED_VCF pipeline, selected_vcf_ingest, augmented_vcf, run_export 2 htslib cannot parse the VCF's header or a record.
MALFORMED_TSV pipeline 2 A TSV row does not have 4 or 5 columns, or its position is not a number.
TARGET_SAMPLE_NOT_FOUND pipeline, selected_vcf_ingest 2 A selected sample, or the family's proband, is not a sample of the VCF.
MISSING_GT pipeline, selected_vcf_ingest 2 Samples are selected, but the VCF declares no FORMAT/GT.
TARGET_SAMPLE_REQUIRES_VCF pipeline 2 Samples are selected, or a family is given, for TSV input.
AMBIGUOUS_TARGET_SAMPLES pipeline 2 Both --selected-samples-file and --family-phenopacket are given.
INVALID_TARGET_SAMPLES, DUPLICATE_TARGET_SAMPLE pipeline, selected_vcf_ingest 2 The selected sample IDs are empty, padded with spaces, or repeated.
MISSING_FAMILY_OUTPUT pipeline 2 --family-phenopacket is given without --family-out.
INVALID_FAMILY_PHENOPACKET pipeline 2 The family Phenopacket is incomplete, or does not bind its members to the VCF's samples.
INVALID_DIGEST selected_vcf_ingest 2 --expected-input-sha256 or --expected-selected-samples-sha256 is not sha256:<hex>. A bare hex digest is refused with a message that says to add the prefix.
INPUT_DIGEST_MISMATCH selected_vcf_ingest, augmented_vcf 2 The input VCF's SHA-256 is not the expected one, or not the one the ingest manifest records.
SAMPLE_SELECTION_MISMATCH selected_vcf_ingest 2 The selected samples' digest is not --expected-selected-samples-sha256.
INPUT_CHANGED_DURING_INGEST selected_vcf_ingest 1 The staged VCF changed while it was read. Stage it again and rerun.
EMPTY_CALLSET, DUPLICATE_SOURCE_SHARD, INCOMPATIBLE_SHARD_INGESTS callset_union 2 No ingest was given, one file was given twice, or the ingests differ in build or selected samples.
INVALID_SHARD_INGEST, INVALID_CANONICAL_SHARD callset_union 2 An ingest's manifest or Parquet files are incomplete, changed, or from another ingest version, or the manifest is not an altar.ingest-manifest version 1 document. An ingest whose validation_version or normalization_policy is null predates those rules and must be ingested again to be combined.
INVALID_CANONICAL_VARIANT, CANONICAL_ID_COLLISION callset_union 2 The merged rows hold an invalid canonical variant, or one ID with two different rows.
ANNOTATION_DATA_NOT_FOUND pipeline, annotate 1 A region or allele-frequency data file is missing from the data directory.
INVALID_REGION_DATA annotate 1 region_provenance.json is malformed, or does not describe the files beside it.
INVALID_OUTPUT_PATH augmented_vcf, run_export 2 --output-vcf does not end in .vcf.gz.
INVALID_INGEST_MANIFEST augmented_vcf, run_export 2 The ingest manifest is not JSON, not an altar.ingest-manifest version 1 document, or lacks a key the writer reads.
INVALID_MODELS_JSON augmented_vcf 2 --models-json is malformed or not an altar.augmented-vcf-models version 1 document, or --include-model-scores is given without score_fields.
INVALID_ANNOTATION_FIELDS augmented_vcf, run_export 2 --annotation-fields-json is malformed or not an altar.augmented-vcf-annotation-fields version 1 document, or declares an ID twice.
ANNOTATION_COLUMN_MISSING augmented_vcf, run_export 2 No bucket has a column a required annotation field reads, or a struct field it names.
INVALID_ANNOTATION_VALUE augmented_vcf, run_export 2 An annotation value cannot be written as its field's type or shape.
INVALID_BUCKETS augmented_vcf, run_export 2 A bucket has no Parquet parts, or a part has no model_scores column, as in the wide occurrence buckets v1 of earlier releases.
OCCURRENCE_MISMATCH augmented_vcf, run_export 2 The buckets' occurrences do not line up with the VCF's records and ALTs, or the counts differ from the ingest manifest's.
HEADER_CONFLICT augmented_vcf, run_export 2 The input VCF already declares an INFO field or model the output would write, with another definition.
GENOME_BUILD_MISMATCH augmented_vcf, run_export 2 An annotation field's source, or the ingest, is on another build than the VCF or the run.
UNSORTED_VCF augmented_vcf, run_export 2 htslib cannot index the output because the input's records are out of order.
UNSUPPORTED_SORT_POLICY augmented_vcf 2 The ingest sorted the VCF under a policy this writer does not sort under: one it does not know, or altar-sort-v1, which earlier releases recorded. An already sorted input (input_sorted: true) is read whatever its policy.
REFERENCE_FAI_REQUIRED augmented_vcf 2 The ingest sorted the VCF under altar-sort-v2, and --reference-fai is not given.
MALFORMED_REFERENCE_INDEX augmented_vcf, run_export 2 A line of the .fai index holds no contig name and length.
OUTPUT_VALIDATION_FAILED augmented_vcf, run_export 1 The written VCF does not read back with the expected records.
INVALID_EXPORT, EXPORT_NOT_LEFT_ALIGNED, GENOME_BUILD_MISSING, REFERENCE_FASTA_REQUIRED run_export 2 The export is not an altar run Parquet export, its run read no reference, it records no build, or neither --reference-fasta nor --ingest-dir is given.

The ingest commands' codes are the error_code of the VariantIngestError they raise, and the augmented-VCF commands' codes that of the AugmentationError, so a script that calls the functions directly sees the same codes.

altar.variants.preprocessing.pipeline

altar.variants.preprocessing.pipeline -i INPUT -g REFERENCE_FASTA -o VALID_OUT --invalid-out INVALID_OUT
    --region-out-dir REGION_OUT_DIR [options]
Flag Meaning Default
-i, --input The variants: a VCF, plain or BGZF-compressed, or a headerless TSV of chr, pos, ref, alt and an optional fifth ID column. gVCF and BCF are refused. Required.
-g, --reference-fasta The reference FASTA of --genome-build, which each variant is checked and normalized against. Required.
--genome-build, --genome The assembly of the input and the FASTA, such as hg38 or mm10. GRCh38 is read as hg38. hg38
-o, --valid-out The valid-variants TSV. Required.
--invalid-out The rejected-variants TSV. Required.
--region-out-dir The directory of region-category TSVs. Required.
--categories A comma-separated list of the region categories to write. All but intergenic.
-f, --format auto, tsv or vcf. auto reads the first line, through gzip when the file is gzipped: ##fileformat=VCF or #CHROM makes it a VCF, and anything else a TSV. The file's name is not read. auto
--occurrence-out-dir The directory of occurrence Parquet files. ingest/occurrences/ beside --valid-out
--canonical-out-dir The directory of valid canonical Parquet files. ingest/canonical/valid/ beside --valid-out
--invalid-parquet-out-dir The directory of invalid Parquet files. ingest/canonical/invalid/ beside --valid-out
--manifest-out The ingest manifest. ingest/manifest.json beside --valid-out
--header-out The input VCF's parsed header. ingest/header.vcf beside --valid-out
-b, --batch-size The most occurrence rows one ingest batch holds. 250000
--selected-samples-file One VCF sample ID per line. Only the ALTs at least one of these samples carries are scored. All ALTs.
--family-phenopacket A GA4GH Family Phenopacket that binds the family's members to the VCF's samples. Needs VCF input and --family-out. None.
--family-out The family evidence TSV, gzip-compressed. None.
--scratch-dir Where an unsorted VCF is sorted, in about twice the compressed input's space. The directory of --valid-out.
--data-dir The directory of region_annotations.parquet. $ALTAR_VARIANTS_DATA_DIR, then the installed package's data directory.
--failure-json The failure record. None.
File Contents
--valid-out Headerless, tab-separated chr, pos, ref, alt, source_variant_id, one row per scoreable ALT, normalized.
--invalid-out One row per rejected ALT: the occurrence columns below and error_message, with a header row when any ALT is rejected. Empty otherwise.
--region-out-dir/<category>.tsv The valid rows, as --valid-out writes them, of each region category. A row is in every category its labels match. Every requested category gets a file, empty when no row matches, and every file is empty for a build other than hg38.
--occurrence-out-dir/part-00000000.parquet, ... One row per ALT of every record, unsupported ones included: record_ordinal, alt_index, original_chrom, original_pos, original_ref, original_alt, source_variant_id, canonical_variant_id, status, error_code, canonicalizer_version, source_record_ordinal. The schema is altar.variants.OCCURRENCE_ARROW_SCHEMA.
--canonical-out-dir/part-00000000.parquet, ... The scoreable variants, canonical_variant_id, genome, chr, pos, ref, alt (CANONICAL_ARROW_SCHEMA).
--invalid-parquet-out-dir/part-00000000.parquet, ... The rejected ALTs, as --invalid-out (INVALID_ARROW_SCHEMA).
<part>.parquet.success.json Beside each Parquet file: its uri, row_count, size_bytes, sha256 (sha256:<hex>) and the ingest's run_fingerprint. A rerun of the same ingest reuses a file whose marker matches.
--header-out The VCF's header as htslib parsed it. Not written for TSV input.
--manifest-out Written last, so its presence marks the ingest complete. See The ingest manifest.
--family-out With a family: one row per variant the proband carries. Columns canonical_variant_id, chrom, pos, ref, alt, cohort_ac, cohort_an, cohort_af; then id, sample, gt, ad, dp and gq for each of proband_, mother_ and father_; then inheritance, affected_carriers, unaffected_carriers, shared_siblings, quality_flags and member_genotypes_json.

Parquet files are numbered from part-00000000.parquet (part-%08d.parquet), one per ingest batch that has rows of that kind. The region categories are coding, exonic, five_prime_utr, three_prime_utr, splice, splice_site, splice_region, intronic, promoter, noncoding_gene, genic and intergenic; altar.variants.REGION_CATEGORIES lists them, and DEFAULT_REGION_CATEGORIES the ones written without --categories (both provisional). Region annotations says what each one holds.

The ingest manifest

The manifest is one JSON object, and every key below is always present (null where the table says so). Every digest in it is spelled sha256:<hex>. The augmented-VCF writer refuses a manifest that lacks a key it reads: input_sha256, genome_build, record_count, alt_occurrence_count, input_sorted or sort_policy. It also refuses one without validation_version or normalization_policy, but accepts null for either, since it reads neither.

Key Value
format, version "altar.ingest-manifest" and 1.
source_format vcf or tsv.
input_size_bytes, input_sha256 The input's size and the SHA-256 digest of its bytes.
header_sha256 The SHA-256 digest of the parsed VCF header, or null for TSV input.
genome_build The assembly, in Altar's spelling, such as hg38. It is every canonical row's genome.
canonicalizer_version, validation_version, normalization_policy altar-vcf-v1, altar-validate-v3 and altar-normalize-v1, the rules the rows were made under. Altar's ingest always writes all three. validation_version and normalization_policy are null in a manifest recorded before those rules were tracked: the rules its rows were made under are unknown. callset_union refuses such an ingest; ingest the file again to combine it.
sort_policy, input_sorted altar-sort-v2, and whether the input was already in that order. When it was not, the records were numbered in sorted order.
selected_sample_count, selected_samples_sha256 With selected samples, their count and the SHA-256 digest of their sorted IDs as a JSON list; otherwise null.
record_count, alt_occurrence_count The input's records, and their ALTs.
valid_occurrence_count, invalid_occurrence_count, unsupported_occurrence_count, target_excluded_occurrence_count The ALTs that are scoreable, rejected by the reference check, unsupported (such as * or a symbolic ALT), and carried by no selected sample.
unique_canonical_variants, duplicate_canonical_occurrences The distinct scoreable variants, and the valid ALTs that repeat one.
normalized_occurrence_count The valid ALTs that normalization moved or trimmed.
occurrence_shards, canonical_shards, invalid_shards One entry per Parquet file: uri (the file name), row_count, size_bytes and sha256, its digest.

altar.variants.preprocessing.selected_vcf_ingest

altar.variants.preprocessing.selected_vcf_ingest --input INPUT --reference-fasta REFERENCE_FASTA
    --selected-samples-file FILE --output-dir OUTPUT_DIR --expected-input-sha256 DIGEST
    --expected-selected-samples-sha256 DIGEST [options]
Flag Meaning Default
--input One VCF file of a callset, plain or BGZF-compressed. Required.
--reference-fasta The reference FASTA of --genome-build. Required.
--selected-samples-file One selected VCF sample ID per line, none empty or padded. Required.
--output-dir The ingest's directory. Required.
--expected-input-sha256 The sha256:<hex> digest of the input's bytes. A mismatch fails before anything is written, and a bare hex digest is refused (INVALID_DIGEST). Required.
--expected-selected-samples-sha256 The sha256:<hex> digest of the sorted sample IDs as a JSON list, which altar.variants.canonical_sample_selection_digest returns. A mismatch fails before anything is written, and a bare hex digest is refused. Required.
--genome-build As the pipeline's. hg38
--batch-size As the pipeline's -b. 250000
--failure-json The failure record. None.

It writes the pipeline's ingest files, without region TSVs, under --output-dir: valid.tsv, invalid.tsv, occurrences/, canonical/valid/, canonical/invalid/, header.vcf and, last, manifest.json. It removes an earlier manifest.json first, so an interrupted retry never leaves one that looks complete.

altar.variants.preprocessing.callset_union

Provisional.

altar.variants.preprocessing.callset_union --ingest-dir DIR [--ingest-dir DIR ...] --output-dir OUTPUT_DIR
Flag Meaning
--ingest-dir A selected_vcf_ingest output directory. Repeat it for every file of the callset. Required.
--output-dir Where the merged variants are written. Required.
--failure-json The failure record.

It checks each ingest's manifest and Parquet files against their recorded sizes and digests, then writes canonical-variants.parquet, the distinct canonical variants in CANONICAL_ARROW_SCHEMA, and last manifest.json, an altar.callset-union-manifest version 1 document with the source digests and the counts (see File formats). Standard output is {"input_digest": ..., "unique_canonical_variants": ...}. A rerun on the same ingests returns the existing union.

altar.variants.annotation.annotate

altar.variants.annotation.annotate -v VARIANTS [-o OUTPUT] [-b BATCH_SIZE] [--data-dir DATA_DIR]
Flag Meaning Default
-v, --variants A headerless TSV of chr, pos, ref, alt and an optional variant_id. Required.
-o, --output The JSONL to write, one annotated variant per line. The input path with .tsv replaced by _annotated.jsonl.
-b, --batch-size The variants read and annotated at a time. 2000
--data-dir The directory of region_annotations.parquet, ccres.dnatree, region_provenance.json and variants.pkl.gz. $ALTAR_VARIANTS_DATA_DIR, then the installed package's data directory.
--failure-json The failure record. None.

Each JSONL line is an altar.variants.AnnotatedVariant: the alleles and variant_id, ref_length, alt_length, variant_length, variant_type, the region-annotation columns, in_ot and the af_* allele frequencies. The annotate command describes the fields. When the data directory records its provenance, the command writes <output>.identity.json after the last row: format (1), the region source's identity and identity_hash, its columns, the data's provenance and the row_count. It removes an earlier sidecar before it writes any row.

altar.variants.export.augmented_vcf

altar.variants.export.augmented_vcf --input-vcf INPUT_VCF --bucket-dir BUCKET_DIR --models-json MODELS_JSON
    --ingest-manifest INGEST_MANIFEST --output-vcf OUTPUT_VCF --output-manifest OUTPUT_MANIFEST
    --results-parquet-uri URI [options]
Flag Meaning Default
--input-vcf The VCF the ingest read. Its SHA-256 digest must be the manifest's input_sha256. Required.
--bucket-dir The occurrence buckets, bucket=<n>/part-*.parquet; see Occurrence buckets. Required.
--models-json The models whose scores are written: {"format": "altar.augmented-vcf-models", "version": 1, "models": [{"model_id", "name", "column_prefix"}], "score_fields": [...]}; see Write an augmented VCF. Required.
--ingest-manifest The ingest's manifest.json, an altar.ingest-manifest version 1 document. Required.
--output-vcf The augmented VCF, which must end in .vcf.gz. Its CSI index is written beside it as <output>.csi. Required.
--output-manifest The manifest of the output. Required.
--results-parquet-uri The results the buckets came from, recorded in the manifest as results_parquet.uri. Required.
--include-model-scores Add one ALTAR1_MODEL_SCORE entry per model, with the models JSON's score_fields. Off.
--annotation-fields-json The annotation INFO fields: {"format": "altar.augmented-vcf-annotation-fields", "version": 1, "include_defaults": ..., "fields": [...]}; see Choose the INFO fields. The default region and AlphaMissense fields.
--reference-fai The FASTA index (.fai) of the reference the VCF was ingested against. It gives the length of each contig the records use and the header does not declare. Required when the ingest sorted the VCF under altar-sort-v2. None.
--failure-json The failure record. None.

The output manifest is an altar.augmented-vcf-manifest version 2 document; File formats lists its keys. The VCF and its index are renamed into place before the manifest is written.

altar.variants.export.run_export

Provisional.

altar.variants.export.run_export --export-dir EXPORT_DIR --input-vcf INPUT_VCF --output-vcf OUTPUT_VCF [options]
Flag Meaning Default
--export-dir The Parquet export directory of an altar run. Required.
--input-vcf The VCF the run read as [variants] path. Required.
--output-vcf The augmented VCF, which must end in .vcf.gz. Required.
--reference-fasta The FASTA the run named as [variants] reference_fasta. With --ingest-dir, only its .fai is read. None; give it or --ingest-dir.
--ingest-dir An existing ingest of the VCF, with manifest.json and occurrences/. A new ingest in --work-dir.
--work-dir Where the ingest and buckets are kept. A temporary directory.
--output-manifest The manifest path. <output name>.manifest.json
--annotation-fields-json More INFO fields, after the sources' presets. None.
--genome-build The cohort's build, needed only when the export records none. The export's.
--bucket-records VCF records per bucket. 100000
--failure-json The failure record. None.

Standard output is a JSON summary: the output manifest, the sources_without_preset, and the occurrences counts. Write an augmented VCF shows a run.

File formats

Each JSON document these commands write or read names its kind and version in two keys, "format": "altar.<document>" and "version": <int>. A command reads only the format and version it knows: a document without them, or of another format or version, is refused with a message that names both. Every digest in these documents, and every digest a flag takes, is spelled sha256: followed by 64 lowercase hex digits; a bare hex digest is refused.

Document format version Written by Read by
Ingest manifest, manifest.json altar.ingest-manifest 1 pipeline, selected_vcf_ingest, run_export callset_union, augmented_vcf, run_export
Callset union manifest, manifest.json altar.callset-union-manifest 1 callset_union callset_union, to reuse an existing union
Models JSON, --models-json altar.augmented-vcf-models 1 the host; run_export augmented_vcf
Annotation fields JSON, --annotation-fields-json altar.augmented-vcf-annotation-fields 1 the host augmented_vcf, run_export
Augmented-VCF manifest, --output-manifest altar.augmented-vcf-manifest 2 augmented_vcf, run_export the host
Failure record, --failure-json altar.command-failure 1 every command the host

The ingest manifest's keys are listed under The ingest manifest. The others:

Callset union manifest. format, version; input_digest, the digest of the sorted sources as compact JSON; genome_build; selected_sample_count and selected_samples_sha256, which every ingest shares; ingest_manifest_count; canonical_input_rows, unique_canonical_variants and duplicate_canonical_rows; canonical_file, the uri, row_count, size_bytes and sha256 of canonical-variants.parquet; and sources, one {"input_sha256", "manifest_sha256"} per ingest, the digests of its input VCF and of its manifest's bytes.

Models JSON. format, version; models, a list of {"model_id", "name", "column_prefix"} with an optional short_id (M0001, M0002, ... by default); and an optional score_fields list.

Annotation fields JSON. format, version; include_defaults, required; and fields, each in the AnnotationInfoField.to_dict form. No other key is accepted.

Augmented-VCF manifest. format, version; bucket_schema_version, the occurrence-bucket format the writer read; source_input_sha256, the input VCF's digest; record_count and alt_occurrence_count; augmented_vcf and csi_index, each with uri, size_bytes and sha256; results_parquet.uri; include_model_scores; score_fields; annotation_fields, every declaration with its keys filled in; and models, as the writer read them.

The occurrence buckets are not a JSON document: a part of altar-augmentation-buckets-v2 has a model_scores column (see Occurrence buckets).