lamindb.dev.CanValidate#

class lamindb.dev.CanValidate#

Bases: object

Base class providing Registry-based validation.

Attributes

Methods

add_synonym(synonym, force=False, save=None)#

Add synonyms to a record.

Parameters:
  • synonym (Union[str, TypeVar(ListLike, list, pd.Series, np.array)]) –

  • force (bool, default: False) –

  • save (Optional[bool], default: None) –

See also

remove_synonym()

Remove synonyms

Examples

>>> import lnschema_bionty as lb
>>> lb.CellType.from_bionty(name="T cell").save()
>>> lookup = lb.CellType.lookup()
>>> record = lookup.t_cell
>>> record.synonyms
'T-cell|T lymphocyte|T-lymphocyte'
>>> record.add_synonym("T cells")
>>> record.synonyms
'T cells|T-cell|T-lymphocyte|T lymphocyte'
classmethod inspect(values, field=None, *, mute=False, **kwargs)#

Inspect if values are mappable to a field.

Being mappable means that an exact match exists.

Parameters:
  • values (TypeVar(ListLike, list, pd.Series, np.array)) – Values that will be checked against the field.

  • field (Union[str, TypeVar(StrField, str, DeferredAttribute), None], default: None) – The field of values. Examples are ‘ontology_id’ to map against the source ID or ‘name’ to map against the ontologies field names.

  • mute (bool, default: False) – Mute logging.

Return type:

InspectResult

See also

validate()

Examples

>>> import lnschema_bionty as lb
>>> lb.settings.species = "human"
>>> ln.save(lb.Gene.from_values(["A1CF", "A1BG", "BRCA2"], field="symbol"))
>>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"]
>>> result = lb.Gene.inspect(gene_symbols, field=lb.Gene.symbol)
✅ 2 terms (50.00%) are validated
🔶 2 terms (50.00%) are not validated
    🟠 detected synonyms
    to increase validated terms, standardize them via .standardize()
>>> result.validated
['A1CF', 'A1BG']
>>> result.non_validated
['FANCD1', 'FANCD20']
classmethod map_synonyms(synonyms, *, return_mapper=False, case_sensitive=False, keep='first', synonyms_field='synonyms', field=None, **kwargs)#

{}

Return type:

Union[List[str], Dict[str, str]]

remove_synonym(synonym)#

Remove synonyms from a record.

Parameters:

synonym (Union[str, TypeVar(ListLike, list, pd.Series, np.array)]) – The synonym value.

See also

add_synonym()

Add synonyms

Examples

>>> import lnschema_bionty as lb
>>> lb.CellType.from_bionty(name="T cell").save()
>>> lookup = lb.CellType.lookup()
>>> record = lookup.t_cell
>>> record.synonyms
'T-cell|T lymphocyte|T-lymphocyte'
>>> record.remove_synonym("T-cell")
'T lymphocyte|T-lymphocyte'
set_abbr(value)#

Set value for abbr field and add to synonyms.

Parameters:

value (str) – A value for an abbreviation.

See also

add_synonym()

Add synonyms

Examples

>>> import lnschema_bionty as lb
>>> lb.ExperimentalFactor.from_bionty(name="single-cell RNA sequencing").save()
>>> scrna = lb.ExperimentalFactor.filter(name="single-cell RNA sequencing").one()
>>> scrna.abbr
None
>>> scrna.synonyms
'single-cell RNA-seq|single-cell transcriptome sequencing|scRNA-seq|single cell RNA sequencing'
>>> scrna.set_abbr("scRNA")
>>> scrna.abbr
'scRNA'
>>> scrna.synonyms
'scRNA|single-cell RNA-seq|single cell RNA sequencing|single-cell transcriptome sequencing|scRNA-seq'
>>> scrna.save()
classmethod standardize(values, field=None, *, return_mapper=False, case_sensitive=False, mute=False, bionty_aware=True, keep='first', synonyms_field='synonyms', **kwargs)#

Maps input synonyms to standardized names.

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

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

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

  • mute (bool, default: False) – Mute logging.

  • bionty_aware (bool, default: True) – Whether to standardize from Bionty reference.

  • keep (Literal['first', 'last', False], default: '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 (str, default: 'synonyms') – A field containing the concatenated synonyms.

  • field (Union[str, TypeVar(StrField, str, DeferredAttribute), None], default: None) – The field representing the standardized names.

Return type:

Union[List[str], Dict[str, 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.

See also

add_synonym()

Add synonyms

remove_synonym()

Remove synonyms

Examples

>>> import lnschema_bionty as lb
>>> lb.settings.species = "human"
>>> ln.save(lb.Gene.from_values(["A1CF", "A1BG", "BRCA2"], field="symbol"))
>>> gene_synonyms = ["A1CF", "A1BG", "FANCD1", "FANCD20"]
>>> standardized_names = lb.Gene.standardize(gene_synonyms)
>>> standardized_names
['A1CF', 'A1BG', 'BRCA2', 'FANCD20']
classmethod validate(values, field=None, *, mute=False, **kwargs)#

Validate values against existing values of a string field.

Note this is strict validation, only asserts exact matches.

Parameters:
  • values (TypeVar(ListLike, list, pd.Series, np.array)) – Values that will be validated against the field.

  • field (Union[str, TypeVar(StrField, str, DeferredAttribute), None], default: None) – The field of values. Examples are ‘ontology_id’ to map against the source ID or ‘name’ to map against the ontologies field names.

  • mute (bool, default: False) – Mute logging.

Return type:

ndarray

Returns:

A vector of booleans indicating if an element is validated.

See also

inspect()

Examples

>>> import lnschema_bionty as lb
>>> lb.settings.species = "human"
>>> ln.save(lb.Gene.from_values(["A1CF", "A1BG", "BRCA2"], field="symbol"))
>>> gene_symbols = ["A1CF", "A1BG", "FANCD1", "FANCD20"]
>>> lb.Gene.validate(gene_symbols, field=lb.Gene.symbol)
✅ 2 terms (50.00%) are validated
🔶 2 terms (50.00%) are not validated
array([ True,  True, False, False])