|
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", |
|
167 | 167 | "metadata": {}, |
168 | 168 | "outputs": [], |
169 | 169 | "source": [ |
170 | | - "cache_dir = Path('../data/out')" |
| 170 | + "cache_dir = Path(\"../data/out\")" |
171 | 171 | ] |
172 | 172 | }, |
173 | 173 | { |
|
266 | 266 | "source": [ |
267 | 267 | "# This function looks if the given ontology has a link with a given extension\n", |
268 | 268 | "\n", |
269 | | - "print('Link: {}'.format(onto_registry.get_download_url('chebi', 'obo')))" |
| 269 | + "print(\"Link: {}\".format(onto_registry.get_download_url(\"chebi\", \"obo\")))" |
270 | 270 | ] |
271 | 271 | }, |
272 | 272 | { |
|
282 | 282 | "metadata": {}, |
283 | 283 | "outputs": [], |
284 | 284 | "source": [ |
285 | | - "print(onto_registry.get_available_formats(ontology_id='chebi'))" |
| 285 | + "print(onto_registry.get_available_formats(ontology_id=\"chebi\"))" |
286 | 286 | ] |
287 | 287 | }, |
288 | 288 | { |
|
326 | 326 | "source": [ |
327 | 327 | "# Put the ontologies and their formats as a dictionary\n", |
328 | 328 | "resources = [\n", |
329 | | - " {'name_id': 'chebi', 'format': 'owl'},\n", |
330 | | - " {'name_id': 'go', 'format': 'obo'},\n", |
331 | | - " {'name_id': 'ado', 'format': 'owl'},\n", |
| 329 | + " {\"name_id\": \"chebi\", \"format\": \"owl\"},\n", |
| 330 | + " {\"name_id\": \"go\", \"format\": \"obo\"},\n", |
| 331 | + " {\"name_id\": \"ado\", \"format\": \"owl\"},\n", |
332 | 332 | "]\n", |
333 | 333 | "\n", |
334 | 334 | "# Use the downloader, it has a cache in case you have already downloaded the ontologies.\n", |
335 | 335 | "batch_results = downloader.fetch_batch(resources)\n", |
336 | 336 | "\n", |
337 | 337 | "# Print all the paths where your ontologies are located\n", |
338 | | - "print('Ontologies in cache:')\n", |
| 338 | + "print(\"Ontologies in cache:\")\n", |
339 | 339 | "for ontology_name, ontology_path in batch_results.items():\n", |
340 | | - " print(f'\\t{ontology_name}: {ontology_path}')" |
| 340 | + " print(f\"\\t{ontology_name}: {ontology_path}\")" |
341 | 341 | ] |
342 | 342 | }, |
343 | 343 | { |
|
376 | 376 | "metadata": {}, |
377 | 377 | "outputs": [], |
378 | 378 | "source": [ |
379 | | - "name_id_go = 'go'\n", |
380 | | - "format_go = 'obo'\n", |
| 379 | + "name_id_go = \"go\"\n", |
| 380 | + "format_go = \"obo\"\n", |
381 | 381 | "\n", |
382 | 382 | "gene_ontology = ontology_loader.load(name_id=name_id_go, format=format_go)\n", |
383 | 383 | "\n", |
384 | | - "print(f'Loaded ontology: {name_id_go}.{format_go}')\n", |
385 | | - "print(f'Number of terms: {len(gene_ontology.terms())}')" |
| 384 | + "print(f\"Loaded ontology: {name_id_go}.{format_go}\")\n", |
| 385 | + "print(f\"Number of terms: {len(gene_ontology.terms())}\")" |
386 | 386 | ] |
387 | 387 | }, |
388 | 388 | { |
|
400 | 400 | "source": [ |
401 | 401 | "# term_id = \"GO:0008150\" # biological_process\n", |
402 | 402 | "# term_id = \"GO:0160266\" # anestrus phase\n", |
403 | | - "term_id = 'GO:0070360' # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host" |
| 403 | + "term_id = \"GO:0070360\" # symbiont-mediated actin polymerization-dependent cell-to-cell migration in host" |
404 | 404 | ] |
405 | 405 | }, |
406 | 406 | { |
|
412 | 412 | "queries = OntologyQueries(gene_ontology)\n", |
413 | 413 | "\n", |
414 | 414 | "# 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", |
| 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", |
418 | 418 | "\n", |
419 | 419 | "\n", |
420 | 420 | "# print(f\" Ancestors : {queries.ancestors(term_id)}\")\n", |
421 | 421 | "# print(f\" Descendants : {queries.descendants(term_id)}\")" |
422 | 422 | ] |
423 | 423 | }, |
| 424 | + { |
| 425 | + "cell_type": "markdown", |
| 426 | + "metadata": {}, |
| 427 | + "source": [ |
| 428 | + "## Step 5. Client" |
| 429 | + ] |
| 430 | + }, |
| 431 | + { |
| 432 | + "cell_type": "markdown", |
| 433 | + "metadata": {}, |
| 434 | + "source": [ |
| 435 | + "### Import the library" |
| 436 | + ] |
| 437 | + }, |
424 | 438 | { |
425 | 439 | "cell_type": "code", |
426 | 440 | "execution_count": null, |
427 | 441 | "metadata": {}, |
428 | 442 | "outputs": [], |
429 | | - "source": [] |
| 443 | + "source": [ |
| 444 | + "import ontograph as op" |
| 445 | + ] |
| 446 | + }, |
| 447 | + { |
| 448 | + "cell_type": "markdown", |
| 449 | + "metadata": {}, |
| 450 | + "source": [ |
| 451 | + "### Interact with the registry" |
| 452 | + ] |
430 | 453 | }, |
431 | 454 | { |
432 | 455 | "cell_type": "code", |
433 | 456 | "execution_count": null, |
434 | 457 | "metadata": {}, |
435 | 458 | "outputs": [], |
436 | | - "source": [] |
| 459 | + "source": [ |
| 460 | + "# Load the ontogragh catalog of ontologies\n", |
| 461 | + "onto_registry = op.registry(\"../data/out\")" |
| 462 | + ] |
| 463 | + }, |
| 464 | + { |
| 465 | + "cell_type": "code", |
| 466 | + "execution_count": null, |
| 467 | + "metadata": {}, |
| 468 | + "outputs": [], |
| 469 | + "source": [ |
| 470 | + "# In case you want to force downloading the registry you can use\n", |
| 471 | + "onto_registry.load_registry(force_download=True)" |
| 472 | + ] |
| 473 | + }, |
| 474 | + { |
| 475 | + "cell_type": "code", |
| 476 | + "execution_count": null, |
| 477 | + "metadata": {}, |
| 478 | + "outputs": [], |
| 479 | + "source": [ |
| 480 | + "# You can save ALL the catalog as a Python dictionary. The original OBO Foundry registry comes from a YAML file.\n", |
| 481 | + "onto_registry_dict = onto_registry.registry_as_dict()" |
| 482 | + ] |
437 | 483 | }, |
438 | 484 | { |
439 | 485 | "cell_type": "code", |
440 | 486 | "execution_count": null, |
441 | 487 | "metadata": {}, |
442 | 488 | "outputs": [], |
| 489 | + "source": [ |
| 490 | + "# You can verify the id and description of all the ontologies in the catalog\n", |
| 491 | + "onto_registry.list_available_ontologies()" |
| 492 | + ] |
| 493 | + }, |
| 494 | + { |
| 495 | + "cell_type": "code", |
| 496 | + "execution_count": null, |
| 497 | + "metadata": {}, |
| 498 | + "outputs": [], |
| 499 | + "source": [ |
| 500 | + "# You can print the current schema or possible fields the catalog store for each ontology.\n", |
| 501 | + "onto_registry.print_registry_schema_tree()" |
| 502 | + ] |
| 503 | + }, |
| 504 | + { |
| 505 | + "cell_type": "code", |
| 506 | + "execution_count": null, |
| 507 | + "metadata": {}, |
| 508 | + "outputs": [], |
| 509 | + "source": [ |
| 510 | + "# 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)" |
| 512 | + ] |
| 513 | + }, |
| 514 | + { |
| 515 | + "cell_type": "code", |
| 516 | + "execution_count": null, |
| 517 | + "metadata": {}, |
| 518 | + "outputs": [], |
| 519 | + "source": [ |
| 520 | + "# 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\")" |
| 522 | + ] |
| 523 | + }, |
| 524 | + { |
| 525 | + "cell_type": "markdown", |
| 526 | + "metadata": {}, |
| 527 | + "source": [ |
| 528 | + "### Interact with a specific ontology." |
| 529 | + ] |
| 530 | + }, |
| 531 | + { |
| 532 | + "cell_type": "markdown", |
| 533 | + "metadata": {}, |
| 534 | + "source": [] |
| 535 | + }, |
| 536 | + { |
| 537 | + "cell_type": "markdown", |
| 538 | + "metadata": {}, |
| 539 | + "source": [] |
| 540 | + }, |
| 541 | + { |
| 542 | + "cell_type": "markdown", |
| 543 | + "metadata": {}, |
443 | 544 | "source": [] |
444 | 545 | }, |
445 | 546 | { |
|
470 | 571 | "name": "python", |
471 | 572 | "nbconvert_exporter": "python", |
472 | 573 | "pygments_lexer": "ipython3", |
473 | | - "version": "3.10.12" |
| 574 | + "version": "3.13.3" |
474 | 575 | } |
475 | 576 | }, |
476 | 577 | "nbformat": 4, |
|
0 commit comments