### Setup Development Environment Source: https://github.com/biolink/ontobio/blob/master/notebooks/README.md Commands to create a virtual environment, install dependencies, and configure the Python path. ```bash pyvenv venv source venv/bin/activate export PYTHONPATH=.:$PYTHONPATH pip install -r requirements.txt pip install jupyter ``` -------------------------------- ### Setup Ontobio with Pyvenv Source: https://github.com/biolink/ontobio/blob/master/docs/installation.md Set up a Python virtual environment using pyvenv, activate it, and install dependencies from requirements.txt. This isolates Ontobio's environment from your system's Python installation. ```default cd ontobio pyvenv venv source venv/bin/activate export PYTHONPATH=.:$PYTHONPATH pip install -r requirements.txt ``` -------------------------------- ### Launch Notebooks Source: https://github.com/biolink/ontobio/blob/master/notebooks/README.md Command to start the Jupyter notebook server from the parent folder. ```makefile make nb ``` -------------------------------- ### Install Ontobio Development Version Source: https://github.com/biolink/ontobio/blob/master/docs/installation.md Clone the Ontobio repository from GitHub and install the development version using pip. This is useful for contributing to the project or testing the latest features. ```default git clone https://github.com/biolink/ontobio.git cd ontobio pip install -e .[dev,test] ``` -------------------------------- ### Start Jupyter Notebook Server Source: https://github.com/biolink/ontobio/blob/master/docs/notebooks.md Run this command in your terminal to start the Jupyter Notebook server. Ensure the PYTHONPATH is set correctly to access Ontobio libraries. ```bash PYTHONPATH=.. jupyter notebook ``` -------------------------------- ### Install Ontobio with Pip Source: https://github.com/biolink/ontobio/blob/master/docs/installation.md Use this command to install the latest stable version of Ontobio from PyPI. Ensure you have Python 3.4 or higher. ```default pip install ontobio ``` -------------------------------- ### Execute annotation summary Source: https://github.com/biolink/ontobio/blob/master/notebooks/Summarize_GOTerm_Descendants.ipynb Example call to the summarize function. ```python print(summarize(term_id)) ``` -------------------------------- ### Initialize OntologyFactory Source: https://github.com/biolink/ontobio/blob/master/notebooks/Lookup_KEGG_Genes_by_Pathway_Name.ipynb Instantiate the OntologyFactory to create ontology objects. No specific setup is required before this. ```python from ontobio.ontol_factory import OntologyFactory ofactory= OntologyFactory() ``` -------------------------------- ### Set up Ontobio CLI PATH Source: https://github.com/biolink/ontobio/blob/master/docs/commandline.md Add the Ontobio bin directory to your system's PATH to make the CLI tools accessible. Ensure you have installed Ontobio first. ```bash export PATH $HOME/repos/ontobio/ontobio/bin ogr -h ``` -------------------------------- ### Load Local OWL and OBO-Format Ontologies Source: https://github.com/biolink/ontobio/blob/master/docs/inputs.md Requires OWLTools to be installed for processing OWL and OBO files. ```default ogr.py -r path/to/my/file.owl ``` ```python from ontobio.ontol_factory import OntologyFactory ont = OntologyFactory().create("/path/to/my/file.owl") ``` -------------------------------- ### Search for terms starting with a string Source: https://github.com/biolink/ontobio/blob/master/docs/commandline.md Use a wildcard '%' or the `-s r` flag with a regex to find terms that start with a specific string. This mimics SQL LIKE behavior. ```bash ogr -r cl neuron% ogr -r cl -s r ^neuron ``` -------------------------------- ### Import OntoBio Libraries Source: https://github.com/biolink/ontobio/blob/master/notebooks/Summarize_GOTerm_Descendants.ipynb Imports necessary libraries for ontology manipulation and querying. Ensure these libraries are installed. ```python import pandas as pd ## Create an ontology factory in order to fetch GO from ontobio.ontol_factory import OntologyFactory ofactory = OntologyFactory() ## GOLR queries from ontobio.golr.golr_query import GolrAssociationQuery ## rendering ontologies from ontobio import GraphRenderer ``` -------------------------------- ### Query for multiple classes Source: https://github.com/biolink/ontobio/blob/master/docs/commandline.md Provide multiple class names as arguments to the `ogr` command to query for them simultaneously. This example queries for 'neuron', 'hepatocyte', and 'erythrocyte'. ```bash ogr -r cl neuron hepatocyte erythrocyte ``` -------------------------------- ### Create Poetry Development Environment Source: https://github.com/biolink/ontobio/blob/master/README-developers.md Use this command to create a new pyproject.toml file, set up a .venv virtual environment, and install dependencies. It will delete existing lock files and virtual environments. ```bash make poetry ``` -------------------------------- ### Recreate Poetry Virtual Environment Source: https://github.com/biolink/ontobio/blob/master/README-developers.md To recreate the virtual environment, either rerun `make poetry` or remove the existing .venv directory and run `poetry install` to use the poetry.lock file. ```bash rm -rf .venv poetry install ``` -------------------------------- ### Query Genes by Phenotype using ontobio-assoc.py Source: https://github.com/biolink/ontobio/blob/master/docs/analyses.md Command-line example to find genes associated with a specific phenotype using the ontobio-assoc.py script. It queries a remote SPARQL service for MP and uses a default for associations. ```console # find all mouse genes that have 'abnormal synaptic transmission' phenotype # (using remote sparql service for MP, and default (Monarch) for associations ontobio-assoc.py -v -r mp -T NCBITaxon:10090 -C gene phenotype query -q MP:0003635 > genes.txt ``` -------------------------------- ### Get NetworkX Graph Representation Source: https://github.com/biolink/ontobio/blob/master/notebooks/Find_All_Paths.ipynb Import the NetworkX library and obtain the graph representation of the ontology. This graph can be used for pathfinding algorithms. ```python from networkx import nx G = ont.get_graph() G ``` -------------------------------- ### Get Objects for Subject Source: https://github.com/biolink/ontobio/blob/master/docs/api.md Returns a list of classes used to describe a subject. This is the recommended method for retrieving subject descriptions. ```python objects_for_subject(subject_id) ``` -------------------------------- ### Lexical Mapping with Remote Ontologies Source: https://github.com/biolink/ontobio/blob/master/docs/analyses.md Example of using ontobio-lexmap.py with remote ontology identifiers (e.g., Monarch Phenotype, Human Phenotype Ontology, WormPhenotype). ```console ontobio-lexmap.py mp hp wbphenotype > mappings.tsv ``` -------------------------------- ### Get Reflexive Ancestors Source: https://github.com/biolink/ontobio/blob/master/notebooks/Find_All_Paths.ipynb Retrieves all ancestors of a given term, including the term itself, and filters for those starting with 'HP:'. Useful for exploring hierarchical context. ```python ancs = ont.ancestors(t, reflexive=True) ancs = [a for a in ancs if a.startswith('HP:')] ``` -------------------------------- ### Initialize Lexical Map Engine Source: https://github.com/biolink/ontobio/blob/master/notebooks/Parse_RareList.ipynb Sets up the LexicalMapEngine for mapping. ```python from ontobio.lexmap import LexicalMapEngine lexmap = LexicalMapEngine() ``` -------------------------------- ### Create and Query an Ontology Source: https://github.com/biolink/ontobio/blob/master/docs/concepts.md Demonstrates how to create an ontology object from a factory and perform basic searches and ancestor queries. Requires the 'go' ontology to be available. ```python from ontobio.ontol_factory import OntologyFactory ont = OntologyFactory().create("go") [nucleus] = ont.search('nucleus') ancestors = ont.ancestors(nucleus) ``` -------------------------------- ### Initialize OntologyFactory and Load Ontology Source: https://github.com/biolink/ontobio/blob/master/notebooks/Intro_Local_Ontologies.ipynb Create an ontology factory instance and load a local obographs-json file. ```python from ontobio.ontol_factory import OntologyFactory ofactory = OntologyFactory() ont = ofactory.create("nucleus.json") ## interpreted as a json local handle ``` -------------------------------- ### Create Ontology Object (GO) Source: https://github.com/biolink/ontobio/blob/master/notebooks/GO_Functional_Similarity_using_AssocFiles.ipynb Initializes an OntologyFactory and creates a 'go' ontology object. This may take a few seconds on the first run as it connects to a remote SPARQL service. ```python from ontobio.ontol_factory import OntologyFactory # Create ontology object, for GO # Transparently uses remote SPARQL service. # (May take a few seconds to run first time, Jupyter will show '*'. BE PATIENT, do # not re-execute cell) ofactory = OntologyFactory() ont = ofactory.create('go') ``` -------------------------------- ### Get Node Descendants Source: https://github.com/biolink/ontobio/blob/master/notebooks/Remote_Ontology.ipynb Retrieve all descendants of a given ontology node ID. ```python ancs = ont.descendants('PATO:0001374') ancs ``` -------------------------------- ### Get Node Label Source: https://github.com/biolink/ontobio/blob/master/notebooks/Remote_Ontology.ipynb Retrieve the label for a given ontology node ID. ```python cls = ont.node('PATO:0001374') cls ``` -------------------------------- ### Generate initial IDs using SPARQL WHERE clause Source: https://github.com/biolink/ontobio/blob/master/docs/commandline.md Use the `-Q` option with `ogr-tree` to pipe results from a SPARQL query into the tool, generating the initial set of IDs for further processing. ```bash ogr-tree -r pato -Q "{?x rdfs:subClassOf+ PATO:0000052}" ``` -------------------------------- ### Get number of nodes in ontology Source: https://github.com/biolink/ontobio/blob/master/notebooks/Intro_Local_Ontologies.ipynb Returns the total count of nodes present in the graph object. ```python len(graph) ``` -------------------------------- ### Initialize Ontology Factory Source: https://github.com/biolink/ontobio/blob/master/notebooks/Gene_Expression.ipynb Creates an ontology factory instance and fetches the Uberon ontology. ```python ## Create an ontology factory in order to fetch Uberon from ontobio.ontol_factory import OntologyFactory ofactory = OntologyFactory() ont = ofactory.create("uberon") ``` -------------------------------- ### Select Arbitrary Node Source: https://github.com/biolink/ontobio/blob/master/notebooks/Find_All_Paths.ipynb Selects the first node from a list of nodes, often used as a starting point for further hierarchical analysis. ```python t = nodes_with_max[0] ``` -------------------------------- ### Create AssociationSet from sources Source: https://context7.com/biolink/ontobio/llms.txt Demonstrates initializing an AssociationSet from a remote GAF file or programmatically from tuples. ```python aset = afactory.create_from_remote_file( group='pombase', ontology=ont ) # Create from tuples programmatically tuples = [ ('UniProtKB:P12345', 'Gene1', 'GO:0005634'), ('UniProtKB:P12346', 'Gene2', 'GO:0005737'), ] aset = afactory.create_from_tuples(tuples, ontology=ont) ``` -------------------------------- ### Get Label for ID Source: https://github.com/biolink/ontobio/blob/master/docs/api.md Retrieves the human-readable label for a given subject ID, utilizing both the ontology and the association set for context. ```python label(id) ``` -------------------------------- ### Use ogr Command Line Tool Source: https://context7.com/biolink/ontobio/llms.txt Perform ontology graph operations directly from the command line. ```bash ogr -r go nucleus ogr -r cl neuron% # Wildcard: starts with 'neuron' ogr -r hp %diabetes% # Contains 'diabetes' ``` ```bash ogr -r cl -p subClassOf -t tree neuron ``` ```bash ogr -r go -p subClassOf -p BFO:0000050 -t tree nucleus ``` ```bash ogr -r cl -p subClassOf -t tree -d d neuron ``` ```bash ogr -r cl -p subClassOf -t tree -d du neuron ``` ```bash ogr -r go -p subClassOf -p BFO:0000050 -t png nucleus ``` ```bash ogr -r /path/to/my-ontology.json neuron ``` -------------------------------- ### Get ECO Class Label Source: https://github.com/biolink/ontobio/blob/master/notebooks/Map_Evidence_Codes.ipynb Retrieve the human-readable label for a given ECO class identifier using the ontology object. ```python ontol.label(cls) ``` -------------------------------- ### Get Annotations for Subject Source: https://github.com/biolink/ontobio/blob/master/docs/api.md Retrieves a list of classes used to describe a given subject. This method is deprecated; use `objects_for_subject` instead. ```python annotations(subject_id) ``` -------------------------------- ### Verify Remote Configuration Source: https://github.com/biolink/ontobio/blob/master/docs/contributing.md Displays the configured remote repositories and their URLs. ```bash git remote -v ``` -------------------------------- ### Ontology.synonyms - Get Term Synonyms Source: https://context7.com/biolink/ontobio/llms.txt Retrieves all synonyms for an ontology class, including the synonym type (exact, related, narrow, broad). ```APIDOC ## Ontology.synonyms - Get Term Synonyms ### Description Retrieves all synonyms for an ontology class, including the synonym type (exact, related, narrow, broad). ### Method `synonyms` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from ontobio.ontol_factory import OntologyFactory ont = OntologyFactory().create('go') # Get synonyms for a term term_id = 'GO:0005634' synonyms = ont.synonyms(term_id) for syn in synonyms: print(f" {syn.pred}: {syn.val}") # syn.pred is one of: hasExactSynonym, hasRelatedSynonym, # hasNarrowSynonym, hasBroadSynonym # Include label as a synonym object synonyms_with_label = ont.synonyms(term_id, include_label=True) # Get all synonyms across entire ontology all_synonyms = ont.all_synonyms() print(f"Total synonyms in ontology: {len(all_synonyms)}") # Get all synonyms including labels all_syns_with_labels = ont.all_synonyms(include_label=True) ``` ### Response #### Success Response (200) Returns a list of synonym objects, each containing a predicate (synonym type) and value (the synonym string). #### Response Example ```json [ { "pred": "hasExactSynonym", "val": "nuclear envelope" }, { "pred": "hasRelatedSynonym", "val": "nucleus" } ] ``` ``` -------------------------------- ### Initialize Ontology and Association Factories Source: https://github.com/biolink/ontobio/blob/master/notebooks/Mouse_Gene_Phenotypes.ipynb Create ontology and association set objects using the factory classes. These operations may take time as they connect to remote services. ```python from ontobio.ontol_factory import OntologyFactory # Create ontology object, for mammalian phenotype ontology # Transparently uses remote SPARQL service. # (May take a few seconds to run first time, Jupyter will show '*'. BE PATIENT, do # not re-execute cell) ofactory = OntologyFactory() ont = ofactory.create('mp') ``` ```python from ontobio.assoc_factory import AssociationSetFactory MOUSE = 'NCBITaxon:10090' # Create association set # Transparently uses remote Monarch service. # (May take a few seconds to run first time, Jupyter will show '*'. BE PATIENT, do # not re-execute cell) afactory = AssociationSetFactory() aset = afactory.create(ontology=ont, subject_category='gene', object_category='phenotype', taxon=MOUSE) ``` -------------------------------- ### Ontology.label - Get Node Labels Source: https://context7.com/biolink/ontobio/llms.txt Retrieve the human-readable label for an ontology node. Returns None if no label exists unless `id_if_null=True`. ```APIDOC ## Ontology.label - Get Node Labels ### Description Retrieve the human-readable label for an ontology node. Returns None if no label exists unless `id_if_null=True`. ### Method `label` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from ontobio.ontol_factory import OntologyFactory ont = OntologyFactory().create('go') # Get label for a term term_id = 'GO:0005634' label = ont.label(term_id) print(f"{term_id}: {label}") # GO:0005634: nucleus # Return ID if no label exists label = ont.label('UNKNOWN:123', id_if_null=True) print(label) # UNKNOWN:123 # Get text definition text_def = ont.text_definition(term_id) if text_def: print(f"Definition: {text_def.val}") # Check if term is obsolete is_obs = ont.is_obsolete(term_id) print(f"Is obsolete: {is_obs}") # Get replacement for obsolete term if is_obs: replacement = ont.replaced_by(term_id) print(f"Replaced by: {replacement}") ``` ### Response #### Success Response (200) Returns the label string for the given term ID, or the term ID itself if `id_if_null=True` and no label is found. #### Response Example ```json { "label": "nucleus" } ``` ``` -------------------------------- ### Get First 5 Subjects from Association Set Source: https://github.com/biolink/ontobio/blob/master/notebooks/GO_Functional_Similarity.ipynb Retrieves and displays the first 5 subjects from a previously created association set. ```python aset.subjects[0:5] ``` -------------------------------- ### Create Ontology Instance Source: https://github.com/biolink/ontobio/blob/master/notebooks/Map2Slim_GO.ipynb Instantiate a specific ontology, such as the Gene Ontology (GO). ```python ont = OntologyFactory().create('go') ``` -------------------------------- ### Get Annotations for a Mouse Subject Source: https://github.com/biolink/ontobio/blob/master/notebooks/GO_Functional_Similarity_using_AssocFiles.ipynb Retrieves and displays the annotations (GO terms) associated with a specific subject in the mouse association set. ```python asoc_mouse.annotations('MGI:MGI:1918911') ``` -------------------------------- ### Initialize ontology factory and load HPO Source: https://github.com/biolink/ontobio/blob/master/notebooks/Phenotype_Enrichment.ipynb Creates an ontology factory instance to load the Human Phenotype Ontology (HP). ```python ## Create an ontology factory in order to fetch HPO from ontobio.ontol_factory import OntologyFactory ofactory = OntologyFactory() ont = ofactory.create("hp") ## Load HP. Note the first time this runs Jupyter will show '*' - be patient ``` -------------------------------- ### Get Unmapped DataFrame Source: https://github.com/biolink/ontobio/blob/master/notebooks/Parse_RareList.ipynb Generates a DataFrame containing entries that could not be mapped. This is useful for identifying data that requires manual review or further processing. ```python udf = lexmap.unmapped_dataframe(g) ``` -------------------------------- ### Ontology.descendants - Get Descendant Nodes Source: https://context7.com/biolink/ontobio/llms.txt Retrieves all descendant node IDs for a given node, with options to filter by relation types and include the node itself. ```APIDOC ## Ontology.descendants - Get Descendant Nodes ### Description Returns all descendant node IDs for a specified node, traversing the ontology graph downward. Useful for finding all subtypes or parts of a concept. ### Method `ontology.descendants(node_id, relations=None, reflexive=False)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from ontobio.ontol_factory import OntologyFactory ont = OntologyFactory().create('go') # Get all descendants of a GO term cell_id = 'GO:0005623' # cell descendants = ont.descendants(cell_id) print(f"Descendants of cell: {len(descendants)} terms") # Get only direct subclasses (children) children = ont.children(cell_id, relations=['subClassOf']) print(f"Direct children: {len(children)}") # Include the query node (reflexive) descendants_reflexive = ont.descendants(cell_id, reflexive=True) # Get descendants filtered by relation type PART_OF = 'BFO:0000050' descendants_parts = ont.descendants(cell_id, relations=['subClassOf', PART_OF]) ``` ### Response #### Success Response (200) A set of descendant node IDs. #### Response Example ```json { "descendants": [ "GO:0005622", "GO:0005623", "GO:0005624" ] } ``` ``` -------------------------------- ### Manual Release PyPI Upload Source: https://github.com/biolink/ontobio/blob/master/README-developers.md Commands for building distribution files and uploading them to PyPI. Requires a PyPI token and a configured ~/.pypirc file. ```bash make cleandist python setup.py sdist bdist_wheel twine upload --repository-url https://upload.pypi.org/legacy/ --username __token__ dist/* ``` -------------------------------- ### Initialize OntologyFactory Source: https://github.com/biolink/ontobio/blob/master/notebooks/Find_All_Paths.ipynb Import and initialize the OntologyFactory from the ontobio library. This is the first step to accessing ontology data. ```python from ontobio import OntologyFactory ``` -------------------------------- ### Ontology.ancestors - Get Ancestor Nodes Source: https://context7.com/biolink/ontobio/llms.txt Retrieves all ancestor node IDs for a given node, with options to filter by relation types and include the node itself. ```APIDOC ## Ontology.ancestors - Get Ancestor Nodes ### Description Returns all ancestor node IDs for a specified node, optionally filtering by relation types. This traverses the ontology graph upward from the given node. ### Method `ontology.ancestors(node_id, relations=None, reflexive=False)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from ontobio.ontol_factory import OntologyFactory ont = OntologyFactory().create('go') # Get all ancestors of a GO term nucleus_id = 'GO:0005634' ancestors = ont.ancestors(nucleus_id) print(f"Ancestors of nucleus: {len(ancestors)} terms") # Get ancestors following only subClassOf relations ancestors_subclass = ont.ancestors(nucleus_id, relations=['subClassOf']) # Include the query node itself (reflexive) ancestors_reflexive = ont.ancestors(nucleus_id, reflexive=True) # Filter by specific relations (subClassOf and part_of) PART_OF = 'BFO:0000050' ancestors_filtered = ont.ancestors(nucleus_id, relations=['subClassOf', PART_OF]) for anc in list(ancestors_filtered)[:5]: print(f" {anc}: {ont.label(anc)}") ``` ### Response #### Success Response (200) A set of ancestor node IDs. #### Response Example ```json { "ancestors": [ "GO:0008374", "GO:0005575", "GO:0003674" ] } ``` ``` -------------------------------- ### Execute Query and Get Associations Source: https://github.com/biolink/ontobio/blob/master/notebooks/Lookup_KEGG_Genes_by_Pathway_Name.ipynb Execute the constructed GolrAssociationQuery to retrieve gene associations. The results are stored in the 'associations' key of the returned dictionary. ```python assocs = q.exec()['associations'] ``` -------------------------------- ### Load Ontologies Source: https://github.com/biolink/ontobio/blob/master/notebooks/Parse_RareList.ipynb Creates instances for HP and MONDO ontologies. ```python hp = ofa.create('obo:hp') ``` ```python mondo = ofa.create('obo:mondo') ``` -------------------------------- ### Helpful Poetry Commands Source: https://github.com/biolink/ontobio/blob/master/README-developers.md A collection of common Poetry commands for managing dependencies and environments. ```bash poetry install # install dependencies from poetry.lock ``` ```bash poetry run # run a command in the poetry virtual environment ``` ```bash poetry env list # list all virtual environments and tags the one currently in use for the project ``` ```bash poetry show --why --tree [pypi_package_name] # show the dependency tree for pypi_package_name ``` ```bash poetry show [pypi_package_name] # show the version of pypi_package_name that is install in the current venv. ``` -------------------------------- ### Create Ontology Instance Source: https://github.com/biolink/ontobio/blob/master/notebooks/Remote_Ontology.ipynb Instantiate OntologyFactory and create an ontology object. Connects remotely to PATO over SPARQL. Note: Jupyter may show '*' indicating kernel busy during fetch. ```python from ontobio.ontol_factory import OntologyFactory ofactory = OntologyFactory() ont = ofactory.create("pato") ## Connect remotely to PATO over SPARQL ## ## Note: Jupyter may show '*' to indicate kernel busy while this is being ## fetched - should only take a few seconds. Wait before proceeding ``` -------------------------------- ### Create AssociationSet from File Source: https://github.com/biolink/ontobio/blob/master/docs/api.md Initializes an AssociationSet from a file. The format can be inferred from the file extension or specified explicitly. Supports GAF format by default. ```python create_from_file(file=None, fmt='gaf', skim=True, **args) ``` -------------------------------- ### Get Inferred Types for Subject Source: https://github.com/biolink/ontobio/blob/master/docs/api.md Returns a set of reflexive inferred types (including ancestors) for a given subject ID. This method is called on initialization. ```python inferred_types(subj) ``` -------------------------------- ### Align Ontologies and Get Xref Graph Source: https://github.com/biolink/ontobio/blob/master/notebooks/Parse_RareList.ipynb Aligns the configured ontologies and retrieves the cross-reference graph. This is typically done after indexing and configuring mapping pairs. ```python # align g = lexmap.get_xref_graph() ``` -------------------------------- ### Initialize Tree Renderer Source: https://github.com/biolink/ontobio/blob/master/notebooks/Summarize_GOTerm_Descendants.ipynb Creates an instance of the Tree renderer for visualizing ontology subgraphs. Note that this renderer may not scale well for complex or 'latticey' sub-ontologies. ```python renderer = GraphRenderer.create('tree') ``` -------------------------------- ### Parse GAF Files Source: https://context7.com/biolink/ontobio/llms.txt Initializes the GAF parser for GO Annotation Format files. ```python from ontobio.io.gafparser import GafParser from ontobio.io.assocparser import AssocParserConfig ``` -------------------------------- ### Get Label and Synonyms for a Term Source: https://context7.com/biolink/ontobio/llms.txt Retrieves the human-readable label and all synonyms for a given ontology term ID. Includes synonym values and their prediction types. ```python for term_id in results[:3]: label = ont.label(term_id) syns = ont.synonyms(term_id) print(f"{term_id}: {label}") for syn in syns: print(f" Synonym: {syn.val} ({syn.pred})") ``` -------------------------------- ### Get Publications for a Gene Source: https://github.com/biolink/ontobio/blob/master/notebooks/TF_Pub_Analysis.ipynb Fetches all publication IDs (PMIDs) associated with a given gene from both Monarch and GO. It iterates through associations and extracts publication information. ```python # Routine to go to GO and Monarch to fetch all annotations for a gene def get_pubs_for_gene(g): # Monarch r = ga.search_associations(subject=g, rows=-1) pubs = set() for a in r['associations']: pl = a['publications'] if pl is not None: pubs.update([p['id'] for p in pl if p['id'].startswith('PMID')]) # GO r = ga.search_associations(subject=g, rows=-1, object_category='function') for a in r['associations']: pl = a['reference'] if pl is not None: pubs.update([p for p in pl if p.startswith('PMID')]) return pubs len(get_pubs_for_gene(tf_genes[0])) ``` -------------------------------- ### Iterate and Print Ontology Terms Source: https://github.com/biolink/ontobio/blob/master/notebooks/Map2Slim_GO.ipynb Display the first 20 GO terms and their corresponding mapped relations. ```python # show the first 20 GO terms plus their mappings for n in ont.nodes()[0:20]: if n.startswith('GO:'): print('{} {}'.format(n, ont.label(n))) for x in m[n]: print(' --> {} {}'.format(x, ont.label(x))) ``` -------------------------------- ### Get Labels for Nodes with Maximum Path Count Source: https://github.com/biolink/ontobio/blob/master/notebooks/Find_All_Paths.ipynb Retrieves the human-readable labels for a list of node IDs, typically used after identifying nodes with specific characteristics. ```python [ont.label(n) for n in nodes_with_max] ``` -------------------------------- ### Translate GPAD to GO-CAM models Source: https://github.com/biolink/ontobio/blob/master/ontobio/rdfgen/gocamgen/README.md Executes the gpad2gocams command to generate GO-CAM models from GPAD and GPI source files. ```bash bin/validate.py -v gpad2gocams --gpad_path gpad2.0.zfin --gpi_path zfin.gpi2 --target target/zfin_models/ --ontology go.json --ontology ro.json --ttl ``` -------------------------------- ### Create HPO Ontology Object Source: https://github.com/biolink/ontobio/blob/master/notebooks/Find_All_Paths.ipynb Get the Human Phenotype Ontology (HPO) using the OntologyFactory. The first retrieval may take some time as data is cached. ```python ofa = OntologyFactory() ont = ofa.create('hp') ``` -------------------------------- ### Initialize Ontology and AssociationSet Objects Source: https://github.com/biolink/ontobio/blob/master/docs/analyses.md Fetch an Ontology object and an AssociationSet object for enrichment analysis. Supports local files or remote services. Ensure gene IDs in the AssociationSet match those used for enrichment. ```python from ontobio import OntologyFactory from ontobio import AssociationSetFactory ofactory = OntologyFactory() afactory = AssociationSetFactory() ont = ofactory.create('go') aset = afactory.create_from_gaf('my.gaf', ontology=ont) ``` -------------------------------- ### Synchronize local master branch with upstream Source: https://github.com/biolink/ontobio/blob/master/CONTRIBUTING.md Resets the local master branch to match the upstream master branch, ensuring a clean starting point for new development. ```bash > git checkout master > git reset --hard upstream/master ``` -------------------------------- ### Verify URL Mapping Source: https://github.com/biolink/ontobio/blob/master/notebooks/Parse_RareList.ipynb Inspects the first 10 entries of the name-to-URL mapping. ```python ## sanity check URL mapping list(name2url.items())[0:10] ``` -------------------------------- ### Initialize GolrAssociationQuery Source: https://github.com/biolink/ontobio/blob/master/notebooks/Lookup_KEGG_Genes_by_Pathway_Name.ipynb Import and initialize GolrAssociationQuery for retrieving gene associations. This is used after obtaining pathway matches. ```python from ontobio.golr.golr_query import GolrAssociationQuery ``` -------------------------------- ### Example Gene Score Output Source: https://github.com/biolink/ontobio/blob/master/notebooks/Gene_Expression.ipynb Displays a sample output of gene scores, formatted as a list of tuples. Each tuple represents a gene with its identifier, symbol, and a numerical score. ```python Result: [('MGI:95590', 'Ftl2-ps', 0.2), ('MGI:1098641', 'Wasf2', 0.25), ('MGI:3644452', 'Gm9083', 0.125), ('MGI:3651858', 'Gm11337', 1.0), ('MGI:3702318', 'Gm11989', 0.25), ('MGI:1916396', 'Gsdmd', 0.25), ('MGI:2443767', 'Aaas', 0.25), ('MGI:2137698', 'Ugt1a6a', 0.125), ('MGI:1351659', 'Abcg5', 0.2), ('MGI:3705426', 'Rpl21-ps15', 0.25), ('MGI:1914745', 'Tmem167b', 0.16666666666666666), ('MGI:1347249', 'Psg16', 0.25), ('MGI:3818630', 'Sco2', 0.2), ('MGI:1919235', 'Acad10', 0.09090909090909091), ('MGI:3780170', 'Gm2000', 0.3333333333333333), ('MGI:1343095', 'Emc8', 0.25), ('MGI:5454530', 'Gm24753', 0.5), ('MGI:3649027', 'Gm7117', 0.2), ('MGI:5454475', 'Gm24698', 0.3333333333333333), ('MGI:4415000', 'Gm16580', 0.16666666666666666), ('MGI:3646089', 'Gm7803', 0.14285714285714285), ('MGI:97987', 'Rnu3b3', 0.25), ('MGI:1353433', 'Timm8a1', 0.25), ('MGI:3649865', 'Rpl23a-ps14', 0.16666666666666666), ('MGI:106686', 'Pon3', 0.5), ('MGI:88216', 'Btk', 0.3333333333333333), ('MGI:3704359', 'Gm9803', 0.2), ('MGI:3780980', 'Gm2810', 0.16666666666666666), ('MGI:2140962', 'Ugt2b34', 0.3333333333333333), ('MGI:2444981', 'Phldb2', 0.2), ('MGI:3644778', 'Gm8738', 0.16666666666666666), ('MGI:88054', 'Apoc2', 0.2), ('MGI:3649201', 'Gm12396', 0.125), ('MGI:5451834', 'Gm22057', 0.5), ('MGI:1861354', 'Apbb1ip', 0.2), ('MGI:5804868', 'Gm45753', 1.0), ('MGI:891967', 'Serpina1e', 0.2), ('MGI:2138853', 'AI182371', 0.5), ('MGI:3041196', 'Fam198a', 0.25), ('MGI:1913761', 'Chtop', 0.16666666666666666), ('MGI:3783208', 'Gm15766', 0.14285714285714285), ('MGI:2385276', 'Kctd15', 0.2), ('MGI:1927868', 'Pex14', 0.14285714285714285), ('MGI:1888526', 'Xpo4', 0.09090909090909091), ('MGI:5455017', 'Gm25240', 0.5), ('MGI:1913534', 'Gkn2', 0.16666666666666666), ('MGI:1930008', 'Ghrl', 0.14285714285714285), ('MGI:2385008', 'Ggact', 0.25), ('MGI:1921821', 'Kcnk16', 0.3333333333333333), ('MGI:96611', 'Itgb2', 0.14285714285714285), ('MGI:894286', 'P4ha2', 0.25), ('MGI:5455293', 'Gm25516', 0.25), ('MGI:1922466', 'Cep128', 0.125), ('MGI:3645079', 'Gm16470', 0.25), ('MGI:3645628', 'Gm8019', 0.2), ('MGI:3647773', 'Gm6498', 0.3333333333333333), ('MGI:3819557', 'Snord83b', 0.16666666666666666), ('MGI:1914709', 'Nvl', 0.14285714285714285), ('MGI:4937849', 'Gm17022', 0.2), ('MGI:3583955', 'Rdh16f2', 0.16666666666666666), ('MGI:2138968', 'Clp1', 0.16666666666666666), ('MGI:5453898', 'Gm24121', 1.0), ('MGI:1915442', 'Leprotl1', 0.16666666666666666), ('MGI:3779824', 'Gm8941', 1.0), ('MGI:3650622', 'Gm12338', 0.2), ('MGI:2444508', 'Fitm2', 0.16666666666666666), ('MGI:5455452', 'Gm25675', 0.5), ('MGI:5454373', 'Gm24596', 0.3333333333333333), ('MGI:1096324', 'Lst1', 0.2), ('MGI:2159614', 'Mia2', 0.2), ('MGI:1918956', 'Slc46a3', 0.14285714285714285), ('MGI:3649696', 'Rps8-ps2', 0.125), ('MGI:3644876', 'Rps2-ps6', 0.2), ('MGI:5453824', 'Gm24047', 0.5), ('MGI:3649769', 'Gm12355', 0.2), ('MGI:2445040', 'Tyw3', 0.16666666666666666), ('MGI:5452129', 'Gm22352', 0.3333333333333333), ('MGI:1196423', 'Onecut1', 1.0), ('MGI:97620', 'Plg', 0.25), ('MGI:3643679', 'Gm8682', 0.2), ('MGI:95856', 'Gsta3', 0.16666666666666666), ('MGI:5455590', 'Gm25813', 0.3333333333333333), ('MGI:3651301', 'Gm14107', 0.5), ('MGI:105103', 'Rprl3', 0.25), ('MGI:5454298', 'Gm24521', 0.5), ('MGI:1915951', 'Ppp1r27', 0.3333333333333333), ('MGI:106636', 'Atp5k', 0.25), ('MGI:3704327', 'Gm10182', 0.125), ('MGI:3651595', 'Gm11295', 0.25), ('MGI:3652326', 'Gm13902', 0.3333333333333333), ('MGI:3718464', 'Mir291b', 0.16666666666666666), ('MGI:1918982', 'Vps11', 0.3333333333333333), ('MGI:5454076', 'Gm24299', 0.3333333333333333), ('MGI:1350917', 'Rps3', 0.125), ('MGI:1913638', 'Cutc', 0.14285714285714285), ('MGI:1914195', 'Sdha', 0.125), ('MGI:1915254', 'Tmem9b', 0.25), ('MGI:3779470', 'Ces1b', 0.3333333333333333), ('MGI:5454859', 'Gm25082', 0.16666666666666666), ('MGI:1926264', 'Tspan6', 0.2), ('MGI:3651503', 'Gm13862', 0.2), ('MGI:95862', 'Gstm4', 0.125), ('MGI:2444947', 'Mical2', 0.2), ('MGI:5504138', 'Gm27023', 0.14285714285714285), ('MGI:5434102', 'Gm23629', 1.0), ('MGI:3651534', 'Gm12258', 0.3333333333333333), ('MGI:3705806', 'Gm14536', 0.16666666666666666), ('MGI:1921611', '4931429L15Rik', 0.3333333333333333), ('MGI:3642824', 'Rpl9-ps7', 0.14285714285714285), ('MGI:1278340', 'Rpl21', 0.125), ('MGI:4834232', 'Mir3060', 1.0), ('MGI:107508', 'Ereg', 0.2), ('MGI:88343', 'Cd69', 0.16666666666666666), ('MGI:3650581', 'Gm12419', 0.2), ('MGI:3610314', 'Scimp', 0.3333333333333333), ('MGI:1098779', 'Cdk2ap2', 0.1111111111111111), ('MGI:2144766', 'Slc25a47', 0.125), ('MGI:2138935', 'Fam102a', 0.3333333333333333), ('MGI:5434102', 'Ftl1-ps2', 0.5), ('MGI:1925560', '1810024B03Rik', 0.16666666666666666), ('MGI:3704487', 'Amd-ps3', 0.25)] ``` -------------------------------- ### Get ECO Class Ancestors Source: https://github.com/biolink/ontobio/blob/master/notebooks/Map_Evidence_Codes.ipynb Retrieve a list of all ancestor classes for a given ECO class, including their labels. This helps in understanding the hierarchical context of an evidence type. ```python ["{} '{}'".format(c, ontol.label(c)) for c in ontol.ancestors(cls)] ``` -------------------------------- ### Get Term Synonyms Source: https://context7.com/biolink/ontobio/llms.txt Retrieves all synonyms for a given ontology class, including their type (exact, related, narrow, broad). Can optionally include the term's primary label. ```python from ontobio.ontol_factory import OntologyFactory ont = OntologyFactory().create('go') # Get synonyms for a term term_id = 'GO:0005634' synonyms = ont.synonyms(term_id) for syn in synonyms: print(f" {syn.pred}: {syn.val}") # syn.pred is one of: hasExactSynonym, hasRelatedSynonym, # hasNarrowSynonym, hasBroadSynonym # Include label as a synonym object synonyms_with_label = ont.synonyms(term_id, include_label=True) # Get all synonyms across entire ontology all_synonyms = ont.all_synonyms() print(f"Total synonyms in ontology: {len(all_synonyms)}") # Get all synonyms including labels all_syns_with_labels = ont.all_synonyms(include_label=True) ``` -------------------------------- ### Generate lexical mappings with ontobio-lexmap.py Source: https://context7.com/biolink/ontobio/llms.txt Create mappings between local or remote ontologies and output the results as a TSV file. ```bash # Map between two local ontology files ontobio-lexmap.py ont1.json ont2.json > mappings.tsv # Map between remote ontologies (via SPARQL) ontobio-lexmap.py mp hp > mp-hp-mappings.tsv # Map multiple ontologies ontobio-lexmap.py mp hp wbphenotype > phenotype-mappings.tsv ``` -------------------------------- ### Render Sub-ontology with Highlighted Path Source: https://github.com/biolink/ontobio/blob/master/notebooks/Find_All_Paths.ipynb Renders a sub-ontology to a PNG file, highlighting a specified sample path. Requires the `GraphRenderer` class and a defined sub-ontology and sample path. ```python from ontobio.io.ontol_renderers import GraphRenderer w = GraphRenderer.create('png') w.outfile = 'output/multipath.png' w.write(subont,query_ids=sample_path) ``` -------------------------------- ### Search with regex using ogr Source: https://context7.com/biolink/ontobio/llms.txt Perform regex-based searches on ontology terms using the ogr command. ```bash ogr -r cl -s r ^neuron # Starts with 'neuron' ogr -r cl -s r neuron$ # Ends with 'neuron' ``` -------------------------------- ### Get Node Labels and Definitions Source: https://context7.com/biolink/ontobio/llms.txt Retrieves the human-readable label for an ontology node. Optionally returns the node ID if no label exists. Also fetches text definitions and checks for obsolescence. ```python from ontobio.ontol_factory import OntologyFactory ont = OntologyFactory().create('go') # Get label for a term term_id = 'GO:0005634' label = ont.label(term_id) print(f"{term_id}: {label}") # GO:0005634: nucleus # Return ID if no label exists label = ont.label('UNKNOWN:123', id_if_null=True) print(label) # UNKNOWN:123 # Get text definition text_def = ont.text_definition(term_id) if text_def: print(f"Definition: {text_def.val}") # Check if term is obsolete is_obs = ont.is_obsolete(term_id) print(f"Is obsolete: {is_obs}") # Get replacement for obsolete term if is_obs: replacement = ont.replaced_by(term_id) print(f"Replaced by: {replacement}") ``` -------------------------------- ### Configure SciGraph Connection Source: https://github.com/biolink/ontobio/blob/master/notebooks/Lookup_KEGG_Genes_by_Pathway_Name.ipynb Set up the configuration for connecting to SciGraph by mapping a handle to a URL using a YAML config file. Ensure the config file path is correct. ```python from ontobio.config import set_config set_config('../conf/config.yaml') ``` -------------------------------- ### Create AssociationSet from File Source: https://github.com/biolink/ontobio/blob/master/docs/inputs.md Use AssociationSetFactory to create an association set from a local file. ```python afactory = AssociationSetFactory() aset = afactory.create_from_file(file=args.assocfile,ontology=ont) ``` -------------------------------- ### Run Gene Function Enrichment using ontobio-assoc.py Source: https://github.com/biolink/ontobio/blob/master/docs/analyses.md Perform gene function enrichment analysis using the ontobio-assoc.py script. This example uses a gene ID list and the GO ontology for enrichment testing. ```console # enrichment, using GO ontobio-assoc.py -r go -T NCBITaxon:10090 -C gene function enrichment -s genes.ids ``` -------------------------------- ### Run Makefile Release Target Source: https://github.com/biolink/ontobio/blob/master/README-developers.md Execute the 'release' target in the Makefile to automate the release process. Ensure the USER environment variable is set to your PyPI username. ```bash $ make USER=sauron release ``` -------------------------------- ### Initialize EcoMap for GO GAF to ECO Mapping Source: https://github.com/biolink/ontobio/blob/master/notebooks/Map_Evidence_Codes.ipynb Create an EcoMap object to facilitate mapping between GO GAF codes and ECO classes. This is the primary object for performing the mappings. ```python ## Create an EcoMap object, for mapping to and from ECO classes from ontobio.ecomap import EcoMap m = EcoMap() ``` -------------------------------- ### Query associations from a file Source: https://github.com/biolink/ontobio/blob/master/docs/commandline.md Performs a query on a local GAF file for a specific GO term. ```default ontobio-assoc -C gene function -T pombe -r go -f tests/resources/truncated-pombase.gaf query -q GO:0005622 ``` -------------------------------- ### Query remote ontologies and associations in Python Source: https://github.com/biolink/ontobio/blob/master/docs/quickstart.md Demonstrates initializing an ontology and association set to query gene annotations. ```python from ontobio.ontol_factory import OntologyFactory from ontobio.assoc_factory import AssociationSetFactory ## label IDs for convenience MOUSE = 'NCBITaxon:10090' NUCLEUS = 'GO:0005634' TRANSCRIPTION_FACTOR = 'GO:0003700' PART_OF = 'BFO:0000050' ## Create an ontology object containing all of GO, with relations filtered ofactory = OntologyFactory() ont = ofactory.create('go').subontology(relations=['subClassOf', PART_OF]) ## Create an AssociationSet object with all mouse GO annotations afactory = AssociationSetFactory() aset = afactory.create(ontology=ont, subject_category='gene', object_category='function', taxon=MOUSE) genes = aset.query([TRANSCRIPTION_FACTOR],[NUCLEUS]) print("Mouse TF genes NOT annotated to nucleus: {}".format(len(genes))) for g in genes: print(" Gene: {} {}".format(g,aset.label(g))) ``` -------------------------------- ### Initialize Ontology Object for ECO Class Lookups Source: https://github.com/biolink/ontobio/blob/master/notebooks/Map_Evidence_Codes.ipynb Optionally, create an ontology object for ECO. This is useful for retrieving ECO class labels and parentage information, enhancing the understanding of mapped classes. ```python ## Create an ontology object for ECO; ## This is optional; we use this in this notebook ## to look up ECO class labels, and parentage from ontobio.ontol_factory import OntologyFactory ontol = OntologyFactory().create('eco') ``` -------------------------------- ### Run full validation test suite Source: https://github.com/biolink/ontobio/blob/master/bin/README.md Executes the full validate.produce command using multiple sources via a makefile target. ```bash make test_travis_full ``` -------------------------------- ### Fetch Uberon Ontology Source: https://github.com/biolink/ontobio/blob/master/notebooks/Uberon_mappings.ipynb Initializes the OntologyFactory to connect to the Uberon ontology via SPARQL. ```python ## First fetch ontology from ontobio.ontol_factory import OntologyFactory ofactory = OntologyFactory() ont = ofactory.create("uberon") ## Connect remotely to Uberon over SPARQL ## ## Note: Jupyter may show '*' to indicate kernel busy while this is being ## fetched - should only take a few seconds. Wait before proceeding ```