biocontext_kb.core.ols#

Functions#

get_available_ontologies()

Query OLS for all available ontologies with their metadata. Use this first to discover available ontologies.

get_cell_ontology_terms(cell_type[, size, exact_match])

Search OLS for Cell Ontology (CL) terms using a controlled vocabulary for cell types.

get_chebi_terms_by_chemical(chemical_name[, size, ...])

Search OLS for ChEBI (Chemical Entities of Biological Interest) terms for a chemical or drug name.

get_efo_id_by_disease_name(disease_name[, size, ...])

Search OLS for EFO/Mondo/HP IDs related to a disease name. Use this to get EFO IDs for Open Targets queries.

get_go_terms_by_gene(gene_name[, size, exact_match])

Search OLS for Gene Ontology (GO) terms related to a gene name using structured vocabularies.

get_term_details(term_id, ontology_id)

Get comprehensive details about a specific ontology term including definition, synonyms, hierarchical relationships.

get_term_hierarchical_children(term_id, ontology_id[, ...])

Get hierarchical children of an ontology term from OLS. Includes subclasses and hierarchical properties.

search_ontology_terms(search_term[, ontologies, size, ...])

Search for terms across multiple ontologies in OLS. Use get_available_ontologies() first to discover ontologies.

Package Contents#

biocontext_kb.core.ols.get_available_ontologies()#

Query OLS for all available ontologies with their metadata. Use this first to discover available ontologies.

Returns:

Ontologies list with id, name, description, prefix, homepage, number of terms, status or error message.

Return type:

dict

biocontext_kb.core.ols.get_cell_ontology_terms(cell_type, size=10, exact_match=False)#

Search OLS for Cell Ontology (CL) terms using a controlled vocabulary for cell types.

Returns:

Cell ontology terms with cl_terms array containing id, label, definition, synonyms or error message.

Return type:

dict

Parameters:
  • cell_type (Annotated[str, Field(description="Cell type to search for (e.g., 'T cell', 'neuron')")])

  • size (Annotated[int, Field(description='Maximum number of results to return')])

  • exact_match (Annotated[bool, Field(description='Whether to perform exact match search')])

biocontext_kb.core.ols.get_chebi_terms_by_chemical(chemical_name, size=10, exact_match=False)#

Search OLS for ChEBI (Chemical Entities of Biological Interest) terms for a chemical or drug name.

Returns:

ChEBI terms with chebi_terms array containing id, label, description, synonyms or error message.

Return type:

dict

Parameters:
  • chemical_name (Annotated[str, Field(description="Chemical or drug name to search for (e.g., 'aspirin', 'glucose')")])

  • size (Annotated[int, Field(description='Maximum number of results to return')])

  • exact_match (Annotated[bool, Field(description='Whether to perform exact match search')])

biocontext_kb.core.ols.get_efo_id_by_disease_name(disease_name, size=5, exact_match=False)#

Search OLS for EFO/Mondo/HP IDs related to a disease name. Use this to get EFO IDs for Open Targets queries.

Returns:

EFO IDs with efo_ids array containing id, label, description or error message.

Return type:

dict

Parameters:
  • disease_name (Annotated[str, Field(description="Disease name to search for (e.g., 'choledocholithiasis')")])

  • size (Annotated[int, Field(description='Maximum number of results to return')])

  • exact_match (Annotated[bool, Field(description='Whether to perform exact match search')])

biocontext_kb.core.ols.get_go_terms_by_gene(gene_name, size=10, exact_match=False)#

Search OLS for Gene Ontology (GO) terms related to a gene name using structured vocabularies.

Returns:

GO terms with go_terms array containing id, label, description, type or error message.

Return type:

dict

Parameters:
  • gene_name (Annotated[str, Field(description="Gene name or symbol to search for (e.g., 'TP53', 'BRCA1')")])

  • size (Annotated[int, Field(description='Maximum number of results to return')])

  • exact_match (Annotated[bool, Field(description='Whether to perform exact match search')])

biocontext_kb.core.ols.get_term_details(term_id, ontology_id)#

Get comprehensive details about a specific ontology term including definition, synonyms, hierarchical relationships.

Returns:

Term details with id, label, definition, synonyms, hierarchical info, num_descendants or error message.

Return type:

dict

Parameters:
  • term_id (Annotated[str, Field(description="Term ID in CURIE format (e.g., 'EFO:0000001', 'GO:0008150')")])

  • ontology_id (Annotated[str, Field(description="Ontology ID where the term is defined (e.g., 'efo', 'go', 'chebi')")])

biocontext_kb.core.ols.get_term_hierarchical_children(term_id, ontology_id, size=20)#

Get hierarchical children of an ontology term from OLS. Includes subclasses and hierarchical properties.

Returns:

Parent term, hierarchical_children array with id/label/definition, total_children, page_info or error message.

Return type:

dict

Parameters:
  • term_id (Annotated[str, Field(description="Term ID in CURIE format (e.g., 'EFO:0000001', 'GO:0008150')")])

  • ontology_id (Annotated[str, Field(description="Ontology ID (e.g., 'efo', 'go', 'chebi')")])

  • size (Annotated[int, Field(description='Maximum number of children to return')])

biocontext_kb.core.ols.search_ontology_terms(search_term, ontologies='', size=20, exact_match=False)#

Search for terms across multiple ontologies in OLS. Use get_available_ontologies() first to discover ontologies.

Returns:

Terms array, terms_by_ontology grouped results, total_results, ontologies_found list or error message.

Return type:

dict

Parameters:
  • search_term (Annotated[str, Field(description='Term to search for')])

  • ontologies (Annotated[str, Field(description="Comma-separated ontology IDs (e.g., 'efo,go,chebi'). Leave empty for all. Use get_available_ontologies() to see options")])

  • size (Annotated[int, Field(description='Maximum number of results to return')])

  • exact_match (Annotated[bool, Field(description='Whether to perform exact match search')])