{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "science-rnaseq-proposal-v1 parsed output bundle",
  "description": "Research design. TSV rows are parsed according to serialization-contract.md. Cross-row invariants and scientific tolerances are not implemented by this schema.",
  "type": "object",
  "additionalProperties": false,
  "required": ["sample_qc", "gene_stats", "summary"],
  "properties": {
    "sample_qc": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/sample"}},
    "gene_stats": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/gene"}},
    "summary": {"$ref": "#/$defs/summary"}
  },
  "$defs": {
    "hash": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
    "count": {"type": "integer", "minimum": 0},
    "sample": {
      "type": "object", "additionalProperties": false,
      "required": ["sample_id", "donor_id", "condition", "library_assigned_counts", "detected_genes", "normalization_factor"],
      "properties": {
        "sample_id": {"type": "string", "minLength": 1},
        "donor_id": {"type": "string", "minLength": 1},
        "condition": {"enum": ["Dex", "untreated"]},
        "library_assigned_counts": {"type": "integer", "minimum": 1},
        "detected_genes": {"type": "integer", "minimum": 1},
        "normalization_factor": {"type": "number", "exclusiveMinimum": 0}
      }
    },
    "gene": {
      "type": "object", "additionalProperties": false,
      "required": ["gene_id", "log2_fc", "lfc_se", "pvalue", "padj", "status", "direction", "significant"],
      "properties": {
        "gene_id": {"type": "string", "minLength": 1},
        "log2_fc": {"type": ["number", "null"]},
        "lfc_se": {"type": ["number", "null"], "minimum": 0},
        "pvalue": {"type": ["number", "null"], "minimum": 0, "maximum": 1},
        "padj": {"type": ["number", "null"], "minimum": 0, "maximum": 1},
        "status": {"enum": ["tested", "filtered", "all_zero", "not_estimable"]},
        "direction": {"enum": ["increase", "decrease", "zero", "not_estimable"]},
        "significant": {"type": "boolean"}
      },
      "allOf": [
        {
          "if": {"properties": {"status": {"const": "tested"}}},
          "then": {"properties": {"log2_fc": {"type": "number"}, "pvalue": {"type": "number"}, "padj": {"type": "number"}, "direction": {"enum": ["increase", "decrease", "zero"]}}},
          "else": {"properties": {"log2_fc": {"type": "null"}, "lfc_se": {"type": "null"}, "pvalue": {"type": "null"}, "padj": {"type": "null"}, "direction": {"const": "not_estimable"}, "significant": {"const": false}}}
        }
      ]
    },
    "summary": {
      "type": "object", "additionalProperties": false,
      "required": ["contract_version", "fixture_sha256", "method", "method_version", "design", "contrast", "fdr_threshold", "adjustment", "counts", "artifact_sha256"],
      "properties": {
        "contract_version": {"const": "science-rnaseq-proposal-v1"},
        "fixture_sha256": {"$ref": "#/$defs/hash"},
        "method": {"type": "string", "minLength": 1, "description": "Allowed method identifiers must be frozen after reference calibration."},
        "method_version": {"type": "string", "minLength": 1},
        "design": {"const": "~ donor + condition"},
        "contrast": {"type": "object", "additionalProperties": false, "required": ["numerator", "denominator"], "properties": {"numerator": {"const": "Dex"}, "denominator": {"const": "untreated"}}},
        "fdr_threshold": {"const": 0.05},
        "adjustment": {"const": "BH"},
        "counts": {
          "type": "object", "additionalProperties": false,
          "required": ["samples", "genes_input", "genes_tested", "genes_filtered", "genes_all_zero", "genes_not_estimable", "genes_significant"],
          "properties": {
            "samples": {"$ref": "#/$defs/count"}, "genes_input": {"$ref": "#/$defs/count"},
            "genes_tested": {"$ref": "#/$defs/count"}, "genes_filtered": {"$ref": "#/$defs/count"},
            "genes_all_zero": {"$ref": "#/$defs/count"}, "genes_not_estimable": {"$ref": "#/$defs/count"},
            "genes_significant": {"$ref": "#/$defs/count"}
          }
        },
        "artifact_sha256": {
          "type": "object", "additionalProperties": false, "required": ["sample_qc.tsv", "gene_stats.tsv"],
          "properties": {"sample_qc.tsv": {"$ref": "#/$defs/hash"}, "gene_stats.tsv": {"$ref": "#/$defs/hash"}}
        }
      }
    }
  }
}
