{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "$id": "https://nextstrain.org/schemas/dataset/v1/tree",
    "type": "object",
    "title": "Nextstrain tree JSON schema",
    "additionalProperties": false,
    "required": ["attr", "strain"],
    "properties": {
        "attr": {
            "description": "Attributes / decorations on the nodes",
            "type": "object",
            "additionalProperties": true,
            "required": ["div", "num_date"],
            "properties": {
                "div": {
                    "description": "Node (phylogenetic) divergence",
                    "$comment": "Cumulative (root = 0)",
                    "type": "number"
                },
                "num_date": {
                    "description": "Node date",
                    "$comment": "Year in decimal format",
                    "type": "number"
                },
                "num_date_confidence": {
                    "description": "Confidence of the node date",
                    "type": "array",
                    "items": [
                        {"type": "number"},
                        {"type": "number"}
                    ]
                },
                "date": {
                    "description": "Node date",
                    "$comment": "Is this used? Should only use this or num_date",
                    "type": "string",
                    "pattern": "^[0-9X]{4}-[0-9X]{2}-[0-9X]{2}$"
                },
                "clock_length": {
                    "$comment": "DEPRECATED. Not used in auspice.",
                    "type": "number"
                },
                "mutation_length": {
                    "$comment": "DEPRECATED. Not used in auspice.",
                    "type": "number"
                },
                "branch_length": {
                    "$comment": "DEPRECATED. Not used in auspice.",
                    "type": "number"
                },
                "url": {
                    "description": "URL of the sequence (usually https://www.ncbi.nlm.nih.gov/nuccore/...)",
                    "type": ["null", "string"]
                },
                "accession": {
                    "description": "Genome accession",
                    "oneOf": [
                        {
                            "type": "string",
                            "pattern": "^[0-9A-Za-z-]+$"
                        },
                        {
                            "type": "null"
                        }
                    ]
                },
                "authors": {
                    "description": "Author lookup key for the relevant publication / credit",
                    "$comment": "Should have a corresponding entry in the meta JSON author_info property",
                    "type": ["null", "string"]
                }
            },
            "patternProperties": {
                "^.*_confidence$": {
                    "description": "confidence values for trait",
                    "$comment": "The trait must exist. This cannot be checked for in the JSON schema AFAIK",
                    "oneOf": [
                        {
                            "description": "",
                            "type": "object",
                            "patternProperties": {
                                "^.+$": {
                                    "type": "number"
                                }
                            }
                        },
                        {
                            "description": "",
                            "type": "array",
                            "items": [
                                {"type": "number"},
                                {"type": "number"}
                            ]
                        }
                    ]
                },
                "^.*_entropy$": {
                    "description": "",
                    "type": "number"
                }
            }
        },
        "branch_length": {
            "$comment": "DEPRECATED. Not used in auspice.",
            "type": "number"
        },
        "strain": {
            "description": "Strain name. Must be unique",
            "type": "string"
        },
        "clade": {
            "description": "Will be removed in schema 2.0",
            "type": ["number"]
        },
        "tvalue": {
            "$comment": "DEPRECATED. Not used in auspice.",
            "type": ["null", "number"]
        },
        "yvalue": {
            "$comment": "DEPRECATED. Not used in auspice.",
            "type": ["null", "number"]
        },
        "xvalue": {
            "$comment": "DEPRECATED. Not used in auspice.",
            "type": ["null", "number"]
        },
        "serum": {
            "description": "to do",
            "$comment": "Used in dengue & flu trees",
            "type": "boolean"
        },
        "muts": {
            "description": "Nucleotide mutations occuring between the parent and this node",
            "$comment": "same numbering scheme as used by the meta.JSON -> annotations",
            "type": "array",
            "items": {
              "oneOf": [
                {"type": "string", "pattern": "^[ATCGNYRWSKMDVHB-][0-9]+[ATCGNYRWSKMDVHB-]$"},
                {"type": "string", "pattern": "^insertion [0-9]+-[0-9]+$", "$comment": "unused by auspice"},
                {"type": "string", "pattern": "^deletion [0-9]+-[0-9]+$", "$comment": "unused by auspice"}
              ]
            }
        },
        "aa_muts": {
            "description": "Amino-acid mutations (for each gene) occuring between the parent and this node",
            "$comment": "properties (keys) must exist in the meta.JSON -> annotation object, and cannot be \"nuc\"",
            "type": "object",
            "additionalProperties": false,
            "patternProperties": {
                "^[a-zA-Z0-9*_-]+$": {
                    "description": "Mutations for this gene (or annotated region)",
                    "type": "array",
                    "items": {
                      "pattern": "^[A-Z*][0-9]+[A-Z*]$"
                    }
                }
            }
        },
        "children": {
            "description": "Child nodes. Recursive structure. Terminal nodes do not have this property.",
            "$comment": "Polytomies (more than 2 items) allowed.",
            "type": "array",
            "minItems": 2,
            "items": {"$ref": "#"}
        }
    }
}
