A robust, thread-safe Rust library for managing the lifecycle of biological ontologies.
ontology-registry automates the process of resolving, downloading, and caching ontology files (JSON, OBO, OWL). It
acts as a centralized local registry, ensuring that your applications always have access to the data they need without
redundant network requests or race conditions.
- 🚀 Smart Caching: Automatically downloads ontologies from the OBO Foundry and persists them locally. Subsequent requests load instantly from the disk.
- 🔄 Version Resolution: resolving
Version::Latestautomatically queries BioRegistry.io to find the most recent semantic version. - 🛡️ Thread-Safe & Atomic: Built for concurrency. It uses Mutex locks and atomic file writes (downloading to
.tmpfirst) to ensure you never read a corrupted or partially downloaded file. - 🔌 Modular Architecture: The logic is split into
MetadataProviding,OntologyProviding, andRegistrationtraits, allowing you to swap out backends if needed. - 📂 Multiple Formats: First-class support for
.json,.obo, and.owlformats.
Add this to your Cargo.toml:
cargo add ontology-registryuse ontology_registry::blocking::bio_registry_metadata_provider::BioRegistryMetadataProvider;
use ontology_registry::blocking::file_system_ontology_registry::FileSystemOntologyRegistry;
use ontology_registry::blocking::obolib_ontology_provider::OboLibraryProvider;
use ontology_registry::enums::{FileType, Version, SupportedOntology};
use ontology_registry::traits::OntologyRegistration;
use std::path::PathBuf;
use std::io::Read;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Setup the registry with standard providers
// In a real app, use a persistent path like "~/.cache/ontologies"
let cache_dir = PathBuf::from("./local_ontology_cache");
let registry = FileSystemOntologyRegistry::new(
cache_dir,
BioRegistryMetadataProvider::default(), // Resolves versions via BioRegistry.io
OboLibraryProvider::default(), // Downloads content from OBO Library
);
// 2. Register (Download & Cache)
// This resolves 'Latest' to a specific date (e.g., "2024-01-01")
let mut reader = registry.register(
SupportedOntology::MONDO, // This can also just be a string "mondo"
Version::Latest,
FileType::Obo
)?;
// 3. Read the content
let mut content = String::new();
reader.read_to_string(&mut content)?;
println!("Successfully loaded Mondo Ontology ({} bytes)", content.len());
Ok(())
}If you need reproducibility, you can request a specific version string.
use ontology_registry::enums::{FileType, Version};
use ontology_registry::blocking::file_system_ontology_registry::FileSystemOntologyRegistry;
use ontology_registry::traits::OntologyRegistration;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let registry = FileSystemOntologyRegistry::default();
let version = Version::Declared("2023-01-01".to_string());
let reader = registry.register(
"go",
version,
FileType::Owl
)?;
}| Enum Variant | Extension | Description |
|---|---|---|
FileType::Json |
.json |
OBO Graph JSON format |
FileType::Obo |
.obo |
Standard OBO flat file |
FileType::Owl |
.owl |
Web Ontology Language format |