ehrapy.anndata.infer_feature_types

ehrapy.anndata.infer_feature_types(adata, layer=None, output='tree')[source]

Infer feature types from AnnData object.

For each feature in adata.var_names, the method infers one of the following types: ‘date’, ‘categorical’, or ‘numeric’. The inferred types are stored in adata.var[‘feature_type’]. Please check the inferred types and adjust if necessary using adata.var[‘feature_type’][‘feature1’]=’corrected_type’. Be aware that not all features stored numerically are of ‘numeric’ type, as categorical features might be stored in a numerically encoded format. For example, a feature with values [0, 1, 2] might be a categorical feature with three categories. This is accounted for in the method, but it is recommended to check the inferred types.

Parameters:
  • adata (AnnData) – AnnData object storing the EHR data.

  • layer (str | None) – The layer to use from the AnnData object. If None, the X layer is used.

  • output (Optional[Literal['tree', 'dataframe']]) – The output format. Choose between ‘tree’, ‘dataframe’, or None. If ‘tree’, the feature types will be printed to the console in a tree format. If ‘dataframe’, a pandas DataFrame with the feature types will be returned. If None, nothing will be returned. Defaults to ‘tree’.