Skip to content

Commit 82001b0

Browse files
chores: clean current implementation by removing unneeded files
1 parent 8add7f5 commit 82001b0

9 files changed

Lines changed: 2321 additions & 106 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ __pycache__/
2424

2525
notebooks/cache/
2626
.venv/
27+
28+
29+

api_view_user.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# API final view from user perspective
2+
3+
## Importing the library
4+
- Complete import of Ontograph
5+
```python
6+
import ontograph
7+
```
8+
9+
10+
## Download Ontologies
11+
- Download a single ontology from standard resources
12+
```python
13+
14+
resource = [
15+
{"name_id": "go","format": "obo"},
16+
]
17+
18+
path_ontologie = ontograph.downloader.download(resource, cache_directory)
19+
```
20+
21+
- Download a multiple ontologies from standard resources
22+
```python
23+
24+
resources = [
25+
{"name_id": "go","format": "obo"},
26+
{"name_id": "chebi","format": "owl"},
27+
]
28+
29+
paths_ontologies = ontograph.downloader.download(resources, cache_directory)
30+
```
31+
32+
## Load ontologies
33+
34+
- Load the "ontology from standard resources, or local source"
35+
```python
36+
gene_ontology = ontograph.load(name_id="go", format="obo")
37+
```
38+
39+
## Exploring the ontology
40+
41+
- Print the metadata related to the ontology
42+
```python
43+
gene_ontology.metadata()
44+
```
45+
46+
- Print the roots of the ontology
47+
```python
48+
gene_ontology.roots()
49+
```
50+
51+
52+
```mermaid
53+
flowchart TD
54+
%% API Layer
55+
A1[OntologyClient<br>api/client.py]
56+
57+
%% Core Domain
58+
subgraph Core
59+
B1[OntologyGraph<br>core/ontology_graph.py]
60+
B2[QueryEngine<br>core/query_engine.py]
61+
B3[TermMapping<br>core/term_mapping.py]
62+
end
63+
64+
%% Ports (Interfaces)
65+
subgraph Ports
66+
P1[OntologyLoader<br>ports/ontology_loader.py]
67+
P2[GraphBackend<br>ports/graph_backend.py]
68+
P3[Downloader<br>ports/downloader.py]
69+
end
70+
71+
%% Adapters
72+
subgraph Adapters
73+
C1[pronto_loader.py]
74+
C2[pronto_graph.py]
75+
C3[pooch_downloader.py]
76+
C4[tsv_mapping_loader.py]
77+
end
78+
79+
%% Utilities & Config (internal use only)
80+
subgraph Utils_Config
81+
U1[file_cache.py]
82+
U2[validation.py]
83+
U3[logging.py]
84+
S1[settings.py]
85+
end
86+
87+
%% Connections
88+
A1 --> B1
89+
A1 --> B2
90+
A1 --> B3
91+
92+
%% Core uses Ports (interfaces)
93+
B1 --> P1
94+
B2 --> P2
95+
B3 --> P3
96+
97+
%% Adapters implement Ports (interfaces)
98+
P1 -.-> C1
99+
P2 -.-> C2
100+
P3 -.-> C3
101+
P3 -.-> C4
102+
103+
%% Internal usage (no direct arrow from API)
104+
Core --> Utils_Config
105+
Adapters --> Utils_Config
106+
```
107+
108+
**Legend:**
109+
110+
- --> means "uses"
111+
- -.-> means "implemented by"

notebooks/template_notebooks.ipynb

