Skip to content

Commit cf6da92

Browse files
chores: clean up Ruff issues, update client, refactor modules, and update tests.
- chores: clean up Ruff issues in quickstart_demo.ipynb - chores: update client functionality for automatic downloading - chores: clean errors suggested by ruff - chores: format files by suggestion of running ruff - test: remove assertion for cache directory - chores: refactor modules for better separation of resposibilities - chores: remove additional libraries no need it. - test: update tests based on the new structure
1 parent a52cf9c commit cf6da92

32 files changed

Lines changed: 13326 additions & 1858 deletions

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ default_stages:
2222
repos:
2323
# Fast Python linter and formatter with auto-fix support
2424
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: v0.12.3
25+
rev: v0.12.7
2626
hooks:
2727
- id: ruff-check
2828
args: [--fix, --show-fixes]
@@ -33,12 +33,12 @@ repos:
3333
files: \.py$
3434

3535
# Go code cleaner (removes unused exports)
36-
- repo: https://github.com/deeenes/unexport
37-
rev: 0.4.0-patch0-3
38-
hooks:
39-
- id: unexport
40-
args: [--refactor, --single_quotes]
41-
exclude: __init__.py$
36+
#- repo: https://github.com/deeenes/unexport
37+
# rev: 0.4.0-patch0-3
38+
# hooks:
39+
# - id: unexport
40+
# args: [--refactor, --single_quotes]
41+
# exclude: __init__.py$
4242

4343
# Official pre-commit-hooks for general checks
4444
- repo: https://github.com/pre-commit/pre-commit-hooks

notebooks/quickstart_demo.ipynb

