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
ofSpecies
Bionty.
- version property#
The
name
ofversion
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, *, case_sensitive=False, inspect_synonyms=True, 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 source ID or ‘name’ to map against the ontologies field names.
case_sensitive – Whether the identifier inspection is case sensitive.
inspect_synonyms – Whether to inspect synonyms.
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, case_sensitive=False, keep='first', 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 – If True, returns {input synonyms : standardized field name}.
case_sensitive – Whether the mapping is case sensitive.
keep – {‘first’, ‘last’, False}, default ‘first’ When a synonym maps to multiple standardized values, determines which duplicates to mark as
pandas.DataFrame.duplicated
- “first”: returns the first mapped standardized value - “last”: returns the last mapped standardized value - False: returns all mapped standardized valuesynonyms_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:
- If return_mapper is False – a list of mapped field values. - If return_mapper is True: a dictionary of mapped values with mappable identifiers
as keys and values mapped to field as values.
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 the 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")