tacco.get.data_from_key

data_from_key(adata, key, default_key=None, key_name='key', check_uns=False, search_order=('X', 'layer', 'obs', 'var', 'obsm', 'varm'), check_uniqueness=True, result_type='obs', verbose=1, raise_on_error=True)

Given a short key for data stored somewhere in an AnnData find the data associated with it following a deterministic scheme.

Parameters:
  • adata – A AnnData; if it is a DataFrame, use it in place of a adata.obs or adata.var data frame.

  • key

    The short key or “path” in adata where the data is stored as a string (e.g. “X”) or as a list-like of strings, e.g. (“raw”,”obsm”,”counts”), where the last element can be a list-like of stings, e.g. (“obsm”,”types”,[“B”,”T”]). Possible parts of paths are:

    • ”X”

    • ”layer”

    • ”obs”

    • ”var”

    • ”obsm”

    • ”varm”

    • ”raw”

    If None and check_uns is not False, looks in adata.uns[key_name] for the key and if unsuccessful uses default_key.

  • default_key – The default location to use; see key.

  • key_name – The name of the key to use for lookup in .uns; see key. Also used for meaningful error messages.

  • check_uns – Whether to check .uns for the key; if a string, overrides the value of key_name for the lookup; see key and key_name.

  • search_order – In which order to check the properties of AnnData for the key, if it is a string. The first hit will be returned. If check_uniqueness, the remaining properties will be checked for uniqueness of the hit, generating a warning for non-unique hits. In addition to the properties ‘X’,’layer’,’obs’,’var’,’obsm’, and ‘varm’, the two pseudo properties ‘multi-obs’ and ‘multi-var’ can be specified to allow for the selection of multiple obs/var columns.

  • check_uniqueness – Whether to check for uniqueness of the hit; see search_order.

  • result_type

    What type of data to look for. Options are:

    • ”obs”: return a Series with index like a .obs column

    • ”var”: return a Series with index like a .var column

    • ”obsm”: return a DataFrame with index like a .obs column

    • ”varm”: return a DataFrame with index like a .var column

    • ”X”: return an array-like of shape compatible with adata

    If “obs” or “obsm”, then “var” and “varm” will be excluded from the search_order. If “var” or “varm”, then “obs” and “obsm” will be excluded from the search_order. If “X”, then “obs” and “var” will be excluded from the search_order.

  • verbose – Level of verbosity, with 0 (no output), 1 (some output), …

  • raise_on_error – Whether to raise on errors. Alternatively just return None.

Returns:

Depending on result_type, a Series, DataFrame, or array-like containing the data (or None on failure it not raise_on_error).