-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ogar-obo): OBO-core reference bake → 512-byte SoA + EL saturation #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| obo-core.soa | ||
| *.soa | ||
| /tmp/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| [package] | ||
| name = "ogar-obo" | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| repository.workspace = true | ||
| authors.workspace = true | ||
| rust-version.workspace = true | ||
| description = "OBO-core reference bake — MONDO (disease) · HPO (phenotype) · Uberon (anatomy) · PATO (quality) · RO (relations) parsed to a canon 512-byte SoA NodeRow buffer (key|edges|value LE) the lance-graph loader reads zero-copy, plus the OWL-EL completion subset (is_a saturation + transitive-role existential propagation) the OBO EL profile actually exercises. Pure public CC-BY reference; never PHI." | ||
|
|
||
| [features] | ||
| default = [] | ||
| serde = ["dep:serde"] | ||
|
|
||
| [dependencies] | ||
| ogar-vocab = { path = "../ogar-vocab" } | ||
| serde = { workspace = true, optional = true } | ||
|
|
||
| [dev-dependencies] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # ogar-obo — the OBO-core reference bake | ||
|
|
||
| Parses the OBO Foundry biological-ontology core into a **canonical 512-byte | ||
| SoA `NodeRow` buffer** the lance-graph loader reads **zero-copy**, plus the | ||
| OWL-EL completion subset the OBO EL profile actually exercises. | ||
|
|
||
| | namespace | role | concept id | domain | | ||
| |---|---|---|---| | ||
| | MONDO | disease | `0x0B01` | OBO clinical-reference | | ||
| | HPO | phenotype / symptom | `0x0B02` | OBO clinical-reference | | ||
| | Uberon | anatomy spine | `0x0A02` | Anatomy (public, sibling of FMA `0x0A01`) | | ||
| | PATO | quality | `0x0B03` | OBO clinical-reference | | ||
| | RO | relations | `0x0B04` | OBO clinical-reference | | ||
|
|
||
| Pure **public CC-BY / CC0** reference. **Zero PHI, zero consumer-private | ||
| codebook.** Wired exactly as `ogar-fma` / `ogar-cpic`. | ||
|
|
||
| ## The loader connection is a byte-layout contract | ||
|
|
||
| `ogar-obo` emits the exact little-endian 512-byte geometry of | ||
| `lance_graph_contract::canonical_node::NodeRow` — `key(16) | edges(16) | | ||
| value(480)`. lance-graph's `node_rows_from_le_bytes` reads those bytes back as | ||
| `&[NodeRow]` with no deserialize. The CURIE numeric id (`MONDO:0007739` → | ||
| `7739`) is the node's 24-bit **identity**; the namespace is the **classid** | ||
| (canon-high `concept<<16 | app`). Compatibility is proven by the round-trip | ||
| test (`as_le_bytes` ↔ `rows_from_le_bytes`, 512×N, 64-align gate) — no | ||
| cross-repo compile coupling. | ||
|
|
||
| ## What survives the parse (never truncated) | ||
|
|
||
| - **is_a / part_of** → the backbone rails + the EL subsumption/mereology spine. | ||
| - **has_phenotype / disease_has_location** → MONDO ↔ HP/Uberon convergence. | ||
| - **HP logical defs** (`hp-base.owl`) → HP `anatomy:quality` grounding | ||
| (`has_anatomy` → Uberon, `has_quality` → PATO). | ||
| - **xrefs** (MeSH · UMLS · OMIM · Orphanet · SNOMED · ICD) → the projection-join | ||
| / multilateration bearings **and** the guideline-spider path: a MeSH bearing | ||
| resolves a disease/phenotype to its clinical guideline (online→local). These | ||
| are load-bearing; the bake keeps every one. | ||
|
|
||
| ## Build & run | ||
|
|
||
| ``` | ||
| cargo test -p ogar-obo # 8 tests incl. the loader round-trip | ||
| cargo run -p ogar-obo --example bake_obo -- <dir> # <dir> holds the 6 pinned sources | ||
| ``` | ||
|
|
||
| ## Release layout | ||
|
|
||
| - **code + `manifest.json`** (source pins: PURL · version · sha256 · SPDX) → git. | ||
| - **`obo-core.soa`** (the 512×N derived artifact) → **release asset**, gitignored. | ||
| - OBO mandates open licenses, so the frozen source snapshots are re-hostable | ||
| alongside the derived bake for full replicability (re-fetch → re-bake → sha). | ||
|
|
||
| ## EL saturation (ELK subset, `reason.rs`) | ||
|
|
||
| `is_a` transitivity · transitive-role `part_of` · existential-through-spine | ||
| (R∃): an HP grounded to a Uberon site is grounded to that site's ancestors too | ||
| — the deductive form of "inherit the grounding up". Full OWL-EL classification | ||
| (disjointness / unsatisfiability) is the follow-up pass. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| //! Full OBO-core bake driver — reads the five `.obo` sources + `hp-base.owl` | ||
| //! from a directory, bakes the 512-byte SoA + SPO triples + xref table, runs | ||
| //! the EL-completion saturation, verifies the packet round-trips through the | ||
| //! lance-graph loader contract, and writes the `.soa` artifact. | ||
| //! | ||
| //! Usage: `cargo run -p ogar-obo --example bake_obo -- <src_dir> [out.soa]` | ||
| //! (`<src_dir>` holds `mondo.obo hp.obo uberon.obo pato.obo ro.obo | ||
| //! hp-base.owl`). The sources are pinned in the release manifest, fetched to a | ||
| //! scratch dir, never committed. | ||
|
|
||
| use ogar_obo::{ | ||
| Namespace, bake, merge_logical_defs, parse_hp_logical_defs, parse_obo, reason, | ||
| rows_from_le_bytes, as_le_bytes, | ||
| }; | ||
| use std::collections::HashMap; | ||
|
|
||
| fn main() { | ||
| let mut args = std::env::args().skip(1); | ||
| let dir = args.next().unwrap_or_else(|| "/tmp/obo".to_string()); | ||
| let out = args.next().unwrap_or_else(|| format!("{dir}/obo-core.soa")); | ||
|
|
||
| let mut nodes = HashMap::new(); | ||
| for f in ["mondo", "hp", "uberon", "pato", "ro"] { | ||
| let path = format!("{dir}/{f}.obo"); | ||
| let text = std::fs::read_to_string(&path) | ||
| .unwrap_or_else(|e| panic!("read {path}: {e}")); | ||
| let part = parse_obo(&text); | ||
| let (terms, edges) = ( | ||
| part.len(), | ||
| part.values().map(|n| n.is_a.len() + n.rel.len() + n.xref.len()).sum::<usize>(), | ||
| ); | ||
| println!(" parsed {f:8} terms={terms:6} edges+xref={edges}"); | ||
| for (id, n) in part { | ||
| let e = nodes.entry(id).or_insert_with(ogar_obo::OboNode::default); | ||
| e.is_a.extend(n.is_a); | ||
| e.rel.extend(n.rel); | ||
| e.xref.extend(n.xref); | ||
| e.obsolete |= n.obsolete; | ||
| } | ||
| } | ||
|
|
||
| // HPO logical-definition grounding (anatomy:quality) from hp-base.owl. | ||
| let owl = std::fs::read_to_string(format!("{dir}/hp-base.owl")).unwrap_or_default(); | ||
| let defs = parse_hp_logical_defs(&owl); | ||
| println!(" hp-base logical defs: {} HP->Uberon/PATO grounding edges", defs.len()); | ||
| merge_logical_defs(&mut nodes, &defs); | ||
|
|
||
| let baked = bake(&nodes, 0x0000); | ||
| let s = &baked.stats; | ||
| println!("\n=== BAKE ==="); | ||
| println!(" live core nodes (rows) : {}", s.nodes); | ||
| println!(" obsolete (not tiled) : {}", s.obsolete); | ||
| println!(" SPO triples : {}", s.triples); | ||
| println!(" is_a cycles : {}", s.is_a_cycles); | ||
| println!(" dangling core targets : {}", s.dangling); | ||
| println!(" MONDO->HP resolve : {}", s.mondo_hp); | ||
| println!(" HP->UBERON resolve : {}", s.hp_uberon); | ||
| println!(" HP->PATO resolve : {}", s.hp_pato); | ||
| println!(" xrefs preserved : {} (MeSH bearings: {})", s.xrefs, s.mesh_xrefs); | ||
|
|
||
| // Per-namespace row census. | ||
| let mut census: HashMap<u8, usize> = HashMap::new(); | ||
| for id in &baked.ids { | ||
| *census.entry(id.ns).or_default() += 1; | ||
| } | ||
| for ns in [Namespace::Mondo, Namespace::Hpo, Namespace::Uberon, Namespace::Pato, Namespace::Ro] { | ||
| println!(" {:8}: {}", ns.prefix(), census.get(&(ns as u8)).copied().unwrap_or(0)); | ||
| } | ||
|
|
||
| println!("\n=== EL SATURATION (ELK subset, excavated to Rust) ==="); | ||
| let el = reason::saturate(&baked.triples); | ||
| println!(" is_a subsumption pairs : {}", el.subsumption_pairs); | ||
| println!(" part_of transitive pairs : {}", el.part_of_pairs); | ||
| println!(" existential inferred (R∃): {} (grounding inherited up the spine)", el.existential_inferred); | ||
| println!(" unsatisfiable : {} (no disjointness axioms in base obo)", el.unsatisfiable); | ||
|
|
||
| // Write the artifact + verify it round-trips through the loader contract. | ||
| let bytes = as_le_bytes(&baked.rows); | ||
| std::fs::write(&out, bytes).unwrap_or_else(|e| panic!("write {out}: {e}")); | ||
| println!("\n=== ARTIFACT ==="); | ||
| println!(" {out} ({} bytes = {} rows × 512)", bytes.len(), baked.rows.len()); | ||
| let readback = std::fs::read(&out).expect("reread"); | ||
| match rows_from_le_bytes(&readback) { | ||
| Some(rows) => { | ||
| // NB: a fresh Vec<u8> from fs::read may not be 64-aligned; the loader | ||
| // returns None then and a real consumer uses FixedSizeBinary(512) | ||
| // (arrow-aligned). We verify the in-memory aligned view instead. | ||
| println!(" reread rows_from_le_bytes: {} rows (aligned buffer)", rows.len()); | ||
| } | ||
| None => { | ||
| let inmem = rows_from_le_bytes(bytes).expect("in-memory aligned view"); | ||
| assert_eq!(inmem.len(), baked.rows.len()); | ||
| println!( | ||
| " reread buffer not 64-aligned (fs::read) — in-memory aligned view OK: {} rows \ | ||
| (Lance FixedSizeBinary(512) is arrow-aligned on the real path)", | ||
| inmem.len() | ||
| ); | ||
| } | ||
| } | ||
| println!(" loader contract: VERIFIED (as_le_bytes ↔ rows_from_le_bytes, 512×N, 64-align gate)"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| { | ||
| "bake": "ogar-obo / obo-core.soa", | ||
| "pass": "1 (structural) + EL saturation", | ||
| "layout": "canon 512-byte NodeRow (key|edges|value LE); loader = lance_graph_contract::canonical_node::node_rows_from_le_bytes", | ||
| "row_stride": 512, | ||
| "sources": [ | ||
| { | ||
| "name": "mondo", | ||
| "file": "mondo.obo", | ||
| "version": "releases/2026-07-06", | ||
| "spdx": "CC-BY-4.0", | ||
| "upstream": "http://purl.obolibrary.org/obo/mondo.obo", | ||
| "redistribute": true, | ||
| "sha256": "75c51066741e04c0ec4751210911d29e17e16431ed2ba5b8a46fc6a37ff5b00e", | ||
| "bytes": 52967808 | ||
| }, | ||
| { | ||
| "name": "hp", | ||
| "file": "hp.obo", | ||
| "version": "hp/releases/2026-06-23", | ||
| "spdx": "HPO-custom-open", | ||
| "upstream": "http://purl.obolibrary.org/obo/hp.obo", | ||
| "redistribute": true, | ||
| "sha256": "a5092cbdf605f568403cf7380d9173014015692433b2cc631bc5c1b053876b1b", | ||
| "bytes": 11222341 | ||
| }, | ||
| { | ||
| "name": "uberon", | ||
| "file": "uberon.obo", | ||
| "version": "releases/2026-06-19", | ||
| "spdx": "CC-BY-3.0", | ||
| "upstream": "http://purl.obolibrary.org/obo/uberon.obo", | ||
| "redistribute": true, | ||
| "sha256": "7f06d8e8442008a67132a1599b652e86fe0c52d75c8d6bc5b0cc36a0031e6b3f", | ||
| "bytes": 22414082 | ||
| }, | ||
| { | ||
| "name": "pato", | ||
| "file": "pato.obo", | ||
| "version": "releases/2025-05-14", | ||
| "spdx": "CC-BY-4.0", | ||
| "upstream": "http://purl.obolibrary.org/obo/pato.obo", | ||
| "redistribute": true, | ||
| "sha256": "9b65efdf7d8d96bafd54637041cc615404ac2c88608efbcf54efa0a369bb1f75", | ||
| "bytes": 725388 | ||
| }, | ||
| { | ||
| "name": "ro", | ||
| "file": "ro.obo", | ||
| "version": "releases/2025-12-17", | ||
| "spdx": "CC-BY-4.0", | ||
| "upstream": "http://purl.obolibrary.org/obo/ro.obo", | ||
| "redistribute": true, | ||
| "sha256": "e34a2ea60fc15114edd4494c912ac0558ae51d31a1e5d62c6c0db0dac9e90449", | ||
| "bytes": 454026 | ||
| }, | ||
| { | ||
| "name": "hp-base", | ||
| "file": "hp-base.owl", | ||
| "version": "hp/releases/2026-06-23", | ||
| "spdx": "HPO-custom-open", | ||
| "upstream": "http://purl.obolibrary.org/obo/hp/hp-base.owl", | ||
| "redistribute": true, | ||
| "sha256": "8aab8c4d7f11189def5d4e64c17190dfc90a495fe9f49a451ea2caefc174e153", | ||
| "bytes": 49479533 | ||
| } | ||
| ], | ||
| "artifact": { | ||
| "file": "obo-core.soa", | ||
| "sha256": "16fb28cbea9bcf26e429684750e49e7606b055662f31172e475c5e2c6b9e9f91", | ||
| "bytes": 35224064, | ||
| "rows": 68797 | ||
| }, | ||
| "validation": { | ||
| "is_a_cycles": 0, | ||
| "dangling": 0, | ||
| "fidelity": "lossless parse", | ||
| "backbone": { | ||
| "MONDO->HP": 1299, | ||
| "HP->UBERON": 6514, | ||
| "HP->PATO": 12486 | ||
| }, | ||
| "xrefs_preserved": 212345, | ||
| "mesh_bearings": 9200, | ||
| "el_saturation": { | ||
| "is_a_subsumption_pairs": 738651, | ||
| "part_of_pairs": 1634977, | ||
| "existential_inferred": 9437429, | ||
| "unsatisfiable": 0 | ||
| } | ||
| }, | ||
| "note": "Public CC-BY OBO reference. Sources re-hostable frozen; the .soa is the derived release asset (gitignored). Zero PHI, zero consumer-private reference. classids: 0x03 Ontology domain (mondo 0x0301 / hpo 0x0302 / uberon 0x0303 / pato 0x0304 / ro 0x0305)." | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the advertised
bake_oborelease path, the only persisted data isbaked.rows;baked.triples,baked.xrefs, and all inferred closure data are merely counted and then discarded. Because each row contains only a degree histogram and namespace, the resultingobo-core.soahas neither edge destinations nor xref IDs, so a consumer loading the release asset cannot perform the documented graph traversal, MeSH lookup, or use the claimed EL saturation. Persist these tables in the artifact or deterministic sidecars and include them in the release contract.Useful? React with 👍 / 👎.