bionty.Bionty#

class bionty.Bionty(source=None, version=None, species=None, *, include_id_prefixes=None)#

Bases: object

Bionty base model.

Attributes

fields property#

All Bionty entity fields.

source property#

Name of the source.

species property#

The name of Species Bionty.

version property#

The name of version entity Bionty.

Methods

df()#

Pandas DataFrame of the ontology.

Return type:

DataFrame

Returns:

A Pandas DataFrame of the ontology.

Examples

>>> import bionty as bt
>>> bt.Gene().df()
inspect(identifiers, field, return_df=False)#

Inspect if a list of identifiers are mappable to the entity reference.

Parameters:
  • identifiers – Identifiers that will be checked against the field.

  • field – The BiontyField of the ontology to compare against. Examples are ‘ontology_id’ to map against the ontology ID or ‘name’ to map against the ontologies field names.

  • return_df – Whether to return a Pandas DataFrame.

Return type:

Union[DataFrame, Dict[str, List[str]]]

Returns:

  • A Dictionary of “mapped” and “unmapped” identifiers

  • If return_df: A DataFrame indexed by identifiers with a boolean __mapped__ column that indicates compliance with the identifiers.

Examples

>>> import bionty as bt
>>> gene_bionty = bt.Gene()
>>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"]
>>> gene_bionty.inspect(gene_symbols, field=gene_bionty.symbol)
lookup(field=None)#

An auto-complete object for a Bionty field.

Parameters:

field – The field to lookup the values for. Defaults to ‘name’.

Return type:

Tuple

Returns:

A NamedTuple of lookup information of the field values.

Examples

>>> import bionty as bt
>>> lookup = bt.CellType().lookup()
>>> lookup.cd103_positive_dendritic_cell
>>> lookup_dict = lookup.dict()
>>> lookup['CD103-positive dendritic cell']
map_synonyms(identifiers, *, return_mapper=False, synonyms_field='synonyms', synonyms_sep='|', field=None)#

Maps input identifiers against synonyms.

Parameters:
  • identifiers – Identifiers that will be mapped against an Ontology field (BiontyField).

  • return_mapper – Whether to return a dictionary of {identifiers : <mapped field values>}.

  • synonyms_field – The BiontyField representing the concatenated synonyms.

  • synonyms_sep – Which separator is used to separate synonyms.

  • field – The BiontyField representing the identifiers.

Return type:

Union[Dict[str, str], List[str]]

Returns:

  • A list of mapped field values if return_mapper is False.

  • A dictionary of mapped values with mappable identifiers as keys and values mapped to field as values if return_mapper is True.

Examples

>>> import bionty as bt
>>> gene_bionty = bt.Gene()
>>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"]
>>> standardized_symbols = gene_bionty.map_synonyms(gene_symbols, gn.symbol)
search(string, field=None, top_hit=False, case_sensitive=True, synonyms_field='synonyms', synonyms_sep='|')#

Search a given string against a Bionty field.

Parameters:
  • string – The input string to match against the field values.

  • field – The BiontyField of ontology the input string is matching against.

  • top_hit – Default is False, return all entries ranked by matching ratios. If True, only return the top match.

  • case_sensitive – Whether the match is case sensitive.

  • synonyms_field – By default also search against the synonyms (If None, skips search).

  • synonyms_sep – Which separator is used to separate synonyms.

Return type:

DataFrame

Returns:

Ranked search results.

Examples

>>> import bionty as bt
>>> celltype_bionty = bt.CellType()
>>> celltype_bionty.search("gamma delta T cell")