https://schemas.wur.nl/betula/distance-matrix/0.6.0/schema.json
A pairwise distance matrix, shared by react-bio-viz and acacia (via @holmrenser/nj’s DistanceResult). Squareness, symmetry, and a zero diagonal are semantic constraints, not checked structurally by this schema.
Field | Type | Required | Description |
|---|---|---|---|
|
| optional | Wire-format object-kind discriminator (see betula’s versioning policy). Optional. |
| array of Identifier | required | |
| array of array of | required | |
| object of | optional | Optional display-name lookup from label to a longer/human-readable name. |
No properties beyond those listed are allowed.
Valid examples¶
{
"type": "distance-matrix",
"labels": ["A", "B", "C"],
"matrix": [
[0, 0.1, 0.3],
[0.1, 0, 0.25],
[0.3, 0.25, 0]
]
}
Invalid examples¶
{
"labels": ["A", "B", "C"]
}
{
"labels": ["A", "B"],
"matrix": [
[0, -0.1],
[-0.1, 0]
]
}
{
"type": "tree",
"labels": ["A", "B"],
"matrix": [
[0, 0.1],
[0.1, 0]
]
}
Schema source
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://schemas.wur.nl/betula/distance-matrix/0.6.0/schema.json",
"title": "DistanceMatrix",
"description": "A pairwise distance matrix, shared by react-bio-viz and acacia (via @holmrenser/nj's DistanceResult). Squareness, symmetry, and a zero diagonal are semantic constraints, not checked structurally by this schema.",
"type": "object",
"properties": {
"type": {
"const": "distance-matrix",
"description": "Wire-format object-kind discriminator (see betula's versioning policy). Optional."
},
"labels": {
"type": "array",
"items": { "$ref": "https://schemas.wur.nl/betula/core/identifier/0.6.0/schema.json" },
"minItems": 1
},
"matrix": {
"type": "array",
"items": {
"type": "array",
"items": { "type": "number", "minimum": 0 }
}
},
"labelNames": {
"type": "object",
"description": "Optional display-name lookup from label to a longer/human-readable name.",
"additionalProperties": { "type": "string" }
}
},
"required": ["labels", "matrix"],
"additionalProperties": false
}
Usage¶
Read a JSON document and parse it as a DistanceMatrix. CI runs this exact code against the first valid example above; see Getting started to install the bindings.
from betula_schema import DistanceMatrix, parse_json
with open("distance-matrix.json") as f:
distance_matrix = parse_json(DistanceMatrix, f.read())
print(distance_matrix)
import { readFileSync } from "node:fs";
import { parseJson, type DistanceMatrix } from "betula-schema";
const distanceMatrix: DistanceMatrix = parseJson("DistanceMatrix", readFileSync("distance-matrix.json", "utf8"));
console.log(distanceMatrix);
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = std::fs::read_to_string("distance-matrix.json")?;
let distance_matrix: betula_schema::DistanceMatrix = betula_schema::parse_str(&text)?;
println!("{distance_matrix:?}");
Ok(())
}