Lines changed: 109 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
},
121121
{
122122
"cell_type": "code",
123-
"execution_count": 45,
123+
"execution_count": null,
124124
"metadata": {},
125125
"outputs": [],
126126
"source": [
@@ -135,8 +135,8 @@
135135
"import pronto\n",
136136
"\n",
137137
"# 3. Local application/library specific imports\n",
138-
"from ontograph.downloader import download_file\n",
139-
"import ontograph.constants as constants"
138+
"from ontograph._downloader import download_file\n",
139+
"import ontograph._constants as _constants"
140140
]
141141
},
142142
{
@@ -148,27 +148,9 @@
148148
},
149149
{
150150
"cell_type": "code",
151-
"execution_count": 2,
151+
"execution_count": null,
152152
"metadata": {},
153-
"outputs": [
154-
{
155-
"name": "stderr",
156-
"output_type": "stream",
157-
"text": [
158-
"Downloading data from 'https://purl.obolibrary.org/obo/go.obo' to file '/home/ecarreno/SSC-Projects/b_REPOSITORIES/ontograph/notebooks/cache/gene_ontology.obo'.\n",
159-
"100%|█████████████████████████████████████| 35.1M/35.1M [00:00<00:00, 97.7GB/s]\n",
160-
"SHA256 hash of downloaded file: 0908af70601dd41f2c55f664ca5d5959e939162362e9a5573c6794b5d850e601\n",
161-
"Use this value as the 'known_hash' argument of 'pooch.retrieve' to ensure that the file hasn't changed if it is downloaded again in the future.\n"
162-
]
163-
},
164-
{
165-
"name": "stdout",
166-
"output_type": "stream",
167-
"text": [
168-
"Gene Ontology OBO file cached at: /home/ecarreno/SSC-Projects/b_REPOSITORIES/ontograph/notebooks/cache/gene_ontology.obo\n"
169-
]
170-
}
171-
],
153+
"outputs": [],
172154
"source": [
173155
"CACHE_DIRECTORY = \"cache\"\n",
174156
"\n",
@@ -194,7 +176,7 @@
194176
},
195177
{
196178
"cell_type": "code",
197-
"execution_count": 76,
179+
"execution_count": null,
198180
"metadata": {},
199181
"outputs": [],
200182
"source": [
@@ -210,7 +192,7 @@
210192
},
211193
{
212194
"cell_type": "code",
213-
"execution_count": 75,
195+
"execution_count": null,
214196
"metadata": {},
215197
"outputs": [],
216198
"source": [
@@ -258,32 +240,9 @@
258240
},
259241
{
260242
"cell_type": "code",
261-
"execution_count": 77,
243+
"execution_count": null,
262244
"metadata": {},
263-
"outputs": [
264-
{
265-
"name": "stdout",
266-
"output_type": "stream",
267-
"text": [
268-
"Format_version: \n",
269-
"\t1.2\n",
270-
"Data_version: \n",
271-
"\treleases/2025-06-01\n",
272-
"Ontology_identifier: \n",
273-
"\tgo\n",
274-
"Last_update: \n",
275-
"\tNone\n",
276-
"Name: \n",
277-
"\tGene Ontology\n",
278-
"Description: \n",
279-
"\tThe Gene Ontology (GO) provides a framework and set of concepts for describing the functions of gene products from all organisms.\n",
280-
"License: \n",
281-
"\thttp://creativecommons.org/licenses/by/4.0/\n",
282-
"Roots: \n",
283-
"\t['GO:0003674', 'GO:0005575', 'GO:0008150']\n"
284-
]
285-
}
286-
],
245+
"outputs": [],
287246
"source": [
288247
"print_metadata(gene_ontology)"
289248
]
@@ -313,11 +272,109 @@
313272
"\n",
314273
"Include citations for any external content or suggested resources for deeper learning."
315274
]
275+
},
276+
{
277+
"cell_type": "code",
278+
"execution_count": null,
279+
"metadata": {},
280+
"outputs": [],
281+
"source": []
282+
},
283+
{
284+
"cell_type": "code",
285+
"execution_count": null,
286+
"metadata": {},
287+
"outputs": [
288+
{
289+
"name": "stdout",
290+
"output_type": "stream",
291+
"text": [
292+
"Added to sys.path: /home/edwin/SSC-Projects/b_REPOSITORIES/ontograph\n"
293+
]
294+
}
295+
],
296+
"source": [
297+
"import sys\n",
298+
"import os\n",
299+
"\n",
300+
"# Get the absolute path to the parent folder (where both 'notebooks' and 'ontograph' live)\n",
301+
"project_root = os.path.abspath(os.path.join(os.getcwd(), \"..\"))\n",
302+
"\n",
303+
"# Insert at front of sys.path so it's prioritized\n",
304+
"sys.path.insert(0, project_root)\n",
305+
"\n",
306+
"print(\"Added to sys.path:\", project_root)"
307+
]
308+
},
309+
{
310+
"cell_type": "code",
311+
"execution_count": 3,
312+
"metadata": {},
313+
"outputs": [
314+
{
315+
"name": "stderr",
316+
"output_type": "stream",
317+
"text": [
318+
"Downloading data from 'http://purl.obolibrary.org/obo/go.obo' to file '/home/edwin/.ontograph_cache/go.obo'.\n",
319+
"SHA256 hash of downloaded file: 0908af70601dd41f2c55f664ca5d5959e939162362e9a5573c6794b5d850e601\n",
320+
"Use this value as the 'known_hash' argument of 'pooch.retrieve' to ensure that the file hasn't changed if it is downloaded again in the future.\n"
321+
]
322+
},
323+
{
324+
"name": "stdout",
325+
"output_type": "stream",
326+
"text": [
327+
"{'name': 'go', 'version': 'releases/2025-06-01', 'format': '1.2'}\n"
328+
]
329+
},
330+
{
331+
"ename": "AttributeError",
332+
"evalue": "'Ontology' object has no attribute 'roots'",
333+
"output_type": "error",
334+
"traceback": [
335+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
336+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
337+
"Cell \u001b[0;32mIn[3], line 7\u001b[0m\n\u001b[1;32m 4\u001b[0m gene_ontology \u001b[38;5;241m=\u001b[39m client\u001b[38;5;241m.\u001b[39mload(name_id\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgo\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28mformat\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mobo\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(gene_ontology\u001b[38;5;241m.\u001b[39mmetadata())\n\u001b[0;32m----> 7\u001b[0m \u001b[38;5;28mprint\u001b[39m([root\u001b[38;5;241m.\u001b[39mid \u001b[38;5;28;01mfor\u001b[39;00m root \u001b[38;5;129;01min\u001b[39;00m \u001b[43mgene_ontology\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mroots\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m])\n",
338+
"File \u001b[0;32m~/SSC-Projects/b_REPOSITORIES/ontograph/ontograph/api/client.py:51\u001b[0m, in \u001b[0;36mOntologyWrapper.roots\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mroots\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43montology\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mroots\u001b[49m())\n",
339+
"\u001b[0;31mAttributeError\u001b[0m: 'Ontology' object has no attribute 'roots'"
340+
]
341+
}
342+
],
343+
"source": [
344+
"from ontograph.api.client import OntologyClient\n",
345+
"\n",
346+
"client = OntologyClient()\n",
347+
"gene_ontology = client.load(name_id=\"go\", format=\"obo\")\n",
348+
"\n",
349+
"print(gene_ontology.metadata())\n",
350+
"print([root.id for root in gene_ontology.roots()])"
351+
]
352+
},
353+
{
354+
"cell_type": "code",
355+
"execution_count": null,
356+
"metadata": {},
357+
"outputs": [],
358+
"source": [
359+
"print(os.listdir(sys.path[0]))"
360+
]
361+
},
362+
{
363+
"cell_type": "code",
364+
"execution_count": null,
365+
"metadata": {},
366+
"outputs": [],
367+
"source": [
368+
"import ontograph.api.client\n",
369+
"\n",
370+
"\n",
371+
"ontograph.api."
372+
]
316373
}
317374
],
318375
"metadata": {
319376
"kernelspec": {
320-
"display_name": "Python 3",
377+
"display_name": "ontograph",
321378
"language": "python",
322379
"name": "python3"
323380
},
@@ -331,7 +388,7 @@
331388
"name": "python",
332389
"nbconvert_exporter": "python",
333390
"pygments_lexer": "ipython3",
334-
"version": "3.10.12"
391+
"version": "3.10.18"
335392
}
336393
},
337394
"nbformat": 4,

ontograph/adapters/obo_foundry_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def get_available_formats(self, ontology_id: str) -> List[str]:
187187
if __name__ == "__main__":
188188

189189
# Define the path to store the registry
190-
path = Path("./")
190+
path = Path("./data/out")
191191

192192
# Create object registry
193193
obo_reg = OBOFoundryRegistry(cache_dir=path)

ontograph/constants.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)