Skip to content

Commit 5844c99

Browse files
chores: update client functionality for automatic downloading
1 parent b18add3 commit 5844c99

8 files changed

Lines changed: 258 additions & 170 deletions

File tree

notebooks/quickstart_demo.ipynb

Lines changed: 149 additions & 37 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",
@@ -156,18 +156,7 @@
156156
"metadata": {},
157157
"outputs": [],
158158
"source": [
159-
"import os\n",
160-
"\n",
161-
"os.getcwd()"
162-
]
163-
},
164-
{
165-
"cell_type": "code",
166-
"execution_count": null,
167-
"metadata": {},
168-
"outputs": [],
169-
"source": [
170-
"cache_dir = Path('../data/out')"
159+
"cache_dir = Path(\"../data/out\")"
171160
]
172161
},
173162
{
@@ -247,8 +236,7 @@
247236
"metadata": {},
248237
"outputs": [],
249238
"source": [
250-
"for ontology in onto_registry.list_available_ontologies():\n",
251-
" print(ontology)"
239+
"onto_registry.list_available_ontologies()"
252240
]
253241
},
254242
{
@@ -266,7 +254,7 @@
266254
"source": [
267255
"# This function looks if the given ontology has a link with a given extension\n",
268256
"\n",
269-
"print('Link: {}'.format(onto_registry.get_download_url('chebi', 'obo')))"
257+
"print(\"Link: {}\".format(onto_registry.get_download_url(\"chebi\", \"obo\")))"
270258
]
271259
},
272260
{
@@ -282,7 +270,7 @@
282270
"metadata": {},
283271
"outputs": [],
284272
"source": [
285-
"print(onto_registry.get_available_formats(ontology_id='chebi'))"
273+
"print(onto_registry.get_available_formats(ontology_id=\"chebi\"))"
286274
]
287275
},
288276
{
@@ -326,18 +314,18 @@
326314
"source": [
327315
"# Put the ontologies and their formats as a dictionary\n",
328316
"resources = [\n",
329-
" {'name_id': 'chebi', 'format': 'owl'},\n",
330-
" {'name_id': 'go', 'format': 'obo'},\n",
331-
" {'name_id': 'ado', 'format': 'owl'},\n",
317+
" {\"name_id\": \"chebi\", \"format\": \"owl\"},\n",
318+
" {\"name_id\": \"go\", \"format\": \"obo\"},\n",
319+
" {\"name_id\": \"ado\", \"format\": \"owl\"},\n",
332320
"]\n",
333321
"\n",
334322
"# Use the downloader, it has a cache in case you have already downloaded the ontologies.\n",
335323
"batch_results = downloader.fetch_batch(resources)\n",
336324
"\n",
337325
"# Print all the paths where your ontologies are located\n",
338-
"print('Ontologies in cache:')\n",
326+
"print(\"Ontologies in cache:\")\n",
339327
"for ontology_name, ontology_path in batch_results.items():\n",
340-
" print(f'\\t{ontology_name}: {ontology_path}')"
328+
" print(f\"\\t{ontology_name}: {ontology_path}\")"
341329
]
342330
},
343331
{
@@ -376,13 +364,13 @@
376364
"metadata": {},
377365
"outputs": [],
378366
"source": [
379-
"name_id_go = 'go'\n",
380-
"format_go = 'obo'\n",
367+
"name_id_go = \"go\"\n",
368+
"format_go = \"obo\"\n",
381369
"\n",
382-
"gene_ontology = ontology_loader.load(name_id=name_id_go, format=format_go)\n",
370+
"gene_ontology = ontology_loader.load_from_registry(name_id=name_id_go, format=format_go)\n",
383371
"\n",
384-
"print(f'Loaded ontology: {name_id_go}.{format_go}')\n",
385-
"print(f'Number of terms: {len(gene_ontology.terms())}')"
372+
"print(f\"Loaded ontology: {name_id_go}.{format_go}\")\n",
373+
"print(f\"Number of terms: {len(gene_ontology.terms())}\")"
386374
]
387375
},
388376
{
@@ -400,7 +388,7 @@
400388
"source": [
401389
"# term_id = \"GO:0008150\" # biological_process\n",
402390
"# term_id = \"GO:0160266\" # anestrus phase\n",
403-
"term_id = 'GO:0070360' # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host"
391+
"term_id = \"GO:0070360\" # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host"
404392
]
405393
},
406394
{
@@ -412,9 +400,9 @@
412400
"queries = OntologyQueries(gene_ontology)\n",
413401
"\n",
414402
"# 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",
403+
"print(f\"Term: {term_id}\")\n",
404+
"print(f\" Parents : {queries.ancestors(term_id)}\")\n",
405+
"print(f\" Children : {queries.descendants(term_id)}\")\n",
418406
"\n",
419407
"\n",
420408
"# print(f\" Ancestors : {queries.ancestors(term_id)}\")\n",
@@ -458,7 +446,7 @@
458446
"outputs": [],
459447
"source": [
460448
"# Load the ontogragh catalog of ontologies\n",
461-
"onto_registry = op.registry('../data/out')"
449+
"onto_registry = op.registry(\"../data/out\")"
462450
]
463451
},
464452
{
@@ -508,7 +496,7 @@
508496
"outputs": [],
509497
"source": [
510498
"# 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)"
499+
"go_metadata = onto_registry.get_ontology_metadata(\"go\", show_metadata=True)"
512500
]
513501
},
514502
{
@@ -518,14 +506,138 @@
518506
"outputs": [],
519507
"source": [
520508
"# 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')"
509+
"onto_registry.get_available_formats(\"chebi\")"
510+
]
511+
},
512+
{
513+
"cell_type": "markdown",
514+
"metadata": {},
515+
"source": [
516+
"### Download ontologies"
517+
]
518+
},
519+
{
520+
"cell_type": "code",
521+
"execution_count": null,
522+
"metadata": {},
523+
"outputs": [],
524+
"source": [
525+
"# Instantiate a downloader object\n",
526+
"downloader = PoochDownloaderAdapter(cache_dir=cache_dir, registry=onto_registry)"
527+
]
528+
},
529+
{
530+
"cell_type": "code",
531+
"execution_count": null,
532+
"metadata": {},
533+
"outputs": [],
534+
"source": [
535+
"# List of resources to download\n",
536+
"ontologies_to_download = [\n",
537+
" {\"name_id\": \"go\", \"format\": \"obo\"},\n",
538+
" {\"name_id\": \"chebi\", \"format\": \"obo\"},\n",
539+
"]\n",
540+
"\n",
541+
"# Download ontologies\n",
542+
"paths_downloads = downloader.fetch_batch(resources=ontologies_to_download)\n",
543+
"\n",
544+
"for name_id, path in paths_downloads.items():\n",
545+
" print(f\"{name_id}:\\t{path}\")"
546+
]
547+
},
548+
{
549+
"cell_type": "markdown",
550+
"metadata": {},
551+
"source": [
552+
"### Load Ontologies"
553+
]
554+
},
555+
{
556+
"cell_type": "code",
557+
"execution_count": null,
558+
"metadata": {},
559+
"outputs": [],
560+
"source": [
561+
"# Instantiate a loader object\n",
562+
"loader = ProntoLoaderAdapter(cache_dir=cache_dir)"
563+
]
564+
},
565+
{
566+
"cell_type": "code",
567+
"execution_count": null,
568+
"metadata": {},
569+
"outputs": [],
570+
"source": [
571+
"# Load \"go\" ontology previosly downloaded\n",
572+
"go = loader.load_from_registry(name_id=\"go\", format=\"obo\")"
573+
]
574+
},
575+
{
576+
"cell_type": "code",
577+
"execution_count": null,
578+
"metadata": {},
579+
"outputs": [],
580+
"source": [
581+
"# Load \"chebi\" ontology previosly downloaded\n",
582+
"#chebi = loader.load_from_registry(name_id=\"chebi\", format=\"owl\")"
522583
]
523584
},
524585
{
525586
"cell_type": "markdown",
526587
"metadata": {},
527588
"source": [
528-
"### Interact with a specific ontology."
589+
"go_version1 = op.load(path=\"/home/egcarren/go_version1.obo\")\n",
590+
"\n",
591+
"go_version2 = op.load(name_id=\"go\", format=\"owl\")\n",
592+
"\n",
593+
"go_version3 = op.load(name_id=\"go\")"
594+
]
595+
},
596+
{
597+
"cell_type": "code",
598+
"execution_count": null,
599+
"metadata": {},
600+
"outputs": [],
601+
"source": [
602+
"path=\"../data/out/go_version1.obo\"\n",
603+
"\n",
604+
"Path(path).exists()\n"
605+
]
606+
},
607+
{
608+
"cell_type": "code",
609+
"execution_count": null,
610+
"metadata": {},
611+
"outputs": [],
612+
"source": [
613+
"go_version1 = op.load(path=\"../data/out/go_version1.obo\")"
614+
]
615+
},
616+
{
617+
"cell_type": "code",
618+
"execution_count": null,
619+
"metadata": {},
620+
"outputs": [],
621+
"source": [
622+
"go_version2 = op.load(name_id=\"go\", format=\"owl\", cache_dir=cache_dir)"
623+
]
624+
},
625+
{
626+
"cell_type": "code",
627+
"execution_count": null,
628+
"metadata": {},
629+
"outputs": [],
630+
"source": [
631+
"queries = OntologyQueries(go_version2)"
632+
]
633+
},
634+
{
635+
"cell_type": "code",
636+
"execution_count": null,
637+
"metadata": {},
638+
"outputs": [],
639+
"source": [
640+
"queries.children(term_id=\"GO:0008150\")"
529641
]
530642
},
531643
{
@@ -557,7 +669,7 @@
557669
],
558670
"metadata": {
559671
"kernelspec": {
560-
"display_name": "ontograph",
672+
"display_name": "Python 3",
561673
"language": "python",
562674
"name": "python3"
563675
},
@@ -571,7 +683,7 @@
571683
"name": "python",
572684
"nbconvert_exporter": "python",
573685
"pygments_lexer": "ipython3",
574-
"version": "3.13.3"
686+
"version": "3.10.12"
575687
}
576688
},
577689
"nbformat": 4,

ontograph/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from ontograph.client import registry # , load
1+
from ontograph.client import load, registry
22

33
__all__ = ['registry', 'load']

0 commit comments

Comments
 (0)