{ "cells": [ { "cell_type": "markdown", "id": "738137ef", "metadata": {}, "source": [ "# OAK logical-definitions command\n", "\n", "This notebook is intended as a supplement to the [main OAK CLI docs](https://incatools.github.io/ontology-access-kit/cli.html).\n", "\n", "This notebook provides examples for the `logical-definitions` command, which can be used to **lookup and summarize logical defs**\n", "\n", "For more on logical definitions, see [Logical Definitions](https://incatools.github.io/ontology-access-kit/guide/logical-definitions.html) in the OAK guide.\n", "\n", "## Help Option\n", "\n", "You can get help on any OAK command using `--help`" ] }, { "cell_type": "code", "execution_count": 1, "id": "838586ce", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Usage: runoak logical-definitions [OPTIONS] [TERMS]...\r\n", "\r\n", " Show all logical definitions for a term or terms.\r\n", "\r\n", " To show all logical definitions in an ontology, pass the \".all\" query term\r\n", "\r\n", " Example; first create an alias:\r\n", "\r\n", " alias pato=\"runoak -i obo:sqlite:pato\"\r\n", "\r\n", " Then run the query:\r\n", "\r\n", " pato logical-definitions .all\r\n", "\r\n", " By default, \".all\" will query all axioms for all terms including merged\r\n", " terms; to restrict to only the current terms, use an ID query:\r\n", "\r\n", " pato logical-definitions i^PATO\r\n", "\r\n", " You can also restrict to branches:\r\n", "\r\n", " pato logical-definitions .desc//p=i \"physical object quality\"\r\n", "\r\n", " By default, the output is a subset of OboGraph datamodel rendered as YAML,\r\n", " e.g.\r\n", "\r\n", " definedClassId: PATO:0045071 genusIds: - PATO:0001439\r\n", " restrictions: - fillerId: PATO:0000461 propertyId: RO:0015010\r\n", "\r\n", " You can also specify CSV to generate a flattened form of this.\r\n", "\r\n", " Example:\r\n", "\r\n", " pato logical-definitions .all --output-type csv\r\n", "\r\n", " You can optionally choose to \"--matrix-axes\" to transform the output to a\r\n", " matrix form. This is a comma-separated pair of axes, where each element is a\r\n", " logical definition element type: \"f\" for filler, \"p\" for predicate, \"g\" for\r\n", " genus, \"d\" for defined class.\r\n", "\r\n", " Example:\r\n", "\r\n", " - Each property/predicate is a column - For repeated properties, columns of\r\n", " the form prop_1, prop_2, ... are generated\r\n", "\r\n", " Example:\r\n", "\r\n", " pato logical-definitions .all --matrix-axes d,p --output-type csv\r\n", "\r\n", " This will generate a row for each defined class with a logical definition,\r\n", " with columns for each predicate (\"genus\" is treated as a predicate here).\r\n", "\r\n", " Limitations:\r\n", "\r\n", " Currently this only works for definitions that follow a basic genus-\r\n", " differentia pattern, which is what is currently represented in the OboGraph\r\n", " datamodel.\r\n", "\r\n", " Consider using the \"axioms\" command for inspection of complex nested OWL\r\n", " axioms.\r\n", "\r\n", " More examples:\r\n", "\r\n", " https://github.com/INCATools/ontology-access-\r\n", " kit/blob/main/notebooks/Commands/LogicalDefinitions.ipynb\r\n", "\r\n", " Python API:\r\n", "\r\n", " https://incatools.github.io/ontology-access-kit/interfaces/obograph\r\n", "\r\n", " Data model:\r\n", "\r\n", " https://w3id.org/oak/obograph\r\n", "\r\n", "Options:\r\n", " --unmelt / --no-unmelt Flatten to a wide table [default: no-\r\n", " unmelt]\r\n", " --matrix-axes TEXT If specified, transform results to matrix\r\n", " using these row and column axes. Examples:\r\n", " d,p; f,g\r\n", " -p, --predicates TEXT A comma-separated list of predicates. This\r\n", " may be a shorthand (i, p) or CURIE\r\n", " --autolabel / --no-autolabel If set, results will automatically have\r\n", " labels assigned [default: autolabel]\r\n", " -O, --output-type TEXT Desired output type\r\n", " -o, --output FILENAME Output file, e.g. obo file\r\n", " --if-absent [absent-only|present-only]\r\n", " determines behavior when the value is not\r\n", " present or is empty.\r\n", " -S, --set-value TEXT the value to set for all terms for the given\r\n", " property.\r\n", " --help Show this message and exit.\r\n" ] } ], "source": [ "!runoak logical-definitions --help" ] }, { "cell_type": "markdown", "id": "5b899d5c", "metadata": {}, "source": [ "## Set up an alias\n", "\n", "For convenience we will set up an alias for use in this notebook" ] }, { "cell_type": "code", "execution_count": 2, "id": "6050d1a5", "metadata": {}, "outputs": [], "source": [ "alias uberon runoak -i sqlite:obo:uberon" ] }, { "cell_type": "markdown", "id": "c906c109", "metadata": {}, "source": [ "## Fetching logical definitions for individual terms\n", "\n", "First we will pass in a simple list of terms to the command.\n", "\n", "Like most OAK commands, this command accepts lists of either IDs, labels, queries, or boolean combinations thereof" ] }, { "cell_type": "code", "execution_count": 3, "id": "572be78c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "definedClassId: UBERON:0009565\r\n", "genusIds:\r\n", "- UBERON:0001705\r\n", "restrictions:\r\n", "- fillerId: UBERON:0002389\r\n", " propertyId: BFO:0000050\r\n", "\r\n", "---\r\n", "definedClassId: UBERON:0009567\r\n", "genusIds:\r\n", "- UBERON:0001705\r\n", "restrictions:\r\n", "- fillerId: UBERON:0001466\r\n", " propertyId: BFO:0000050\r\n" ] } ], "source": [ "uberon logical-definitions fingernail toenail" ] }, { "cell_type": "code", "execution_count": 4, "id": "3b3c4afa", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "definedClassId\tdefinedClassId_label\tgenusIds\tgenusIds_label\trestrictions\trestrictionsPropertyIds\trestrictionsPropertyIds_label\trestrictionsFillerIds\trestrictionsFillerIds_label\r", "\r\n", "UBERON:0009565\tnail of manual digit\tUBERON:0001705\tnail\tBFO:0000050=UBERON:0002389\tBFO:0000050\tpart of\tUBERON:0002389\tmanual digit\r", "\r\n", "UBERON:0009567\tnail of pedal digit\tUBERON:0001705\tnail\tBFO:0000050=UBERON:0001466\tBFO:0000050\tpart of\tUBERON:0001466\tpedal digit\r", "\r\n" ] } ], "source": [ "uberon logical-definitions fingernail toenail -O csv" ] }, { "cell_type": "code", "execution_count": 5, "id": "c9900ca0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[Term]\r\n", "id: UBERON:0009565 ! nail of manual digit\r\n", "intersection_of: UBERON:0001705 ! nail\r\n", "intersection_of: BFO:0000050 UBERON:0002389 ! manual digit\r\n", "\r\n", "\r\n", "[Term]\r\n", "id: UBERON:0009567 ! nail of pedal digit\r\n", "intersection_of: UBERON:0001705 ! nail\r\n", "intersection_of: BFO:0000050 UBERON:0001466 ! pedal digit\r\n", "\r\n", "\r\n" ] } ], "source": [ "uberon logical-definitions fingernail toenail -O obo" ] }, { "cell_type": "markdown", "id": "d08c6000", "metadata": {}, "source": [ "## Matrix views\n", "\n", "We can use the `--matrix-axes` option to summarize a large collection of logical definitions as a wide table.\n", "\n", "This takes two values, separated by a comma:\n", "\n", "- d: defined_class\n", "- f: filler\n", "- g: genus\n", "- p: predicate\n", "\n", "### Define class x Predicate\n", "\n", "In the following example `d,p` will create a matrix whose rows are defined classes and whose columns are predicates" ] }, { "cell_type": "code", "execution_count": 8, "id": "ae4748a0", "metadata": {}, "outputs": [], "source": [ "uberon logical-definitions -p p .desc//p=i \"bone element\" .and .desc//p=i,p UBERON:0002544 --matrix-axes d,p -O csv -o output/uberon-digit-defs-dp.tsv" ] }, { "cell_type": "code", "execution_count": 9, "id": "dcb7bb7e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | defined_class | \n", "defined_class_label | \n", "genus | \n", "genus_label | \n", "part_of | \n", "part_of_label | \n", "
---|---|---|---|---|---|---|
0 | \n", "UBERON:0001436 | \n", "phalanx of manus | \n", "UBERON:0003221 | \n", "phalanx | \n", "UBERON:0002389 | \n", "manual digit | \n", "
1 | \n", "UBERON:0002234 | \n", "proximal phalanx of manus | \n", "UBERON:0004302 | \n", "proximal phalanx | \n", "UBERON:0002389 | \n", "manual digit | \n", "
2 | \n", "UBERON:0004328 | \n", "proximal phalanx of manual digit 2 | \n", "UBERON:0004302 | \n", "proximal phalanx | \n", "UBERON:0003622 | \n", "manual digit 2 | \n", "
3 | \n", "UBERON:0004329 | \n", "proximal phalanx of manual digit 3 | \n", "UBERON:0004302 | \n", "proximal phalanx | \n", "UBERON:0003623 | \n", "manual digit 3 | \n", "
4 | \n", "UBERON:0004330 | \n", "proximal phalanx of manual digit 4 | \n", "UBERON:0004302 | \n", "proximal phalanx | \n", "UBERON:0003624 | \n", "manual digit 4 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
59 | \n", "UBERON:0014503 | \n", "proximal phalanx of digit 3 | \n", "UBERON:0004302 | \n", "proximal phalanx | \n", "UBERON:0006050 | \n", "digit 3 | \n", "
60 | \n", "UBERON:0014504 | \n", "proximal phalanx of digit 4 | \n", "UBERON:0004302 | \n", "proximal phalanx | \n", "UBERON:0006051 | \n", "digit 4 | \n", "
61 | \n", "UBERON:0014505 | \n", "proximal phalanx of digit 5 | \n", "UBERON:0004302 | \n", "proximal phalanx | \n", "UBERON:0006052 | \n", "digit 5 | \n", "
62 | \n", "UBERON:0004248 | \n", "pedal digit bone | \n", "UBERON:0001474 | \n", "bone element | \n", "UBERON:0001466 | \n", "pedal digit | \n", "
63 | \n", "UBERON:0004249 | \n", "manual digit bone | \n", "UBERON:0001474 | \n", "bone element | \n", "UBERON:0002389 | \n", "manual digit | \n", "
64 rows × 6 columns
\n", "\n", " | filler | \n", "filler_label | \n", "phalanx | \n", "phalanx_label | \n", "proximal_phalanx | \n", "proximal_phalanx_label | \n", "middle_phalanx | \n", "middle_phalanx_label | \n", "distal_phalanx | \n", "distal_phalanx_label | \n", "bone_element | \n", "bone_element_label | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "UBERON:0002387 | \n", "pes | \n", "UBERON:0001449 | \n", "phalanx of pes | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
1 | \n", "UBERON:0009563 | \n", "pastern region of limb | \n", "UBERON:0009558 | \n", "pastern bone | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
2 | \n", "UBERON:0002389 | \n", "manual digit | \n", "UBERON:0001436 | \n", "phalanx of manus | \n", "UBERON:0002234 | \n", "proximal phalanx of manus | \n", "UBERON:0003864 | \n", "middle phalanx of manus | \n", "UBERON:0003865 | \n", "distal phalanx of manus | \n", "UBERON:0004249 | \n", "manual digit bone | \n", "
3 | \n", "UBERON:0003622 | \n", "manual digit 2 | \n", "UBERON:0003636 | \n", "manual digit 2 phalanx | \n", "UBERON:0004328 | \n", "proximal phalanx of manual digit 2 | \n", "UBERON:0004320 | \n", "middle phalanx of manual digit 2 | \n", "UBERON:0004311 | \n", "distal phalanx of manual digit 2 | \n", "NaN | \n", "NaN | \n", "
4 | \n", "UBERON:0003623 | \n", "manual digit 3 | \n", "UBERON:0003637 | \n", "manual digit 3 phalanx | \n", "UBERON:0004329 | \n", "proximal phalanx of manual digit 3 | \n", "UBERON:0004321 | \n", "middle phalanx of manual digit 3 | \n", "UBERON:0004312 | \n", "distal phalanx of manual digit 3 | \n", "NaN | \n", "NaN | \n", "
5 | \n", "UBERON:0003624 | \n", "manual digit 4 | \n", "UBERON:0003638 | \n", "manual digit 4 phalanx | \n", "UBERON:0004330 | \n", "proximal phalanx of manual digit 4 | \n", "UBERON:0004322 | \n", "middle phalanx of manual digit 4 | \n", "UBERON:0004313 | \n", "distal phalanx of manual digit 4 | \n", "NaN | \n", "NaN | \n", "
6 | \n", "UBERON:0001463 | \n", "manual digit 1 | \n", "UBERON:0003620 | \n", "manual digit 1 phalanx | \n", "UBERON:0004338 | \n", "proximal phalanx of manual digit 1 | \n", "NaN | \n", "NaN | \n", "UBERON:0004337 | \n", "distal phalanx of manual digit 1 | \n", "NaN | \n", "NaN | \n", "
7 | \n", "UBERON:0003625 | \n", "manual digit 5 | \n", "UBERON:0003639 | \n", "manual digit 5 phalanx | \n", "UBERON:0004331 | \n", "proximal phalanx of manual digit 5 | \n", "UBERON:0004323 | \n", "middle phalanx of manual digit 5 | \n", "UBERON:0004314 | \n", "distal phalanx of manual digit 5 | \n", "NaN | \n", "NaN | \n", "
8 | \n", "UBERON:0001466 | \n", "pedal digit | \n", "NaN | \n", "NaN | \n", "UBERON:0003868 | \n", "proximal phalanx of pes | \n", "UBERON:0003866 | \n", "middle phalanx of pes | \n", "UBERON:0003867 | \n", "distal phalanx of pes | \n", "UBERON:0004248 | \n", "pedal digit bone | \n", "
9 | \n", "UBERON:0003632 | \n", "pedal digit 2 | \n", "UBERON:0003641 | \n", "pedal digit 2 phalanx | \n", "UBERON:0004333 | \n", "proximal phalanx of pedal digit 2 | \n", "UBERON:0004324 | \n", "middle phalanx of pedal digit 2 | \n", "UBERON:0004316 | \n", "distal phalanx of pedal digit 2 | \n", "NaN | \n", "NaN | \n", "
10 | \n", "UBERON:0003633 | \n", "pedal digit 3 | \n", "UBERON:0003642 | \n", "pedal digit 3 phalanx | \n", "UBERON:0004334 | \n", "proximal phalanx of pedal digit 3 | \n", "UBERON:0004325 | \n", "middle phalanx of pedal digit 3 | \n", "UBERON:0004317 | \n", "distal phalanx of pedal digit 3 | \n", "NaN | \n", "NaN | \n", "
11 | \n", "UBERON:0003634 | \n", "pedal digit 4 | \n", "UBERON:0003862 | \n", "pedal digit 4 phalanx | \n", "UBERON:0004335 | \n", "proximal phalanx of pedal digit 4 | \n", "UBERON:0004326 | \n", "middle phalanx of pedal digit 4 | \n", "UBERON:0004318 | \n", "distal phalanx of pedal digit 4 | \n", "NaN | \n", "NaN | \n", "
12 | \n", "UBERON:0003631 | \n", "pedal digit 1 | \n", "UBERON:0003640 | \n", "pedal digit 1 phalanx | \n", "UBERON:0004332 | \n", "proximal phalanx of pedal digit 1 | \n", "NaN | \n", "NaN | \n", "UBERON:0004315 | \n", "distal phalanx of pedal digit 1 | \n", "NaN | \n", "NaN | \n", "
13 | \n", "UBERON:0003635 | \n", "pedal digit 5 | \n", "UBERON:0003863 | \n", "pedal digit 5 phalanx | \n", "UBERON:0004336 | \n", "proximal phalanx of pedal digit 5 | \n", "UBERON:0004327 | \n", "middle phalanx of pedal digit 5 | \n", "UBERON:0004319 | \n", "distal phalanx of pedal digit 5 | \n", "NaN | \n", "NaN | \n", "
14 | \n", "UBERON:0012137 | \n", "pedal digit 7 | \n", "UBERON:4100009 | \n", "pedal digit 7 phalanx | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
15 | \n", "UBERON:0006049 | \n", "digit 2 | \n", "NaN | \n", "NaN | \n", "UBERON:0014502 | \n", "proximal phalanx of digit 2 | \n", "UBERON:0014488 | \n", "middle phalanx of digit 2 | \n", "UBERON:0014484 | \n", "distal phalanx of digit 2 | \n", "NaN | \n", "NaN | \n", "
16 | \n", "UBERON:0006050 | \n", "digit 3 | \n", "NaN | \n", "NaN | \n", "UBERON:0014503 | \n", "proximal phalanx of digit 3 | \n", "UBERON:0014489 | \n", "middle phalanx of digit 3 | \n", "UBERON:0014485 | \n", "distal phalanx of digit 3 | \n", "NaN | \n", "NaN | \n", "
17 | \n", "UBERON:0006051 | \n", "digit 4 | \n", "NaN | \n", "NaN | \n", "UBERON:0014504 | \n", "proximal phalanx of digit 4 | \n", "UBERON:0014490 | \n", "middle phalanx of digit 4 | \n", "UBERON:0014486 | \n", "distal phalanx of digit 4 | \n", "NaN | \n", "NaN | \n", "
18 | \n", "UBERON:0006048 | \n", "digit 1 | \n", "NaN | \n", "NaN | \n", "UBERON:0014501 | \n", "proximal phalanx of digit 1 | \n", "NaN | \n", "NaN | \n", "UBERON:0014483 | \n", "distal phalanx of digit 1 | \n", "NaN | \n", "NaN | \n", "
19 | \n", "UBERON:0006052 | \n", "digit 5 | \n", "NaN | \n", "NaN | \n", "UBERON:0014505 | \n", "proximal phalanx of digit 5 | \n", "UBERON:0014491 | \n", "middle phalanx of digit 5 | \n", "UBERON:0014487 | \n", "distal phalanx of digit 5 | \n", "NaN | \n", "NaN | \n", "