|
129 | 129 | "# 1. Standard library imports\n", |
130 | 130 | "import sys\n", |
131 | 131 | "\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", |
133 | 133 | "\n", |
134 | 134 | "from pathlib import Path\n", |
135 | 135 | "\n", |
|
156 | 156 | "metadata": {}, |
157 | 157 | "outputs": [], |
158 | 158 | "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')" |
171 | 160 | ] |
172 | 161 | }, |
173 | 162 | { |
|
247 | 236 | "metadata": {}, |
248 | 237 | "outputs": [], |
249 | 238 | "source": [ |
250 | | - "for ontology in onto_registry.list_available_ontologies():\n", |
251 | | - " print(ontology)" |
| 239 | + "onto_registry.list_available_ontologies()" |
252 | 240 | ] |
253 | 241 | }, |
254 | 242 | { |
|
266 | 254 | "source": [ |
267 | 255 | "# This function looks if the given ontology has a link with a given extension\n", |
268 | 256 | "\n", |
269 | | - "print(\"Link: {}\".format(onto_registry.get_download_url(\"chebi\", \"obo\")))" |
| 257 | + "print('Link: {}'.format(onto_registry.get_download_url('chebi', 'obo')))" |
270 | 258 | ] |
271 | 259 | }, |
272 | 260 | { |
|
282 | 270 | "metadata": {}, |
283 | 271 | "outputs": [], |
284 | 272 | "source": [ |
285 | | - "print(onto_registry.get_available_formats(ontology_id=\"chebi\"))" |
| 273 | + "print(onto_registry.get_available_formats(ontology_id='chebi'))" |
286 | 274 | ] |
287 | 275 | }, |
288 | 276 | { |
|
326 | 314 | "source": [ |
327 | 315 | "# Put the ontologies and their formats as a dictionary\n", |
328 | 316 | "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", |
332 | 320 | "]\n", |
333 | 321 | "\n", |
334 | 322 | "# Use the downloader, it has a cache in case you have already downloaded the ontologies.\n", |
335 | 323 | "batch_results = downloader.fetch_batch(resources)\n", |
336 | 324 | "\n", |
337 | 325 | "# Print all the paths where your ontologies are located\n", |
338 | | - "print(\"Ontologies in cache:\")\n", |
| 326 | + "print('Ontologies in cache:')\n", |
339 | 327 | "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}')" |
341 | 329 | ] |
342 | 330 | }, |
343 | 331 | { |
|
376 | 364 | "metadata": {}, |
377 | 365 | "outputs": [], |
378 | 366 | "source": [ |
379 | | - "name_id_go = \"go\"\n", |
380 | | - "format_go = \"obo\"\n", |
| 367 | + "name_id_go = 'go'\n", |
| 368 | + "format_go = 'obo'\n", |
381 | 369 | "\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", |
383 | 373 | "\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())}')" |
386 | 376 | ] |
387 | 377 | }, |
388 | 378 | { |
|
400 | 390 | "source": [ |
401 | 391 | "# term_id = \"GO:0008150\" # biological_process\n", |
402 | 392 | "# 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" |
404 | 394 | ] |
405 | 395 | }, |
406 | 396 | { |
|
412 | 402 | "queries = OntologyQueries(gene_ontology)\n", |
413 | 403 | "\n", |
414 | 404 | "# 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", |
418 | 408 | "\n", |
419 | 409 | "\n", |
420 | 410 | "# print(f\" Ancestors : {queries.ancestors(term_id)}\")\n", |
|
458 | 448 | "outputs": [], |
459 | 449 | "source": [ |
460 | 450 | "# Load the ontogragh catalog of ontologies\n", |
461 | | - "onto_registry = op.registry(\"../data/out\")" |
| 451 | + "onto_registry = op.registry('../data/out')" |
462 | 452 | ] |
463 | 453 | }, |
464 | 454 | { |
|
508 | 498 | "outputs": [], |
509 | 499 | "source": [ |
510 | 500 | "# 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)" |
512 | 502 | ] |
513 | 503 | }, |
514 | 504 | { |
|
518 | 508 | "outputs": [], |
519 | 509 | "source": [ |
520 | 510 | "# 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\")" |
522 | 585 | ] |
523 | 586 | }, |
524 | 587 | { |
525 | 588 | "cell_type": "markdown", |
526 | 589 | "metadata": {}, |
527 | 590 | "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')" |
529 | 643 | ] |
530 | 644 | }, |
531 | 645 | { |
|
557 | 671 | ], |
558 | 672 | "metadata": { |
559 | 673 | "kernelspec": { |
560 | | - "display_name": "ontograph", |
| 674 | + "display_name": "ontograph (3.10.18)", |
561 | 675 | "language": "python", |
562 | 676 | "name": "python3" |
563 | 677 | }, |
|
571 | 685 | "name": "python", |
572 | 686 | "nbconvert_exporter": "python", |
573 | 687 | "pygments_lexer": "ipython3", |
574 | | - "version": "3.13.3" |
| 688 | + "version": "3.10.18" |
575 | 689 | } |
576 | 690 | }, |
577 | 691 | "nbformat": 4, |
|
0 commit comments