Skip to content

Commit a52cf9c

Browse files
chores: update notebook to include demo showing how to interact with the client
1 parent 304bfab commit a52cf9c

2 files changed

Lines changed: 121 additions & 9665 deletions

File tree

notebooks/quickstart_demo.ipynb

Lines changed: 121 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"# 1. Standard library imports\n",
130130
"import sys\n",
131131
"\n",
132-
"sys.path.append('/home/ecarreno/SSC-Projects/b_REPOSITORIES/ontograph')\n",
132+
"sys.path.append(\"/home/ecarreno/SSC-Projects/b_REPOSITORIES/ontograph\")\n",
133133
"\n",
134134
"from pathlib import Path\n",
135135
"\n",
@@ -167,7 +167,7 @@
167167
"metadata": {},
168168
"outputs": [],
169169
"source": [
170-
"cache_dir = Path('../data/out')"
170+
"cache_dir = Path(\"../data/out\")"
171171
]
172172
},
173173
{
@@ -266,7 +266,7 @@
266266
"source": [
267267
"# This function looks if the given ontology has a link with a given extension\n",
268268
"\n",
269-
"print('Link: {}'.format(onto_registry.get_download_url('chebi', 'obo')))"
269+
"print(\"Link: {}\".format(onto_registry.get_download_url(\"chebi\", \"obo\")))"
270270
]
271271
},
272272
{
@@ -282,7 +282,7 @@
282282
"metadata": {},
283283
"outputs": [],
284284
"source": [
285-
"print(onto_registry.get_available_formats(ontology_id='chebi'))"
285+
"print(onto_registry.get_available_formats(ontology_id=\"chebi\"))"
286286
]
287287
},
288288
{
@@ -326,18 +326,18 @@
326326
"source": [
327327
"# Put the ontologies and their formats as a dictionary\n",
328328
"resources = [\n",
329-
" {'name_id': 'chebi', 'format': 'owl'},\n",
330-
" {'name_id': 'go', 'format': 'obo'},\n",
331-
" {'name_id': 'ado', 'format': 'owl'},\n",
329+
" {\"name_id\": \"chebi\", \"format\": \"owl\"},\n",
330+
" {\"name_id\": \"go\", \"format\": \"obo\"},\n",
331+
" {\"name_id\": \"ado\", \"format\": \"owl\"},\n",
332332
"]\n",
333333
"\n",
334334
"# Use the downloader, it has a cache in case you have already downloaded the ontologies.\n",
335335
"batch_results = downloader.fetch_batch(resources)\n",
336336
"\n",
337337
"# Print all the paths where your ontologies are located\n",
338-
"print('Ontologies in cache:')\n",
338+
"print(\"Ontologies in cache:\")\n",
339339
"for ontology_name, ontology_path in batch_results.items():\n",
340-
" print(f'\\t{ontology_name}: {ontology_path}')"
340+
" print(f\"\\t{ontology_name}: {ontology_path}\")"
341341
]
342342
},
343343
{
@@ -376,13 +376,13 @@
376376
"metadata": {},
377377
"outputs": [],
378378
"source": [
379-
"name_id_go = 'go'\n",
380-
"format_go = 'obo'\n",
379+
"name_id_go = \"go\"\n",
380+
"format_go = \"obo\"\n",
381381
"\n",
382382
"gene_ontology = ontology_loader.load(name_id=name_id_go, format=format_go)\n",
383383
"\n",
384-
"print(f'Loaded ontology: {name_id_go}.{format_go}')\n",
385-
"print(f'Number of terms: {len(gene_ontology.terms())}')"
384+
"print(f\"Loaded ontology: {name_id_go}.{format_go}\")\n",
385+
"print(f\"Number of terms: {len(gene_ontology.terms())}\")"
386386
]
387387
},
388388
{
@@ -400,7 +400,7 @@
400400
"source": [
401401
"# term_id = \"GO:0008150\" # biological_process\n",
402402
"# term_id = \"GO:0160266\" # anestrus phase\n",
403-
"term_id = 'GO:0070360' # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host"
403+
"term_id = \"GO:0070360\" # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host"
404404
]
405405
},
406406
{
@@ -412,34 +412,135 @@
412412
"queries = OntologyQueries(gene_ontology)\n",
413413
"\n",
414414
"# Print term relations\n",
415-
"print(f'Term: {term_id}')\n",
416-
"print(f' Parents : {queries.ancestors(term_id)}')\n",
417-
"print(f' Children : {queries.descendants(term_id)}')\n",
415+
"print(f\"Term: {term_id}\")\n",
416+
"print(f\" Parents : {queries.ancestors(term_id)}\")\n",
417+
"print(f\" Children : {queries.descendants(term_id)}\")\n",
418418
"\n",
419419
"\n",
420420
"# print(f\" Ancestors : {queries.ancestors(term_id)}\")\n",
421421
"# print(f\" Descendants : {queries.descendants(term_id)}\")"
422422
]
423423
},
424+
{
425+
"cell_type": "markdown",
426+
"metadata": {},
427+
"source": [
428+
"## Step 5. Client"
429+
]
430+
},
431+
{
432+
"cell_type": "markdown",
433+
"metadata": {},
434+
"source": [
435+
"### Import the library"
436+
]
437+
},
424438
{
425439
"cell_type": "code",
426440
"execution_count": null,
427441
"metadata": {},
428442
"outputs": [],
429-
"source": []
443+
"source": [
444+
"import ontograph as op"
445+
]
446+
},
447+
{
448+
"cell_type": "markdown",
449+
"metadata": {},
450+
"source": [
451+
"### Interact with the registry"
452+
]
430453
},
431454
{
432455
"cell_type": "code",
433456
"execution_count": null,
434457
"metadata": {},
435458
"outputs": [],
436-
"source": []
459+
"source": [
460+
"# Load the ontogragh catalog of ontologies\n",
461+
"onto_registry = op.registry(\"../data/out\")"
462+
]
463+
},
464+
{
465+
"cell_type": "code",
466+
"execution_count": null,
467+
"metadata": {},
468+
"outputs": [],
469+
"source": [
470+
"# In case you want to force downloading the registry you can use\n",
471+
"onto_registry.load_registry(force_download=True)"
472+
]
473+
},
474+
{
475+
"cell_type": "code",
476+
"execution_count": null,
477+
"metadata": {},
478+
"outputs": [],
479+
"source": [
480+
"# You can save ALL the catalog as a Python dictionary. The original OBO Foundry registry comes from a YAML file.\n",
481+
"onto_registry_dict = onto_registry.registry_as_dict()"
482+
]
437483
},
438484
{
439485
"cell_type": "code",
440486
"execution_count": null,
441487
"metadata": {},
442488
"outputs": [],
489+
"source": [
490+
"# You can verify the id and description of all the ontologies in the catalog\n",
491+
"onto_registry.list_available_ontologies()"
492+
]
493+
},
494+
{
495+
"cell_type": "code",
496+
"execution_count": null,
497+
"metadata": {},
498+
"outputs": [],
499+
"source": [
500+
"# You can print the current schema or possible fields the catalog store for each ontology.\n",
501+
"onto_registry.print_registry_schema_tree()"
502+
]
503+
},
504+
{
505+
"cell_type": "code",
506+
"execution_count": null,
507+
"metadata": {},
508+
"outputs": [],
509+
"source": [
510+
"# You can get the metadata of each ontology and store it in a variable. At the same time, you can print it using `show_metadata=True`\n",
511+
"go_metadata = onto_registry.get_ontology_metadata(\"go\", show_metadata=True)"
512+
]
513+
},
514+
{
515+
"cell_type": "code",
516+
"execution_count": null,
517+
"metadata": {},
518+
"outputs": [],
519+
"source": [
520+
"# The catalog contains different formats for the same ontology. You can verify all the formats available for a specific ontology.\n",
521+
"onto_registry.get_available_formats(\"chebi\")"
522+
]
523+
},
524+
{
525+
"cell_type": "markdown",
526+
"metadata": {},
527+
"source": [
528+
"### Interact with a specific ontology."
529+
]
530+
},
531+
{
532+
"cell_type": "markdown",
533+
"metadata": {},
534+
"source": []
535+
},
536+
{
537+
"cell_type": "markdown",
538+
"metadata": {},
539+
"source": []
540+
},
541+
{
542+
"cell_type": "markdown",
543+
"metadata": {},
443544
"source": []
444545
},
445546
{
@@ -470,7 +571,7 @@
470571
"name": "python",
471572
"nbconvert_exporter": "python",
472573
"pygments_lexer": "ipython3",
473-
"version": "3.10.12"
574+
"version": "3.13.3"
474575
}
475576
},
476577
"nbformat": 4,

0 commit comments

Comments
 (0)