ehrdata.EHRData#

class ehrdata.EHRData(X=None, *, obs=None, var=None, tem=None, uns=None, obsm=None, varm=None, layers=None, raw=None, shape=None, filename=None, filemode=None, asview=False, obsp=None, varp=None, oidx=None, vidx=None, tidx=None)#

Model two and three dimensional electronic health record data.

../_images/ehrdata_logo.png

Extends AnnData to further support time-series data.

Parameters:
X ndarray | MaskedArray | csr_matrix | csc_matrix | csr_array | csc_array | Dataset | Array | ZappyArray | Array | CupyArray | CupySparseMatrix | DataFrame | None (default: None)

A #observations × #variables data array. A view of the data is used if the data type matches, otherwise, a copy is made.

obs DataFrame | Mapping[str, Iterable[Any]] | None (default: None)

Key-indexed one-dimensional observations annotation of length #observations.

var DataFrame | Mapping[str, Iterable[Any]] | None (default: None)

Key-indexed one-dimensional variables annotation of length #variables.

tem DataFrame | None (default: None)

Key-indexed one-dimensional time annotation of length #timesteps.

uns Mapping[str, Any] | None (default: None)

Key-indexed unstructured annotation.

obsm ndarray | Mapping[str, Sequence[Any]] | None (default: None)

Key-indexed multi-dimensional observations annotation of length #observations. If passing a numpy.ndarray, it needs to have a structured datatype.

varm ndarray | Mapping[str, Sequence[Any]] | None (default: None)

Key-indexed multi-dimensional variables annotation of length #variables. If passing a numpy.ndarray, it needs to have a structured datatype.

layers Mapping[str, ndarray] | None (default: None)

Key-indexed multi-dimensional #observations × #variables × #timesteps data arrays, aligned to dimensions of X.

shape tuple[int, int] | None (default: None)

Shape tuple (#observations, #variables, #timesteps). Can only be provided if X is None.

filename PathLike[str] | str | None (default: None)

Name of backing file. See h5py.File.

filemode Literal['r', 'r+'] | None (default: None)

Open mode of backing file. See h5py.File.

Attributes table#

X

Data matrix.

n_t

Number of time points.

shape

Shape of data (n_obs, n_vars, n_t).

tem

Time dataframe for describing third axis.

Methods table#

__getitem__(index)

Slice the EHRData object along 1-3 axes.

copy()

Returns a copy of the EHRData object.

from_adata(adata, *[, tem, tidx])

Create an EHRData object from an AnnData object.

Attributes#

EHRData.X#

Data matrix.

EHRData.n_t#

Number of time points.

EHRData.shape#

Shape of data (n_obs, n_vars, n_t).

EHRData.tem#

Time dataframe for describing third axis.

Methods#

EHRData.__getitem__(index)#

Slice the EHRData object along 1-3 axes.

Parameters:
index int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array | EllipsisType | tuple[int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array, int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array | EllipsisType] | tuple[int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array | EllipsisType, int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array] | tuple[int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array, int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array, EllipsisType] | tuple[EllipsisType, int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array, int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array] | tuple[int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array, EllipsisType, int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array] | tuple[int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array, int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array, int | str | int64 | slice | ndarray[tuple[Any, ...], dtype[bool]] | ndarray[tuple[Any, ...], dtype[integer]] | Sequence[int] | Sequence[str] | Sequence[bool] | Series | Index | ExtensionArray | ndarray[tuple[Any, ...], dtype[str_]] | matrix | csr_matrix | csc_matrix | csr_array | csc_array] | None

1D, 2D, or 3D index.

Return type:

EHRData

Returns:

An EHRData view object.

EHRData.copy()#

Returns a copy of the EHRData object.

Return type:

EHRData

classmethod EHRData.from_adata(adata, *, tem=None, tidx=None)#

Create an EHRData object from an AnnData object.

Parameters:
adata AnnData

Annotated data object.

tem DataFrame | None (default: None)

Time dataframe for describing third axis, see tem attribute.

tidx slice | None (default: None)

A slice for the 3rd dimension. Usually, this will be None here.

Return type:

EHRData

Returns:

An EHRData object extending the AnnData object.