bionty.Bionty#

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

Bases: object

Bionty base model.

Attributes

fields :class:`~<class 'property'>`#

All Bionty entity fields.

source :class:`~<class 'property'>`#

Name of the source.

species :class:`~<class 'property'>`#

The name of Species Bionty.

version :class:`~<class '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()
fuzzy_match(string, field='name', synonyms_field='synonyms', case_sensitive=True, return_ranked_results=False)#

Fuzzy matching of a given string against a Bionty field.

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

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

  • synonyms_field – Also map against in the synonyms (If None, no mapping against synonyms).

  • case_sensitive – Whether the match is case sensitive.

  • return_ranked_results – Whether to return all entries ranked by matching ratios.

Return type:

DataFrame

Returns:

Best match of the input string.

Examples

>>> import bionty as bt
>>> celltype_bionty = bt.CellType()
>>> celltype_bionty.fuzzy_match("gamma delta T cell")
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 Ontology.

  • 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 that maps the input ontology (keys) to the ontology field (values)

  • If specified A Pandas DataFrame with the curated index and a boolean __mapped__ column that indicates compliance with the default identifier.

Examples

>>> import bionty as bt
>>> celltype_bionty = bt.CellType()
>>> celltype_bionty.inspect(["Boettcher cell", "bone marrow cell"], field=celltype_bionty.name)
lookup(field='name')#

Return an auto-complete object for the 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.Gene().lookup()
>>> lookup.adgb_dt
>>> lookup_dict = lookup.dict()
>>> lookup['ADGB-DT']
map_synonyms(identifiers, field, *, synonyms_field='synonyms', return_mapper=False)#

Maps input identifiers against Ontology synonyms.

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

  • field – The BiontyField of ontology representing the identifiers.

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

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(source="ensembl", version="release-108")
>>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"]
>>> mapping = gene_bionty.map_synonyms(gene_symbols, gn.symbol)