https://schemas.wur.nl/betula/core/dna-alphabet/0.6.0/schema.json
IUPAC nucleotide codes for DNA: A/C/G/T plus the standard ambiguity codes (R,Y,S,W,K,M,B,D,H,V,N). Also allows ‘-’ and ‘.’ as alignment gap/missing-data characters, since a Sequence doubles as an alignment row. Case-insensitive (lowercase is the common convention for soft-masked regions in genome assemblies).
string (minLength 1, pattern ^[ACGTRYSWKMBDHVNacgtryswkmbdhvn.-]*$)
Valid examples¶
ambiguity-codes.json
"ACGTRYSWKMBDHVNacgtryswkmbdhvn.-"
Invalid examples¶
contains-u.json
"ACGU"
Schema source
dna-alphabet.schema.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://schemas.wur.nl/betula/core/dna-alphabet/0.6.0/schema.json",
"title": "DnaAlphabet",
"description": "IUPAC nucleotide codes for DNA: A/C/G/T plus the standard ambiguity codes (R,Y,S,W,K,M,B,D,H,V,N). Also allows '-' and '.' as alignment gap/missing-data characters, since a Sequence doubles as an alignment row. Case-insensitive (lowercase is the common convention for soft-masked regions in genome assemblies).",
"type": "string",
"minLength": 1,
"pattern": "^[ACGTRYSWKMBDHVNacgtryswkmbdhvn.-]*$"
}
Usage¶
Read a JSON document and parse it as a DnaAlphabet. CI runs this exact code against the first valid example above; see Getting started to install the bindings.
Python
TypeScript
Rust
dna-alphabet.py
from betula_schema import DnaAlphabet, parse_json
with open("dna-alphabet.json") as f:
dna_alphabet = parse_json(DnaAlphabet, f.read())
# DnaAlphabet is a RootModel; dna_alphabet.root is the plain value
print(dna_alphabet)
dna-alphabet.ts
import { readFileSync } from "node:fs";
import { parseJson, type DnaAlphabet } from "betula-schema";
const dnaAlphabet: DnaAlphabet = parseJson("DnaAlphabet", readFileSync("dna-alphabet.json", "utf8"));
console.log(dnaAlphabet);
dna-alphabet.rs
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = std::fs::read_to_string("dna-alphabet.json")?;
let dna_alphabet: betula_schema::DnaAlphabet = betula_schema::parse_str(&text)?;
// DnaAlphabet is a newtype; deref it (&*dna_alphabet) for the inner value
println!("{dna_alphabet:?}");
Ok(())
}