|
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(name_id=name_id_go, format=format_go)\n", |
383 | 371 | "\n", |
384 | | - "print(f'Loaded ontology: {name_id_go}.{format_go}')\n", |
385 | | - "print(f'Number of terms: {len(gene_ontology.terms())}')" |
| 372 | + "print(f\"Loaded ontology: {name_id_go}.{format_go}\")\n", |
| 373 | + "print(f\"Number of terms: {len(gene_ontology.terms())}\")" |
386 | 374 | ] |
387 | 375 | }, |
388 | 376 | { |
|
400 | 388 | "source": [ |
401 | 389 | "# term_id = \"GO:0008150\" # biological_process\n", |
402 | 390 | "# term_id = \"GO:0160266\" # anestrus phase\n", |
403 | | - "term_id = 'GO:0070360' # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host" |
| 391 | + "term_id = \"GO:0070360\" # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host" |
404 | 392 | ] |
405 | 393 | }, |
406 | 394 | { |
|
412 | 400 | "queries = OntologyQueries(gene_ontology)\n", |
413 | 401 | "\n", |
414 | 402 | "# 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", |
| 403 | + "print(f\"Term: {term_id}\")\n", |
| 404 | + "print(f\" Parents : {queries.ancestors(term_id)}\")\n", |
| 405 | + "print(f\" Children : {queries.descendants(term_id)}\")\n", |
418 | 406 | "\n", |
419 | 407 | "\n", |
420 | 408 | "# print(f\" Ancestors : {queries.ancestors(term_id)}\")\n", |
|
458 | 446 | "outputs": [], |
459 | 447 | "source": [ |
460 | 448 | "# Load the ontogragh catalog of ontologies\n", |
461 | | - "onto_registry = op.registry('../data/out')" |
| 449 | + "onto_registry = op.registry(\"../data/out\")" |
462 | 450 | ] |
463 | 451 | }, |
464 | 452 | { |
|
508 | 496 | "outputs": [], |
509 | 497 | "source": [ |
510 | 498 | "# 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)" |
| 499 | + "go_metadata = onto_registry.get_ontology_metadata(\"go\", show_metadata=True)" |
512 | 500 | ] |
513 | 501 | }, |
514 | 502 | { |
|
518 | 506 | "outputs": [], |
519 | 507 | "source": [ |
520 | 508 | "# 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')" |
| 509 | + "onto_registry.get_available_formats(\"chebi\")" |
| 510 | + ] |
| 511 | + }, |
| 512 | + { |
| 513 | + "cell_type": "markdown", |
| 514 | + "metadata": {}, |
| 515 | + "source": [ |
| 516 | + "### Download ontologies" |
| 517 | + ] |
| 518 | + }, |
| 519 | + { |
| 520 | + "cell_type": "code", |
| 521 | + "execution_count": null, |
| 522 | + "metadata": {}, |
| 523 | + "outputs": [], |
| 524 | + "source": [ |
| 525 | + "# Instantiate a downloader object\n", |
| 526 | + "downloader = PoochDownloaderAdapter(cache_dir=cache_dir, registry=onto_registry)" |
| 527 | + ] |
| 528 | + }, |
| 529 | + { |
| 530 | + "cell_type": "code", |
| 531 | + "execution_count": null, |
| 532 | + "metadata": {}, |
| 533 | + "outputs": [], |
| 534 | + "source": [ |
| 535 | + "# List of resources to download\n", |
| 536 | + "ontologies_to_download = [\n", |
| 537 | + " {\"name_id\": \"go\", \"format\": \"obo\"},\n", |
| 538 | + " {\"name_id\": \"chebi\", \"format\": \"obo\"},\n", |
| 539 | + "]\n", |
| 540 | + "\n", |
| 541 | + "# Download ontologies\n", |
| 542 | + "paths_downloads = downloader.fetch_batch(resources=ontologies_to_download)\n", |
| 543 | + "\n", |
| 544 | + "for name_id, path in paths_downloads.items():\n", |
| 545 | + " print(f\"{name_id}:\\t{path}\")" |
| 546 | + ] |
| 547 | + }, |
| 548 | + { |
| 549 | + "cell_type": "markdown", |
| 550 | + "metadata": {}, |
| 551 | + "source": [ |
| 552 | + "### Load Ontologies" |
| 553 | + ] |
| 554 | + }, |
| 555 | + { |
| 556 | + "cell_type": "code", |
| 557 | + "execution_count": null, |
| 558 | + "metadata": {}, |
| 559 | + "outputs": [], |
| 560 | + "source": [ |
| 561 | + "# Instantiate a loader object\n", |
| 562 | + "loader = ProntoLoaderAdapter(cache_dir=cache_dir)" |
| 563 | + ] |
| 564 | + }, |
| 565 | + { |
| 566 | + "cell_type": "code", |
| 567 | + "execution_count": null, |
| 568 | + "metadata": {}, |
| 569 | + "outputs": [], |
| 570 | + "source": [ |
| 571 | + "# Load \"go\" ontology previosly downloaded\n", |
| 572 | + "go = loader.load_from_registry(name_id=\"go\", format=\"obo\")" |
| 573 | + ] |
| 574 | + }, |
| 575 | + { |
| 576 | + "cell_type": "code", |
| 577 | + "execution_count": null, |
| 578 | + "metadata": {}, |
| 579 | + "outputs": [], |
| 580 | + "source": [ |
| 581 | + "# Load \"chebi\" ontology previosly downloaded\n", |
| 582 | + "#chebi = loader.load_from_registry(name_id=\"chebi\", format=\"owl\")" |
522 | 583 | ] |
523 | 584 | }, |
524 | 585 | { |
525 | 586 | "cell_type": "markdown", |
526 | 587 | "metadata": {}, |
527 | 588 | "source": [ |
528 | | - "### Interact with a specific ontology." |
| 589 | + "go_version1 = op.load(path=\"/home/egcarren/go_version1.obo\")\n", |
| 590 | + "\n", |
| 591 | + "go_version2 = op.load(name_id=\"go\", format=\"owl\")\n", |
| 592 | + "\n", |
| 593 | + "go_version3 = op.load(name_id=\"go\")" |
| 594 | + ] |
| 595 | + }, |
| 596 | + { |
| 597 | + "cell_type": "code", |
| 598 | + "execution_count": null, |
| 599 | + "metadata": {}, |
| 600 | + "outputs": [], |
| 601 | + "source": [ |
| 602 | + "path=\"../data/out/go_version1.obo\"\n", |
| 603 | + "\n", |
| 604 | + "Path(path).exists()\n" |
| 605 | + ] |
| 606 | + }, |
| 607 | + { |
| 608 | + "cell_type": "code", |
| 609 | + "execution_count": null, |
| 610 | + "metadata": {}, |
| 611 | + "outputs": [], |
| 612 | + "source": [ |
| 613 | + "go_version1 = op.load(path=\"../data/out/go_version1.obo\")" |
| 614 | + ] |
| 615 | + }, |
| 616 | + { |
| 617 | + "cell_type": "code", |
| 618 | + "execution_count": null, |
| 619 | + "metadata": {}, |
| 620 | + "outputs": [], |
| 621 | + "source": [ |
| 622 | + "go_version2 = op.load(name_id=\"go\", format=\"owl\", cache_dir=cache_dir)" |
| 623 | + ] |
| 624 | + }, |
| 625 | + { |
| 626 | + "cell_type": "code", |
| 627 | + "execution_count": null, |
| 628 | + "metadata": {}, |
| 629 | + "outputs": [], |
| 630 | + "source": [ |
| 631 | + "queries = OntologyQueries(go_version2)" |
| 632 | + ] |
| 633 | + }, |
| 634 | + { |
| 635 | + "cell_type": "code", |
| 636 | + "execution_count": null, |
| 637 | + "metadata": {}, |
| 638 | + "outputs": [], |
| 639 | + "source": [ |
| 640 | + "queries.children(term_id=\"GO:0008150\")" |
529 | 641 | ] |
530 | 642 | }, |
531 | 643 | { |
|
557 | 669 | ], |
558 | 670 | "metadata": { |
559 | 671 | "kernelspec": { |
560 | | - "display_name": "ontograph", |
| 672 | + "display_name": "Python 3", |
561 | 673 | "language": "python", |
562 | 674 | "name": "python3" |
563 | 675 | }, |
|
571 | 683 | "name": "python", |
572 | 684 | "nbconvert_exporter": "python", |
573 | 685 | "pygments_lexer": "ipython3", |
574 | | - "version": "3.13.3" |
| 686 | + "version": "3.10.12" |
575 | 687 | } |
576 | 688 | }, |
577 | 689 | "nbformat": 4, |
|
0 commit comments