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()
- diff(compare_to, **kwargs)#
Determines a diff between two Bionty objects’ ontologies.
- Parameters:
compare_to – Bionty 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 –
New entries.
A pd.DataFrame.compare result which denotes all changes in
self
andother
.
Examples
>>> import bionty as bt >>> disease_bt_1 = bt.Disease(source="mondo", version="2023-04-04") >>> disease_bt_2 = bt.Disease(source="mondo", version="2023-04-04") >>> new_entries, modified_entries = disease_bt_1.diff(disease_bt_2) >>> print(new_entries.head()) >>> print(modified_entries.head())
- inspect(values, field, *, return_df=False, mute=False)#
Inspect a list of values against a field of entity reference.
- Parameters:
values – 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.
return_df – Whether to return a Pandas DataFrame.
- Return type:
Union
[DataFrame
,Dict
[str
,List
[str
]]]- 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.
- If
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(values, *, return_mapper=False, case_sensitive=False, keep='first', synonyms_field='synonyms', 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.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, limit=None, case_sensitive=False, synonyms_field='synonyms')#
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).
- Return type:
DataFrame
- Returns:
Ranked search results.
Examples
>>> import bionty as bt >>> celltype_bt = bt.CellType() >>> celltype_bt.search("gamma delta T cell")
- validate(values, field)#
Validate a list of values against a field of entity reference.
- Return type:
ndarray
[bool
]