Data I/O (mtb.io)¶
Write your data as a dataset folder the methods can read, and read its
canonical .h5 files back.
| Name | Summary |
|---|---|
mtb.io.export_dataset |
Write an AnnData / MuData (or loose objects) as a canonical dataset folder. |
mtb.io.read |
Read a canonical .h5 (a dataset file or an embedding.h5) as an AnnData. |
mtb.io.export_dataset
¶
export_dataset(
data,
dataset_dir: Path | str,
*,
rna="X",
adt=None,
atac=None,
atac_kind: str | None = None,
labels=None,
batch=None,
category: str | None = None,
adt_names: list | None = None,
batch_index: int | None = None,
overwrite: bool = False,
) -> Path
Write an AnnData / MuData (or loose objects) as a canonical dataset folder.
Produces the dataset folder layout (rna.h5, adt.h5, ATAC files,
cty.csv), so mtb.scan and mtb.run work on your own data. Give
raw counts. The files of each category are listed at
https://dsichang.github.io/scMultiBench/tutorials/run/#folder-layout.
| PARAMETERS | DESCRIPTION |
|---|---|
data
|
Object the selector strings refer to;
type
|
dataset_dir
|
Folder to create; its name is the dataset id for
type
|
rna
|
Raw-count matrix for RNA: a selector against
type
|
adt
|
Raw-count matrix for protein (ADT), same forms as
type
|
atac
|
ATAC matrix, same forms as
type
|
atac_kind
|
What
type
|
labels
|
Cell-type labels: a column, named
type
|
batch
|
Batch per cell, same forms as
type
|
category
|
Integration category the folder is for (
type
|
adt_names
|
Protein names for the ADT matrix; they override any it carries and are needed when it has none.
type
|
batch_index
|
Write the whole object as batch
type
|
overwrite
|
type
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
|
ValueError
|
Missing or conflicting arguments, a missing label or batch, or cells that do not pair across modalities. |
KeyError
|
A selector names a |
FileExistsError
|
A file this call would write exists and |
| WARNS | DESCRIPTION |
|---|---|
UserWarning
|
Values that are not whole numbers, or feature names that are missing or repeated. |
Examples
>>> import multibench as mtb
>>> mtb.io.export_dataset(adata, "data/MYCITE", rna="layer:counts",
... adt="obsm:protein", labels="obs:celltype")
>>> mtb.io.export_dataset(mdata, "data/MYMULTIOME", rna="rna", atac="atac",
... atac_kind="peak", labels="obs:celltype",
... category="vertical")
See Also
mtb.scan : confirm the folder is found and which methods can run on it.
mtb.io.read
¶
Read a canonical .h5 (a dataset file or an embedding.h5) as an AnnData.
matrix/data (features x cells) becomes .X (cells x features, CSR
when fewer than half of the entries are non-zero), matrix/features
the var_names and matrix/barcodes the obs_names. A method's
embedding.h5 goes to .obsm["X_emb"] of an AnnData without features.
| PARAMETERS | DESCRIPTION |
|---|---|
path
|
Canonical
type
|
| RETURNS | DESCRIPTION |
|---|---|
AnnData
|
|
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
|
ValueError
|
|
Examples