Skip to content

Datasets (mtb.data)

Download the demo datasets the tutorials use into mtb.config.data_path. mtb.catalog.datasets() lists them.

Name Summary
mtb.data.fetch Download demo datasets into the data root, skipping those present.
mtb.data.write_example Write the example files of a tutorial dataset as .h5ad files.

mtb.data.fetch

fetch(*datasets: str, verbose: bool = True) -> 'Path | list[Path]'

Download demo datasets into the data root, skipping those present.

PARAMETERS DESCRIPTION
*datasets

Dataset ids; mtb.catalog.datasets() lists them.

type str default ()

verbose

Print one "downloading ..." line per dataset.

type bool default True

RETURNS DESCRIPTION
pathlib.Path or list of pathlib.Path

The dataset folder, <data root>/<dataset>/; a list of them for several datasets.

RAISES DESCRIPTION
ValueError

A dataset id that cannot be downloaded (the message lists the ids).

OSError

The download failed; the message names the URL.

Examples

>>> import multibench as mtb
>>> folder = mtb.data.fetch("D11")          # about 11 MB
>>> mtb.scan(folder, "vertical")
Notes

A non-empty <data root>/<dataset>/ counts as present and is left alone. Each archive is unpacked into a temporary folder under the data root and then moved into place.

mtb.data.write_example

write_example(
    dataset: str, folder: Path | str = ".", *, verbose: bool = True
) -> None

Write the example files of a tutorial dataset as .h5ad files.

The files hold a part of the dataset in the shape that your own data usually has: one .h5ad file per object, with the cell types in obs["celltype"]. The own-data section of each tutorial reads them until you put your own files in their place. They are named my_*.h5ad; the printed lines say what each holds. A file of your own with such a name is kept.

PARAMETERS DESCRIPTION
dataset

Id of a tutorial dataset, such as "D11". It has to be in the data root: mtb.data.fetch(dataset) downloads it.

type str

folder

Folder the files are written to; it is created when it does not exist. The default is the current folder.

type Path | str default '.'

verbose

Print one line per file.

type bool default True

RAISES DESCRIPTION
ValueError

No example is defined for dataset (the message lists the ids).

FileNotFoundError

The dataset is not in the data root; the message gives the fetch call.

Examples

>>> import multibench as mtb
>>> mtb.data.fetch("D11")
>>> mtb.data.write_example("D11")       # my_file.h5ad: RNA in X, ADT in obsm
See Also

mtb.data.fetch : download the dataset that the example is made from. mtb.io.export_dataset : write the objects read from the files as a dataset folder.