|
7 | 7 | "metadata": {}, |
8 | 8 | "outputs": [], |
9 | 9 | "source": [ |
| 10 | + "import logging\n", |
10 | 11 | "import pandas as pd\n", |
11 | | - "import pronto" |
| 12 | + "from ontograph.client import ClientOntology, ClientCatalog\n", |
| 13 | + "from ontograph.utils import translate_ids" |
12 | 14 | ] |
13 | 15 | }, |
14 | 16 | { |
|
18 | 20 | "metadata": {}, |
19 | 21 | "outputs": [], |
20 | 22 | "source": [ |
21 | | - "chebi = pronto.Ontology(\"../data/out/chebi.owl\")" |
| 23 | + "logging.basicConfig(level=logging.INFO)" |
22 | 24 | ] |
23 | 25 | }, |
24 | 26 | { |
|
28 | 30 | "metadata": {}, |
29 | 31 | "outputs": [], |
30 | 32 | "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" |
32 | 91 | ] |
33 | 92 | }, |
34 | 93 | { |
35 | 94 | "cell_type": "code", |
36 | 95 | "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", |
38 | 147 | "metadata": {}, |
39 | 148 | "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 | + ] |
41 | 224 | } |
42 | 225 | ], |
43 | 226 | "metadata": { |
44 | 227 | "kernelspec": { |
45 | | - "display_name": "ontograph", |
| 228 | + "display_name": "ontograph (3.10.18)", |
46 | 229 | "language": "python", |
47 | 230 | "name": "python3" |
48 | 231 | }, |
|
56 | 239 | "name": "python", |
57 | 240 | "nbconvert_exporter": "python", |
58 | 241 | "pygments_lexer": "ipython3", |
59 | | - "version": "3.10.12" |
| 242 | + "version": "3.10.18" |
60 | 243 | } |
61 | 244 | }, |
62 | 245 | "nbformat": 4, |
|
0 commit comments