bionty.core.PublicOntology

class bionty.core.PublicOntology(source=None, version=None, organism=None, *, include_id_prefixes=None, **kwargs)

Bases: object

PublicOntology object.

Attributes

fields set

All PublicOntology entity fields.

organism property

The name of Organism.

source property

Name of the source.

version property

Version of the source.

Methods

df()

Pandas DataFrame of the ontology.

Return type:

DataFrame

Returns:

A Pandas DataFrame of the ontology.

Examples

>>> import bionty_base as bt
>>> bt.Gene().df()
diff(compare_to, **kwargs)

Determines a diff between two PublicOntology objects’ ontologies.

Parameters:
  • compare_to (PublicOntology) – PublicOntology object that must be of the same class as the calling object.

  • kwargs – Are passed to pd.DataFrame.compare()

Return type:

tuple[DataFrame, DataFrame]

Returns:

A tuple of two DataFrames

  1. New entries.

  2. A pd.DataFrame.compare result which denotes all changes in self and other.

Examples

>>> import bionty_base as bt
>>> public_1 = bt.Disease(source="mondo", version="2023-04-04")
>>> public_2 = bt.Disease(source="mondo", version="2023-04-04")
>>> new_entries, modified_entries = public_1.diff(public_2)
>>> print(new_entries.head())
>>> print(modified_entries.head())
inspect(values, field, *, mute=False, **kwargs)

Inspect a list of values against a field of entity reference.

Parameters:
  • values (Iterable) – Identifiers that will be checked against the field.

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

  • return_df – Whether to return a Pandas DataFrame.

  • mute (bool, default: False) – Whether to suppress logging. Defaults to False.

  • kwargs – Used for backwards compatibility and return types.

Return type:

InspectResult

Returns:

  • A Dictionary of “validated” and “not_validated” identifiers

  • If return_df: A DataFrame indexed by identifiers with a boolean

    __validated__ column indicating compliance validation.

Examples

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

An auto-complete object for a PublicOntology field.

Parameters:

field (PublicOntologyField | str | None, default: None) – 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_base as bt
>>> lookup = bt.CellType().lookup()
>>> lookup.cd103_positive_dendritic_cell
>>> lookup_dict = lookup.dict()
>>> lookup['CD103-positive dendritic cell']
map_synonyms(values, *, return_mapper=False, case_sensitive=False, keep='first', synonyms_field='synonyms', field=None)

Maps input synonyms to standardized names.

Return type:

dict[str, str] | list[str]

search(string, *, field=None, limit=None, case_sensitive=False, synonyms_field='synonyms')

Search a given string against a PublicOntology field.

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

  • field (PublicOntologyField | str | None, default: None) – The PublicOntologyField of the ontology the input string is matching against.

  • top_hit – Return all entries ranked by matching ratios. If True, only return the top match. Defaults to False.

  • limit (int | None, default: None) – Maximum amount of top results to return. If None, return all results. Defaults to None.

  • case_sensitive (bool, default: False) – Whether the match is case sensitive.

  • synonyms_field (PublicOntologyField | str | None, default: 'synonyms') – By default also search against the synonyms (If None, skips search).

Returns:

Ranked search results.

Examples

>>> import bionty_base as bt
>>> public = bt.CellType()
>>> public.search("gamma delta T cell")
standardize(values, field=None, *, return_field=None, return_mapper=False, case_sensitive=False, mute=False, keep='first', synonyms_field='synonyms')

Convert into standardized names.

Parameters:
  • values (Iterable) – Iterable Synonyms that will be standardized.

  • field (PublicOntologyField | str | None, default: None) – Optional[str] The field representing the standardized names.

  • return_field (str | None, default: None) – Optional[str] The field to return. Defaults to field.

  • return_mapper (bool, default: False) – bool = False If True, returns {input_synonym1: standardized_name1}.

  • case_sensitive (bool, default: False) – bool = False Whether the mapping is case sensitive.

  • keep (Literal['first', 'last', False], default: 'first') – Literal["first", "last", False] = "first" When a synonym maps to multiple names, determines which duplicates to mark as pd.DataFrame.duplicated

  • mute (bool, default: False) –

    Whether to mute logging. Defaults to False.

    • ”first”: returns the first mapped standardized name

    • ”last”: returns the last mapped standardized name

    • False: returns all mapped standardized name

  • synonyms_field (PublicOntologyField | str, default: 'synonyms') – str = "synonyms" A field containing the concatenated synonyms.

Return type:

dict[str, str] | list[str]

Returns:

If return_mapper is False – a list of standardized names. Otherwise, a dictionary of mapped values with mappable synonyms as keys and standardized names as values.

Examples

>>> import bionty_base as bt
>>> public = bt.Gene()
>>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"]
>>> standardized_symbols = public.standardize(gene_symbols, public.symbol)
to_pronto()

The Pronto Ontology object.

See: https://pronto.readthedocs.io/en/stable/api/pronto.Ontology.html

validate(values, field, *, mute=False, **kwargs)

Validate a list of values against a field of entity reference.

Parameters:
  • values (Iterable) – Identifiers that will be checked against the field.

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

  • mute (bool, default: False) – Whether to suppress logging. Defaults to False.

  • kwargs – Used for backwards compatibility and return types.

Return type:

ndarray

Returns:

A boolean array indicating compliance validation.

Examples

>>> import bionty_base as bt
>>> public = bt.Gene()
>>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"]
>>> public.validate(gene_symbols, field=public.symbol)