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, logging=True)#
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_bt = bt.Gene() >>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"] >>> gene_bt.inspect(gene_symbols, field=gene_bt.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 synonyms to standardized names.
- Parameters:
synonyms –
Iterable
Synonyms that will be standardized.return_mapper –
bool = False
IfTrue
, returns{input_synonym1: standardized_name1}
.case_sensitive –
bool = False
Whether the mapping is case sensitive.species –
Optional[str]
Map only against this species related entries.keep –
Literal["first", "last", False] = "first"
When a synonym maps to multiple names, determines which duplicates to mark aspd.DataFrame.duplicated
“first”: returns the first mapped standardized name
“last”: returns the last mapped standardized name
False
: returns all mapped standardized name
synonyms_field –
str = "synonyms"
A field containing the concatenated synonyms.synonyms_sep –
str = "|"
Which separator is used to separate synonyms.field –
Optional[str]
The field representing the standardized names.
- Return type:
Union
[Dict
[str
,str
],List
[str
]]- Returns:
If
return_mapper
isFalse
– a list of standardized names. Otherwise, a dictionary of mapped values with mappable synonyms as keys and standardized names as values.
Examples
>>> import bionty as bt >>> gene_bt = bt.Gene() >>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"] >>> standardized_symbols = gene_bt.map_synonyms(gene_symbols, gene_bt.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_bt = bt.CellType() >>> celltype_bt.search("gamma delta T cell")