Skip to content

Commit 3bacde6

Browse files
chores: update notebook to demostrate or experiment with the mapping use case
1 parent c7b1f99 commit 3bacde6

2 files changed

Lines changed: 190 additions & 179 deletions

File tree

notebooks/.$pipeline_mapping.drawio.bkp

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

notebooks/chebi_mix_ontology.ipynb

Lines changed: 190 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"metadata": {},
88
"outputs": [],
99
"source": [
10+
"import logging\n",
1011
"import pandas as pd\n",
11-
"import pronto"
12+
"from ontograph.client import ClientOntology, ClientCatalog\n",
13+
"from ontograph.utils import translate_ids"
1214
]
1315
},
1416
{
@@ -18,7 +20,7 @@
1820
"metadata": {},
1921
"outputs": [],
2022
"source": [
21-
"chebi = pronto.Ontology(\"../data/out/chebi.owl\")"
23+
"logging.basicConfig(level=logging.INFO)"
2224
]
2325
},
2426
{
@@ -28,21 +30,202 @@
2830
"metadata": {},
2931
"outputs": [],
3032
"source": [
31-
"len(chebi.terms())"
33+
"PATH_ONTOLOGY_FILE = \"../data/out/swiss_lipids_ontology.obo\" \n",
34+
"PATH_MAPPING_FILE = \"../data/out/swiss_lipids_mapping_ids.csv\""
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"id": "3",
40+
"metadata": {},
41+
"source": [
42+
"## Experimentation"
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"id": "4",
48+
"metadata": {},
49+
"source": [
50+
"1. Read an ontology file\n",
51+
"\n",
52+
"2. Read a mapping file:\n",
53+
" - 2.1. Read the mapping file\n",
54+
" - 2.2. Create a LUT.\n",
55+
"\n",
56+
"3. When look for terms do the following:\n",
57+
" - 3.1. If a LUT exist:\n",
58+
" - Translate the term\n",
59+
" - 3.2. Return the terms of interest in the table.\n",
60+
"\n",
61+
"4. Apply the operation in the ontology"
62+
]
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"id": "5",
67+
"metadata": {},
68+
"source": [
69+
"Use cases\n",
70+
"```markdown\n",
71+
"\n",
72+
"SwisslipidsOntology.common_ancestors('HMDB0000232', 'HMDB0000765', 'HMDB0000342')\n",
73+
"['SWL:0000234']\n",
74+
"\n",
75+
"SwisslipidsOntology.terms_for('HMDB0000232')\n",
76+
"['SWL:0000234']\n",
77+
"\n",
78+
"\n",
79+
"SwisslipidsOntology.mappings()\n",
80+
"['hmdb', 'lipidmaps', 'metanetx']\n",
81+
"\n",
82+
"```"
83+
]
84+
},
85+
{
86+
"cell_type": "markdown",
87+
"id": "6",
88+
"metadata": {},
89+
"source": [
90+
"### Read ontology"
3291
]
3392
},
3493
{
3594
"cell_type": "code",
3695
"execution_count": null,
37-
"id": "3",
96+
"id": "7",
97+
"metadata": {},
98+
"outputs": [],
99+
"source": [
100+
"swiss_onto = ClientOntology()"
101+
]
102+
},
103+
{
104+
"cell_type": "markdown",
105+
"id": "8",
106+
"metadata": {},
107+
"source": [
108+
"### Load ontology file"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": null,
114+
"id": "9",
115+
"metadata": {},
116+
"outputs": [],
117+
"source": [
118+
"swiss_onto.load(file_path_ontology=PATH_ONTOLOGY_FILE)"
119+
]
120+
},
121+
{
122+
"cell_type": "markdown",
123+
"id": "10",
124+
"metadata": {},
125+
"source": [
126+
"### Load mapping file"
127+
]
128+
},
129+
{
130+
"cell_type": "code",
131+
"execution_count": null,
132+
"id": "11",
133+
"metadata": {},
134+
"outputs": [],
135+
"source": [
136+
"swiss_onto.load_mapping(filepath=PATH_MAPPING_FILE,\n",
137+
" delimiter=\"\\t\",\n",
138+
" #target_column=\"chebi_id\",\n",
139+
" target_column=\"swiss_lipid_id\",\n",
140+
" )"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": null,
146+
"id": "12",
38147
"metadata": {},
39148
"outputs": [],
40-
"source": []
149+
"source": [
150+
"test_ids_diverse = [\n",
151+
" 'CHEBI:70995', # chebi\n",
152+
" \"SLM:000508824\", # swiss lipids\n",
153+
" \"HMDB00032\", # hmdb\n",
154+
" \"LMGP01030010\", # lipid maps\n",
155+
" \"MNXM2990\", # metanetx\n",
156+
" \"CHEBI:88888\" # fake chebi id\n",
157+
"]\n",
158+
"\n",
159+
"test_ids_swiss_lipids = ['SLM:000048885','SLM:000508824','SLM:000000042','SLM:000048885','SLM:000000288']"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": null,
165+
"id": "13",
166+
"metadata": {},
167+
"outputs": [],
168+
"source": [
169+
"terms_translated = translate_ids(\n",
170+
" #mapping_lut=None,\n",
171+
" mapping_lut=swiss_onto.get_mapping_lut(),\n",
172+
" terms_id=test_ids_diverse,\n",
173+
" #terms_id=test_ids_swiss_lipids\n",
174+
")\n",
175+
"\n",
176+
"terms_translated"
177+
]
178+
},
179+
{
180+
"cell_type": "code",
181+
"execution_count": null,
182+
"id": "14",
183+
"metadata": {},
184+
"outputs": [],
185+
"source": [
186+
"for term in swiss_onto.get_terms(terms_translated):\n",
187+
" print(f\"\\n{term}\")\n",
188+
" for property in term.annotations:\n",
189+
" print(f\"\\t{property.property}: {property.literal}\")\n"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": null,
195+
"id": "15",
196+
"metadata": {},
197+
"outputs": [],
198+
"source": [
199+
"for term in swiss_onto.get_terms(test_ids_diverse):\n",
200+
" print(f\"\\n{term}\")\n",
201+
" for property in term.annotations:\n",
202+
" print(f\"\\t{property.property}: {property.literal}\")"
203+
]
204+
},
205+
{
206+
"cell_type": "code",
207+
"execution_count": null,
208+
"id": "16",
209+
"metadata": {},
210+
"outputs": [],
211+
"source": [
212+
"swiss_onto.mappings()"
213+
]
214+
},
215+
{
216+
"cell_type": "code",
217+
"execution_count": null,
218+
"id": "17",
219+
"metadata": {},
220+
"outputs": [],
221+
"source": [
222+
"a = swiss_onto.get_mapping_lut()"
223+
]
41224
}
42225
],
43226
"metadata": {
44227
"kernelspec": {
45-
"display_name": "ontograph",
228+
"display_name": "ontograph (3.10.18)",
46229
"language": "python",
47230
"name": "python3"
48231
},
@@ -56,7 +239,7 @@
56239
"name": "python",
57240
"nbconvert_exporter": "python",
58241
"pygments_lexer": "ipython3",
59-
"version": "3.10.12"
242+
"version": "3.10.18"
60243
}
61244
},
62245
"nbformat": 4,

0 commit comments

Comments
 (0)