{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kundajelab.github.io/altar/extend/schemas/altar-registry-1.schema.json",
  "$defs": {
    "Checksum": {
      "additionalProperties": false,
      "description": "A publisher's checksum of the bytes at a URI, such as the MD5 an archive's download page lists.",
      "properties": {
        "md5": {
          "pattern": "^[0-9a-f]{32}$",
          "type": "string"
        },
        "sha1": {
          "pattern": "^[0-9a-f]{40}$",
          "type": "string"
        },
        "sha256": {
          "pattern": "^[0-9a-f]{64}$",
          "type": "string"
        },
        "sha512": {
          "pattern": "^[0-9a-f]{128}$",
          "type": "string"
        }
      },
      "type": "object"
    },
    "Contig": {
      "additionalProperties": false,
      "description": "One contig of a FASTA: its name, the name a variant key gives it, its length and its refget digest.",
      "properties": {
        "name": {
          "minLength": 1,
          "type": "string"
        },
        "canonical": {
          "minLength": 1,
          "type": "string"
        },
        "length": {
          "exclusiveMinimum": 0,
          "type": "integer"
        },
        "digest": {
          "description": "The GA4GH refget sequence digest, SQ.<32>.",
          "pattern": "^SQ\\.[A-Za-z0-9_-]{32}$",
          "type": "string"
        }
      },
      "required": [
        "name",
        "canonical",
        "length",
        "digest"
      ],
      "type": "object"
    },
    "DigestOnly": {
      "additionalProperties": false,
      "description": "A file named by its digest alone, such as the genome a model's prepared files were made from.",
      "properties": {
        "digest": {
          "description": "sha256: and 64 lowercase hexadecimal digits.",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "type": "string"
        }
      },
      "required": [
        "digest"
      ],
      "type": "object"
    },
    "EntryConfiguration": {
      "additionalProperties": false,
      "description": "An Altar saved model configuration (`altar.model-configuration`), as a binding's `save_configuration` writes.\n\nEvery object in `configuration` that has a `uri` is a file reference, and may carry the fetch keys of a\n`FileReference` (`member`, `source_checksum`, `size_bytes`, `compression`), which the run removes\nbefore it gives the configuration to the binding.",
      "properties": {
        "format": {
          "const": "altar.model-configuration",
          "default": "altar.model-configuration",
          "type": "string"
        },
        "plugin_id": {
          "minLength": 1,
          "type": "string"
        },
        "plugin_version": {
          "minLength": 1,
          "type": "string"
        },
        "schema_id": {
          "minLength": 1,
          "type": "string"
        },
        "schema_version": {
          "minLength": 1,
          "type": "string"
        },
        "configuration": {
          "additionalProperties": true,
          "type": "object"
        }
      },
      "required": [
        "plugin_id",
        "schema_id",
        "schema_version",
        "configuration"
      ],
      "type": "object"
    },
    "Facets": {
      "additionalProperties": false,
      "description": "The metadata an index line repeats so `altar resources <registry> --where` filters without reading entries.",
      "properties": {
        "assay": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "cell_types": {
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/Term"
              },
              {
                "minLength": 1,
                "type": "string"
              }
            ]
          },
          "type": "array"
        },
        "organs": {
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/Term"
              },
              {
                "minLength": 1,
                "type": "string"
              }
            ]
          },
          "type": "array"
        },
        "systems": {
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/Term"
              },
              {
                "minLength": 1,
                "type": "string"
              }
            ]
          },
          "type": "array"
        },
        "life_stages": {
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/Term"
              },
              {
                "minLength": 1,
                "type": "string"
              }
            ]
          },
          "type": "array"
        },
        "sex": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "organism": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "project": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        }
      },
      "type": "object"
    },
    "FileReference": {
      "additionalProperties": false,
      "description": "One file an entry names: where it is published and the SHA-256 digest of the file Altar keeps.\n\nA direct copy is `{uri, digest}`: the bytes at `uri` are the file, or with `compression = \"gzip\"` a gzip\nstream of it. An archive member is `{uri, member, digest}`: `uri` is a tar, tar.gz or zip archive and\n`member` the path of the file inside it. `digest` is the file's digest in both forms, so identity does\nnot depend on the form. `source_checksum` is the publisher's checksum of the bytes at `uri` (the archive,\nor the compressed download), checked when the bytes arrive.",
      "properties": {
        "uri": {
          "description": "https://, gs://, s3://, hf://, or a path relative to the registry's index.",
          "type": "string"
        },
        "digest": {
          "description": "sha256: and 64 lowercase hexadecimal digits.",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "type": "string"
        },
        "revision": {
          "type": [
            "string",
            "null"
          ],
          "description": "A provider revision, as altar.models.ResourceReference holds it; identity reads the digest only."
        },
        "member": {
          "type": "string",
          "description": "A path inside the archive at uri."
        },
        "source_checksum": {
          "$ref": "#/$defs/Checksum",
          "description": "The publisher's checksum of the bytes at uri."
        },
        "size_bytes": {
          "minimum": 0,
          "type": "integer",
          "description": "The size of the file Altar keeps."
        },
        "compression": {
          "const": "gzip",
          "type": "string",
          "description": "The bytes at uri are a gzip stream of the file; not with member."
        }
      },
      "required": [
        "uri",
        "digest"
      ],
      "type": "object"
    },
    "Genome": {
      "additionalProperties": false,
      "description": "What a genome entry holds: its assembly, its FASTA, the FASTA's index, its contigs, and who publishes it.\n\n`contigs` lists every contig in FASTA order. `source` says who publishes the FASTA and what sets it apart.",
      "properties": {
        "genome_build": {
          "description": "The assembly, such as hg38 or mm10.",
          "minLength": 1,
          "type": "string"
        },
        "fasta": {
          "$ref": "#/$defs/FileReference"
        },
        "fai": {
          "$ref": "#/$defs/GenomeIndexReference"
        },
        "contigs": {
          "description": "Every contig of the FASTA, in order.",
          "items": {
            "$ref": "#/$defs/Contig"
          },
          "type": "array"
        },
        "collections": {
          "$ref": "#/$defs/SequenceCollections"
        },
        "source": {
          "$ref": "#/$defs/GenomeSource",
          "description": "Who publishes the FASTA, and what sets it apart."
        }
      },
      "required": [
        "genome_build",
        "fasta"
      ],
      "type": "object"
    },
    "GenomeIndexReference": {
      "additionalProperties": false,
      "description": "A FASTA's `.fai` index: its digest, and where it is published when it is.\n\nWithout `uri` Altar writes the index from the FASTA, which takes about a minute for a human genome, and checks\nit against `digest`.",
      "properties": {
        "digest": {
          "description": "sha256: and 64 lowercase hexadecimal digits.",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "type": "string"
        },
        "uri": {
          "type": "string"
        },
        "size_bytes": {
          "minimum": 0,
          "type": "integer"
        }
      },
      "required": [
        "digest"
      ],
      "type": "object"
    },
    "GenomeSource": {
      "additionalProperties": false,
      "description": "Who publishes a genome's FASTA, under what name, and what sets that file apart from others of its assembly.\n\n`authority` is the publisher; `accession` the assembly accession the publisher gives the file, such as\n`GCA_000001405.15`; `product` the publisher's own name for the file, such as `hg38` or `male.hg19`;\n`file_name` the name it publishes the file under, and `url` the page it describes it on. `description` is\none line on what makes the product differ from the others of its assembly.",
      "properties": {
        "authority": {
          "description": "NCBI, the UCSC Genome Browser, or the ENCODE portal.",
          "enum": [
            "NCBI",
            "UCSC",
            "ENCODE"
          ],
          "type": "string"
        },
        "accession": {
          "minLength": 1,
          "type": "string"
        },
        "product": {
          "minLength": 1,
          "type": "string"
        },
        "file_name": {
          "minLength": 1,
          "type": "string"
        },
        "url": {
          "type": "string",
          "description": "The publisher's page about the file: an https:// URL.",
          "pattern": "^https://"
        },
        "description": {
          "minLength": 1,
          "type": "string"
        }
      },
      "required": [
        "authority",
        "product",
        "description"
      ],
      "type": "object"
    },
    "IndexEntry": {
      "additionalProperties": false,
      "description": "One line of an index: what a listing shows and filters on, and where the entry document is.\n\n`entry` is the entry document's path relative to the index, ending in `sha256/<hex>.json`, where `<hex>`\nis the SHA-256 of the document's bytes. A packaged registry may give the document inline, as `document`,\ninstead; its digest is then taken over its canonical JSON (sorted keys, no spaces, UTF-8).",
      "else": {
        "properties": {
          "aliases": {
            "maxItems": 0
          }
        }
      },
      "if": {
        "properties": {
          "type": {
            "const": "GENOME"
          }
        }
      },
      "oneOf": [
        {
          "required": [
            "entry"
          ]
        },
        {
          "required": [
            "document"
          ]
        }
      ],
      "properties": {
        "id": {
          "description": "Segments of letters, digits, '.', '_' and '-' joined by single '/', none of them '.' or '..', such as grch38/ncbi/no-alt-analysis-set; matched ignoring case.",
          "maxLength": 128,
          "pattern": "^(?:[A-Za-z0-9_-]|\\.[A-Za-z0-9_-]|\\.\\.[A-Za-z0-9._-])[A-Za-z0-9._-]*(?:/(?:[A-Za-z0-9_-]|\\.[A-Za-z0-9_-]|\\.\\.[A-Za-z0-9._-])[A-Za-z0-9._-]*)*$",
          "type": "string"
        },
        "aliases": {
          "description": "Other names a GENOME entry is known by, such as hg38; each names it as its id does.",
          "items": {
            "description": "Segments of letters, digits, '.', '_' and '-' joined by single '/', none of them '.' or '..', such as grch38/ncbi/no-alt-analysis-set; matched ignoring case.",
            "maxLength": 128,
            "pattern": "^(?:[A-Za-z0-9_-]|\\.[A-Za-z0-9_-]|\\.\\.[A-Za-z0-9._-])[A-Za-z0-9._-]*(?:/(?:[A-Za-z0-9_-]|\\.[A-Za-z0-9_-]|\\.\\.[A-Za-z0-9._-])[A-Za-z0-9._-]*)*$",
            "type": "string"
          },
          "type": "array"
        },
        "name": {
          "minLength": 1,
          "type": "string"
        },
        "type": {
          "minLength": 1,
          "type": "string"
        },
        "plugin_id": {
          "type": "string",
          "description": "The binding's plugin id; absent for a GENOME entry."
        },
        "training_reference": {
          "$ref": "#/$defs/TrainingReference"
        },
        "size_bytes": {
          "minimum": 0,
          "type": "integer",
          "description": "The bytes the entry's files take once fetched."
        },
        "facets": {
          "$ref": "#/$defs/Facets"
        },
        "entry": {
          "pattern": "(?:^|/)sha256/[0-9a-f]{64}\\.json$",
          "type": "string",
          "description": "The entry document's path relative to the index, ending in sha256/<hex of its bytes>.json."
        },
        "document": {
          "$ref": "#/$defs/RegistryEntry",
          "description": "The entry document, inline."
        },
        "page": {
          "type": "string",
          "description": "A web page about the entry: an https:// URL.",
          "pattern": "^https://"
        }
      },
      "required": [
        "id",
        "name",
        "type"
      ],
      "type": "object"
    },
    "Metadata": {
      "additionalProperties": true,
      "description": "What an entry describes, in a host catalog's public vocabulary. Every key is optional; others may be added.\n\n`assay` is single; `cell_types`, `organs`, `systems` and `life_stages` are lists. A value is an\nontology term `{id, name}` or plain text.",
      "properties": {
        "assay": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "cell_types": {
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/Term"
              },
              {
                "minLength": 1,
                "type": "string"
              }
            ]
          },
          "type": "array"
        },
        "organs": {
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/Term"
              },
              {
                "minLength": 1,
                "type": "string"
              }
            ]
          },
          "type": "array"
        },
        "systems": {
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/Term"
              },
              {
                "minLength": 1,
                "type": "string"
              }
            ]
          },
          "type": "array"
        },
        "life_stages": {
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/Term"
              },
              {
                "minLength": 1,
                "type": "string"
              }
            ]
          },
          "type": "array"
        },
        "sex": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "biosample": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "treatment": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "organism": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "project": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        },
        "source": {
          "anyOf": [
            {
              "$ref": "#/$defs/Term"
            },
            {
              "minLength": 1,
              "type": "string"
            }
          ]
        }
      },
      "type": "object"
    },
    "PreparedFile": {
      "additionalProperties": false,
      "description": "A file the model's preparation step writes, published so a run need not prepare it.\n\n`path` is where `altar prepare` would publish it, relative to the model's directory,\n`models/<model key>/`.",
      "properties": {
        "path": {
          "type": "string"
        },
        "resource": {
          "$ref": "#/$defs/FileReference"
        }
      },
      "required": [
        "path",
        "resource"
      ],
      "type": "object"
    },
    "Reference": {
      "additionalProperties": false,
      "description": "The genome a model was trained on, and its prepared files made from: its assembly, and its files' digests.\n\n`genome` is the FASTA's digest and `genome_index` its `.fai`'s. A genome registry entry with the same\nFASTA digest names the same genome.",
      "properties": {
        "genome_build": {
          "minLength": 1,
          "type": "string"
        },
        "genome": {
          "$ref": "#/$defs/DigestOnly"
        },
        "genome_index": {
          "$ref": "#/$defs/DigestOnly"
        }
      },
      "required": [
        "genome_build",
        "genome"
      ],
      "type": "object"
    },
    "RegistryEntry": {
      "$id": "https://kundajelab.github.io/altar/extend/schemas/altar-registry-entry-1.schema.json",
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "additionalProperties": false,
      "description": "An entry document, `altar-registry-entry/1`: one model, or one genome, with every file it names.\n\nA model entry holds a saved `configuration`, and optionally the `prepared` files its preparation step\nwrites and the `reference` genome it was trained on. A genome entry (`type = \"GENOME\"`) holds `genome`\ninstead. Both may give a `license`, a `citation`, a web `page` about the entry, as its index line may,\n`metadata` and the `upstream` sources of their files.",
      "else": {
        "not": {
          "required": [
            "genome"
          ]
        },
        "required": [
          "configuration"
        ]
      },
      "if": {
        "properties": {
          "type": {
            "const": "GENOME"
          }
        }
      },
      "properties": {
        "format": {
          "const": "altar-registry-entry/1",
          "type": "string"
        },
        "id": {
          "description": "Segments of letters, digits, '.', '_' and '-' joined by single '/', none of them '.' or '..', such as grch38/ncbi/no-alt-analysis-set; matched ignoring case.",
          "maxLength": 128,
          "pattern": "^(?:[A-Za-z0-9_-]|\\.[A-Za-z0-9_-]|\\.\\.[A-Za-z0-9._-])[A-Za-z0-9._-]*(?:/(?:[A-Za-z0-9_-]|\\.[A-Za-z0-9_-]|\\.\\.[A-Za-z0-9._-])[A-Za-z0-9._-]*)*$",
          "type": "string"
        },
        "type": {
          "description": "The registered model type, such as LEGNET, or \"GENOME\".",
          "minLength": 1,
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "configuration": {
          "$ref": "#/$defs/EntryConfiguration"
        },
        "prepared": {
          "items": {
            "$ref": "#/$defs/PreparedFile"
          },
          "type": "array"
        },
        "reference": {
          "$ref": "#/$defs/Reference"
        },
        "genome": {
          "$ref": "#/$defs/Genome"
        },
        "license": {
          "type": "string"
        },
        "citation": {
          "type": "string"
        },
        "page": {
          "type": "string",
          "description": "A web page about the entry, as the index line's page: an https:// URL.",
          "pattern": "^https://"
        },
        "metadata": {
          "$ref": "#/$defs/Metadata"
        },
        "upstream": {
          "items": {
            "$ref": "#/$defs/Upstream"
          },
          "type": "array"
        }
      },
      "required": [
        "format",
        "id",
        "type"
      ],
      "then": {
        "not": {
          "anyOf": [
            {
              "required": [
                "configuration"
              ]
            },
            {
              "required": [
                "prepared"
              ]
            }
          ]
        },
        "required": [
          "genome"
        ]
      },
      "type": "object"
    },
    "SequenceCollections": {
      "additionalProperties": false,
      "description": "GA4GH sequence-collection level-0 digests of the FASTA's contigs and of their canonical names.",
      "properties": {
        "seqcol": {
          "pattern": "^[A-Za-z0-9_-]{32}$",
          "type": "string"
        },
        "canonical": {
          "pattern": "^[A-Za-z0-9_-]{32}$",
          "type": "string"
        }
      },
      "required": [
        "seqcol",
        "canonical"
      ],
      "type": "object"
    },
    "Term": {
      "additionalProperties": false,
      "description": "An ontology term: its identifier, such as `CL:0000236`, and its label.",
      "properties": {
        "id": {
          "minLength": 1,
          "type": "string"
        },
        "name": {
          "minLength": 1,
          "type": "string"
        }
      },
      "required": [
        "id",
        "name"
      ],
      "type": "object"
    },
    "TrainingReference": {
      "additionalProperties": false,
      "description": "An index line's summary of the genome an entry is on: its assembly and its FASTA's digest.",
      "properties": {
        "genome_build": {
          "minLength": 1,
          "type": "string"
        },
        "digest": {
          "description": "sha256: and 64 lowercase hexadecimal digits.",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "type": "string"
        }
      },
      "required": [
        "genome_build"
      ],
      "type": "object"
    },
    "Upstream": {
      "additionalProperties": false,
      "description": "Where an entry's files first came from, recorded for provenance; Altar never fetches it.",
      "properties": {
        "url": {
          "minLength": 1,
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "source_checksum": {
          "$ref": "#/$defs/Checksum"
        }
      },
      "required": [
        "url"
      ],
      "type": "object"
    }
  },
  "additionalProperties": false,
  "description": "An index, `altar-registry/1`: the registry's name and description, and one line per entry.",
  "properties": {
    "format": {
      "const": "altar-registry/1",
      "type": "string"
    },
    "name": {
      "description": "Letters, digits, '.', '_' and '-', starting and ending with a letter or digit; no '/'.",
      "pattern": "^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,62}[A-Za-z0-9])?$",
      "type": "string"
    },
    "description": {
      "default": "",
      "type": "string"
    },
    "entries": {
      "items": {
        "$ref": "#/$defs/IndexEntry"
      },
      "type": "array"
    }
  },
  "required": [
    "format",
    "name",
    "entries"
  ],
  "type": "object"
}
