ehrapy.tools.Translator

class ehrapy.tools.Translator(flavour='deepl', source='de', target='en', token=None)[source]

Class providing an interface to all translation functions. Requires a flavour.

Methods table

translate_X_column(adata[, columns, ...])

Translates a X column into the target language in place.

translate_obs_column(adata[, columns, ...])

Translates a single obs column and optionally replaces the original values

translate_text(text[, target_language])

Translates the provided text into the target language.

translate_var_column(adata[, columns, ...])

Translates a single var column and optionally replaces the original values

Methods

translate_X_column

Translator.translate_X_column(adata, columns=typing.Union[str, list], translate_column_name=False)[source]

Translates a X column into the target language in place.

Note that the translation of a column in X is always in place.

Parameters:
  • adata (AnnData) – AnnData object containing the var column to translate

  • target_language – The target language to translate into (default: EN-US)

  • columns – The columns to translate. Can be either a single column (str) or a list of columns

  • translate_column_name (bool) – Whether to translate the column name itself (only translates var_names, not var)

Return type:

None

translate_obs_column

Translator.translate_obs_column(adata, columns=typing.Union[str, list], translate_column_name=False, inplace=False)[source]

Translates a single obs column and optionally replaces the original values

Parameters:
  • adata (AnnData) – AnnData object containing the obs column to translate

  • target_language – The target language to translate into (default: EN-US)

  • columns – The columns to translate. Can be either a single column (str) or a list of columns

  • translate_column_name (bool) – Whether to translate the column name itself

  • inplace (bool) – Whether to replace the obs values or add a new obs column

Return type:

None

translate_text

Translator.translate_text(text, target_language=None)[source]

Translates the provided text into the target language.

Parameters:
  • text (str | Iterable) – The text to translate

  • target_language (str) – The target language to translate the Text into, e.g. EN-GB

Return type:

str | list[str]

Returns:

A TextResult object

translate_var_column

Translator.translate_var_column(adata, columns=typing.Union[str, list], translate_column_name=False, inplace=False)[source]

Translates a single var column and optionally replaces the original values

Parameters:
  • adata (AnnData) – AnnData object containing the obs column to translate

  • target_language – The target language to translate into (default: EN-US)

  • columns – The columns to translate. Can be either a single column (str) or a list of columns

  • translate_column_name (bool) – Whether to translate the column name itself

  • inplace (bool) – Whether to replace the obs values or add a new obs column

Return type:

None