ehrapy.io.write¶
- ehrapy.io.write(filename, adata, extension=None, compression='gzip', compression_opts=None)[source]¶
Write
AnnData
objects to file.It is possbile to either write an
AnnData
object to a .csv file or a .h5ad file. The .h5ad file can be used as a cache to save the current state of the object and to retrieve it faster once needed. This preserves the object state at the time of writing. It is possible to write both, encoded and unencoded objects.- Parameters:
filename (
str
|Path
) – File name or path to write the file to.adata (
AnnData
) – Annotated data matrix.extension (
str
|bool
, default:None
) – File extension. One of ‘h5ad’, ‘csv’. Defaults to None which infers the extension from the filename.compression (
Optional
[Literal
['gzip'
,'lzf'
]], default:'gzip'
) – Optional file compression. One of ‘gzip’, ‘lzf’.compression_opts (
int
|None
, default:None
) – See http://docs.h5py.org/en/latest/high/dataset.html.
- Return type:
Examples
>>> import ehrapy as ep >>> adata = ep.dt.mimic_2(encoded=True) >>> ep.io.write("mimic_2.h5ad", adata)