#ontology #phenotype #bioinformatics

phenopackets

Rust bindings for Phenopacket Schema

1 unstable release

0.2.2-post0 Mar 17, 2025

#305 in Biology

Download history 75/week @ 2025-03-12 30/week @ 2025-03-19

105 downloads per month

Custom license

135KB
2K SLoC

Continuous Integration Documentation Crate

Rust bindings for Phenopacket Schema

See the documentation on docs.rs for usage examples and more info.


lib.rs:

Rust bindings for Phenopacket Schema.

The crate contains Rust structs and enums generated from Phenopacket Schema protobuf descriptors. Phenopacket Schema versions v1 and v2 are supported.

Examples

Create a Phenopacket Schema element programmatically

Any struct or enum of the schema can be created by invoking its initializer. For instance, an schema::v2::core::OntologyClass:

use phenopackets::schema::v2::core::OntologyClass;

let seizure = OntologyClass {
  id: "HP:0001250".into(),
  label: "Seizure".into(),
};

assert_eq!(&seizure.id, "HP:0001250");
assert_eq!(&seizure.label, "Seizure");

Encode/decode into protobuf binary format

The schema elements can be encoded into or decoded from bytes:

use phenopackets::schema::v2::core::OntologyClass;
use prost::Message;

let seizure = OntologyClass {
  id: "HP:0001250".into(),
  label: "Seizure".into(),
};

// Dump to bytes ...
let bytes: Vec<u8> = seizure.encode_to_vec();

// ... and read back.
let other = OntologyClass::decode(&bytes[..]).unwrap();

assert_eq!(seizure, other);

Note, only the protobuf binary format is implemented (no JSON, YAML, ...).

Dependencies

~0.4–2.2MB
~32K SLoC