bionty.Bionty#
- class bionty.Bionty(source=None, version=None, organism=None, *, include_id_prefixes=None, **kwargs)#
Bases:
object
Bionty base model.
Attributes
- fields property#
All Bionty entity fields.
- organism property#
The
name
ofOrganism
Bionty.
- source property#
Name of the source.
- 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
) – 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, *, 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 (
BiontyField
) – 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:
- 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 (
Union
[BiontyField
,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 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:
Union
[Dict
[str
,str
],List
[str
]]
- search(string, *, field=None, limit=None, case_sensitive=False, synonyms_field='synonyms')#
Search a given string against a Bionty field.
- Parameters:
string (
str
) – The input string to match against the field values.field (
Union
[BiontyField
,str
,None
], default:None
) – 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 (
bool
, default:False
) – Whether the match is case sensitive.synonyms_field (
Union
[BiontyField
,str
,None
], default:'synonyms'
) – 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")
- 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 (
Union
[BiontyField
,str
,None
], default:None
) – Optional[str] The field representing the standardized names.return_field (
Optional
[str
], 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
”first”: returns the first mapped standardized name
”last”: returns the last mapped standardized name
False: returns all mapped standardized name
synonyms_field (
Union
[BiontyField
,str
], default:'synonyms'
) – str = “synonyms” A field containing the concatenated synonyms.
- Return type:
Union
[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 as bt >>> gene_bt = bt.Gene() >>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"] >>> standardized_symbols = gene_bt.standardize(gene_symbols, gene_bt.symbol)
- validate(values, field, *, mute=False, **kwargs)#
Validate a list of values against a field of entity reference.
- Return type:
ndarray