Skip to main content

Explainable, OMOP-native knowledge graph traversal and pathfinding

Project description

omop-graph

omop-graph is a lightweight, opinionated knowledge-graph traversal and path-analysis library built on top of the OMOP vocabulary model.

It provides:

  • a stable KnowledgeGraph façade over OMOP concepts and relationships
  • flexible graph traversal (forward, backward, bidirectional)
  • path discovery with transparent scoring
  • traceable explanations of traversal decisions
  • multiple rendering backends (text, HTML, Mermaid)

The library is designed for:

  • interactive analysis (Jupyter)
  • reproducible research
  • downstream tooling (NLP pipelines, ontology alignment, curation tools)

Installation

pip install omop-graph

With embedding support (sqlite-vec backend, zero config):

pip install "omop-graph[emb]"

For larger deployments use [pgvector] or [faiss-cpu] instead (or in addition). Full setup is covered in the omop-emb documentation.


Core Concepts

KnowledgeGraph

KnowledgeGraph is the main entry point. It wraps a SQLAlchemy Engine connected to an OMOP vocabulary schema and provides a high-level Pythonic API over the relational tables.

from sqlalchemy import create_engine
from omop_graph.graph.kg import KnowledgeGraph

engine = create_engine("postgresql://user:pass@localhost/omop")
kg = KnowledgeGraph(engine)

# Lookup a concept by label
match_group = kg.label_lookup("Atrial Fibrillation", fuzzy=False)
concept = match_group.best_match
print(f"ID: {concept.concept_id}, Name: {concept.matched_label}")

# Traverse the hierarchy
parents = kg.parents(concept.concept_id)

Nodes and Edges

Nodes are OMOP Concepts; Edges are OMOP Concept_Relationships.

Relationships are pre-classified into semantic kinds (PredicateKind):

  • HIERARCHY — parent/child ontological relationships
  • IDENTITY — mapping to standard concepts
  • COMPOSITION — part-of relationships
  • ASSOCIATION — lateral clinical associations
  • ATTRIBUTE — concept attribute relationships

This classification drives traversal filtering and scoring.

Traversal and Paths

from omop_graph.graph.paths import find_shortest_paths
from omop_graph.extensions.omop_alchemy import PredicateKind

ingredient = kg.concept_id_by_code("RxNorm", "6809")    # Metformin
drug = kg.concept_id_by_code("RxNorm", "860975")         # Metformin 500 MG Oral Tablet

paths, trace = find_shortest_paths(
    kg,
    source=drug,
    target=ingredient,
    predicate_kinds=frozenset({PredicateKind.HIERARCHY, PredicateKind.IDENTITY}),
    max_depth=6,
    traced=True,
)

Rendering

Outputs can be rendered as plain text, HTML (Jupyter), or Mermaid diagrams. Rendering auto-detects the environment.

from IPython.display import HTML, display
from omop_graph.render import render_trace

display(HTML(render_trace(kg, trace)))

Project Structure

omop_graph/
├── graph/          # graph logic, traversal, paths, scoring
├── render/         # HTML / text / Mermaid renderers
├── reasoning/      # ontology traversal methods for specific reasoner tasks
│   ├── resolvers/  # resolve labels via exact / fuzzy / full-text / synonym search
│   └── phenotypes/ # set operations for hierarchical groupings
├── oaklib_interface/  # OAK-compliant adapter
├── api.py          # stable public API surface
└── db/             # session helpers

Configuration

omop-graph reads database connection settings from oa-configurator. It requires the CDM database configured by omop-alchemy.

Run once after installation:

omop-config init
omop-config configure omop_alchemy
omop-config configure omop_graph

See Configuration for full details.


Docker Compose

The included docker-compose.yaml provides a PostgreSQL CDM database and a Python container with all optional backends pre-installed ([postgres,emb,pgvector,faiss-cpu]). Default credentials work out of the box:

docker compose up

The python-graph service runs omop-config configure at startup. To override credentials:

cp .env.example .env
docker compose up

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

omop_graph-1.2.0.tar.gz (430.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

omop_graph-1.2.0-py3-none-any.whl (78.5 kB view details)

Uploaded Python 3

File details

Details for the file omop_graph-1.2.0.tar.gz.

File metadata

  • Download URL: omop_graph-1.2.0.tar.gz
  • Upload date:
  • Size: 430.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for omop_graph-1.2.0.tar.gz
Algorithm Hash digest
SHA256 39e8e1cb38ba63f943d4b1ac63cc12a44a9965f5afe3eae26121014e30bb2786
MD5 67ea149465eba5b8c28b6ca9c3e190a4
BLAKE2b-256 23118ec63fafa26057e412992b5ca42bcc7caa17c824bf219b492b774f3f1340

See more details on using hashes here.

Provenance

The following attestation bundles were made for omop_graph-1.2.0.tar.gz:

Publisher: python-publish.yml on AustralianCancerDataNetwork/omop-graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file omop_graph-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: omop_graph-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 78.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for omop_graph-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f96346576875b9767f8d0c4537afb2a2aa483e3ebf519e0c84b610a05f70b1f
MD5 cf0b120dbf2debfe4b75f598653b57e0
BLAKE2b-256 1ab9ebcc4e818ceac2ae8ed8ca8c91fcd625dfa9219c5b1f7fbc378fb5c3cffd

See more details on using hashes here.

Provenance

The following attestation bundles were made for omop_graph-1.2.0-py3-none-any.whl:

Publisher: python-publish.yml on AustralianCancerDataNetwork/omop-graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page