Quickstart
Welcome to the OntoGraph Quickstart!
This guide will help you get up and running with OntoGraph, showing you how to explore ontology catalogs and interact with ontologies programmatically.
1. Explore the OBO Foundry Catalog
First, let's interact with the OBO Foundry catalog to discover available ontologies.
from ontograph.client import ClientCatalog
from ontograph.downloader import DownloadManagerAdapter
from ontograph.config.settings import DEFAULT_CACHE_DIR
# Create a catalog client (specify a cache directory for downloads)
client_catalog = ClientCatalog(cache_dir="./data/out")
# Load the catalog (downloads if not cached)
client_catalog.load_catalog()
# Optional: choose downloader via string or adapter (client-level only)
# client_catalog = ClientCatalog(cache_dir="./data/out", downloader="download_manager")
# downloader = DownloadManagerAdapter(cache_dir=DEFAULT_CACHE_DIR, backend="requests")
# client_catalog = ClientCatalog(cache_dir="./data/out", downloader=downloader)
List Available Ontologies
# Get a list of ontologies (as dicts with id and title)
ontologies_list = client_catalog.list_available_ontologies()
print(ontologies_list[:3]) # Show the first three
Print Ontology List
Get Metadata for a Specific Ontology
# Show metadata for the Gene Ontology (GO)
metadata_go = client_catalog.get_ontology_metadata(ontology_id="go", show_metadata=True)
2. Load and Explore an Ontology
Now, let's load an ontology and explore its structure.
from ontograph.client import ClientOntology
from ontograph.downloader import DownloadManagerAdapter
from ontograph.config.settings import DEFAULT_CACHE_DIR
# Create an ontology client
client_ontology = ClientOntology(cache_dir="./data/out")
# Load a sample ontology (provided in the repo for testing)
client_ontology.load(source="./tests/resources/dummy_ontology.obo")
# Optional: choose downloader via string or adapter (client-level only)
# client_ontology = ClientOntology(cache_dir="./data/out", downloader="pooch")
# downloader = DownloadManagerAdapter(cache_dir=DEFAULT_CACHE_DIR, backend="requests")
# client_ontology = ClientOntology(cache_dir="./data/out", downloader=downloader)
3. Visualize the Ontology Structure
The included demo ontology has the following structure (Z is the root):
graph TB
Z((Z)) --> A((A))
Z((Z)) --> B((B))
Z((Z)) --> C((C))
A((A)) --> D((D))
B((B)) --> H((H))
B((B)) --> I((I))
C((C)) --> J((J))
D((D)) --> E((E))
D((D)) --> F((F))
D((D)) --> G((G))
H((H)) --> K((K))
I((I)) --> L((L))
J((J)) --> M((M))
E((E)) --> N((N))
F((F)) --> O((O))
F((F)) --> Y((Y))
G((G)) --> K1((K1))
G((G)) --> K2((K2))
K((K)) --> Q((Q))
K((K)) --> G1((G))
M((M)) --> S((S))
G1((G)) --> K11((K1))
G1((G)) --> K21((K2))
S((S)) --> T((T))
T((T)) --> U((U))
U((T)) --> V((V))
U((U)) --> W((W))
W((W)) --> Y1((Y))
4. Common Ontology Queries
Navigation
- Get ancestors:
- Ancestors with distance:
- Get children:
- Get descendants:
- Descendants with distance:
- Get parents:
- Get root node:
- Get siblings:
- Get a term:
Relations
- Common ancestors:
- Lowest common ancestors:
- Is ancestor:
- Is descendant:
- Is sibling:
Introspection
- Distance from root:
- Path between nodes:
- All trajectories from root:
- Print trajectories tree:
Next Steps
- Explore the API Reference for more details.
- Try loading your own ontology files or experiment with different queries!
_OntoGraph makes ontology exploration and analysis simple and powerful.