Lines changed: 151 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,15 @@
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(\n",
371+
" name_id=name_id_go, format=format_go\n",
372+
")\n",
383373
"\n",
384-
"print(f\"Loaded ontology: {name_id_go}.{format_go}\")\n",
385-
"print(f\"Number of terms: {len(gene_ontology.terms())}\")"
374+
"print(f'Loaded ontology: {name_id_go}.{format_go}')\n",
375+
"print(f'Number of terms: {len(gene_ontology.terms())}')"
386376
]
387377
},
388378
{
@@ -400,7 +390,7 @@
400390
"source": [
401391
"# term_id = \"GO:0008150\" # biological_process\n",
402392
"# term_id = \"GO:0160266\" # anestrus phase\n",
403-
"term_id = \"GO:0070360\" # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host"
393+
"term_id = 'GO:0070360' # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host"
404394
]
405395
},
406396
{
@@ -412,9 +402,9 @@
412402
"queries = OntologyQueries(gene_ontology)\n",
413403
"\n",
414404
"# 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",
405+
"print(f'Term: {term_id}')\n",
406+
"print(f' Parents : {queries.ancestors(term_id)}')\n",
407+
"print(f' Children : {queries.descendants(term_id)}')\n",
418408
"\n",
419409
"\n",
420410
"# print(f\" Ancestors : {queries.ancestors(term_id)}\")\n",
@@ -458,7 +448,7 @@
458448
"outputs": [],
459449
"source": [
460450
"# Load the ontogragh catalog of ontologies\n",
461-
"onto_registry = op.registry(\"../data/out\")"
451+
"onto_registry = op.registry('../data/out')"
462452
]
463453
},
464454
{
@@ -508,7 +498,7 @@
508498
"outputs": [],
509499
"source": [
510500
"# 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)"
501+
"go_metadata = onto_registry.get_ontology_metadata('go', show_metadata=True)"
512502
]
513503
},
514504
{
@@ -518,14 +508,138 @@
518508
"outputs": [],
519509
"source": [
520510
"# 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\")"
511+
"onto_registry.get_available_formats('chebi')"
512+
]
513+
},
514+
{
515+
"cell_type": "markdown",
516+
"metadata": {},
517+
"source": [
518+
"### Download ontologies"
519+
]
520+
},
521+
{
522+
"cell_type": "code",
523+
"execution_count": null,
524+
"metadata": {},
525+
"outputs": [],
526+
"source": [
527+
"# Instantiate a downloader object\n",
528+
"downloader = PoochDownloaderAdapter(cache_dir=cache_dir, registry=onto_registry)"
529+
]
530+
},
531+
{
532+
"cell_type": "code",
533+
"execution_count": null,
534+
"metadata": {},
535+
"outputs": [],
536+
"source": [
537+
"# List of resources to download\n",
538+
"ontologies_to_download = [\n",
539+
" {'name_id': 'go', 'format': 'obo'},\n",
540+
" {'name_id': 'chebi', 'format': 'obo'},\n",
541+
"]\n",
542+
"\n",
543+
"# Download ontologies\n",
544+
"paths_downloads = downloader.fetch_batch(resources=ontologies_to_download)\n",
545+
"\n",
546+
"for name_id, path in paths_downloads.items():\n",
547+
" print(f'{name_id}:\\t{path}')"
548+
]
549+
},
550+
{
551+
"cell_type": "markdown",
552+
"metadata": {},
553+
"source": [
554+
"### Load Ontologies"
555+
]
556+
},
557+
{
558+
"cell_type": "code",
559+
"execution_count": null,
560+
"metadata": {},
561+
"outputs": [],
562+
"source": [
563+
"# Instantiate a loader object\n",
564+
"loader = ProntoLoaderAdapter(cache_dir=cache_dir)"
565+
]
566+
},
567+
{
568+
"cell_type": "code",
569+
"execution_count": null,
570+
"metadata": {},
571+
"outputs": [],
572+
"source": [
573+
"# Load \"go\" ontology previosly downloaded\n",
574+
"go = loader.load_from_registry(name_id='go', format='obo')"
575+
]
576+
},
577+
{
578+
"cell_type": "code",
579+
"execution_count": null,
580+
"metadata": {},
581+
"outputs": [],
582+
"source": [
583+
"# Load \"chebi\" ontology previosly downloaded\n",
584+
"# chebi = loader.load_from_registry(name_id=\"chebi\", format=\"owl\")"
522585
]
523586
},
524587
{
525588
"cell_type": "markdown",
526589
"metadata": {},
527590
"source": [
528-
"### Interact with a specific ontology."
591+
"go_version1 = op.load(path=\"/home/egcarren/go_version1.obo\")\n",
592+
"\n",
593+
"go_version2 = op.load(name_id=\"go\", format=\"owl\")\n",
594+
"\n",
595+
"go_version3 = op.load(name_id=\"go\")"
596+
]
597+
},
598+
{
599+
"cell_type": "code",
600+
"execution_count": null,
601+
"metadata": {},
602+
"outputs": [],
603+
"source": [
604+
"path = '../data/out/go_version1.obo'\n",
605+
"\n",
606+
"Path(path).exists()"
607+
]
608+
},
609+
{
610+
"cell_type": "code",
611+
"execution_count": null,
612+
"metadata": {},
613+
"outputs": [],
614+
"source": [
615+
"go_version1 = op.load(path='../data/out/go_version1.obo')"
616+
]
617+
},
618+
{
619+
"cell_type": "code",
620+
"execution_count": null,
621+
"metadata": {},
622+
"outputs": [],
623+
"source": [
624+
"go_version2 = op.load(name_id='go', format='owl', cache_dir=cache_dir)"
625+
]
626+
},
627+
{
628+
"cell_type": "code",
629+
"execution_count": null,
630+
"metadata": {},
631+
"outputs": [],
632+
"source": [
633+
"queries = OntologyQueries(go_version2)"
634+
]
635+
},
636+
{
637+
"cell_type": "code",
638+
"execution_count": null,
639+
"metadata": {},
640+
"outputs": [],
641+
"source": [
642+
"queries.children(term_id='GO:0008150')"
529643
]
530644
},
531645
{
@@ -557,7 +671,7 @@
557671
],
558672
"metadata": {
559673
"kernelspec": {
560-
"display_name": "ontograph",
674+
"display_name": "ontograph (3.10.18)",
561675
"language": "python",
562676
"name": "python3"
563677
},
@@ -571,7 +685,7 @@
571685
"name": "python",
572686
"nbconvert_exporter": "python",
573687
"pygments_lexer": "ipython3",
574-
"version": "3.13.3"
688+
"version": "3.10.18"
575689
}
576690
},
577691
"nbformat": 4,

ontograph/__init__.py

Lines changed: 2 additions & 2 deletions
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_catalog
22

3-
__all__ = ['registry', 'load']
3+
# __all__ = ["load_catalog"]

0 commit comments

Comments
 (0)