Skip to main content

torch-adata

Reason this release was yanked:

misordered

Project description

torch-adata

Create pytorch Datasets from AnnData

Example use of the base class

The base class, AnnDataset is a subclass of the widely-used torch.utils.data.Dataset. The outputs of all AnnDataset classes and subclasses are designed to be directly compatible with the torch.utils.data.DataLoader module.

import anndata as a
import torch_adata as ta

adata = a.read_h5ad("/path/to/data.h5ad")
dataset = ta.AnnDataset(adata)

Returns data (X as a torch.Tensor) and the pandas.DataFrame; adata.obs.

# create a dummy index
idx = np.random.choice(range(dataset.__len__()), 5)
X, obs = dataset.__getitem__(idx)

Specialized classes

GroupedAnnDataset

A subclass of the base class, AnnDataset.

import anndata as a
import torch_adata as ta

adata = a.read_h5ad("/path/to/data.h5ad")
dataset = ta.GroupedAnnDataset(adata, groupby="batch")

Returns data as a dictionary of data with values as torch.Tensor and keys as each groupby category and the sampled adata.obs is again returned as a pandas.DataFrame.

# create a dummy index
idx = np.random.choice(range(dataset.__len__()), 5)
X_dict, obs = dataset.__getitem__(idx)

TimeResolvedAnnDataset

A subclass of the class, GroupedAnnDataset.

import anndata as a
import torch_adata as ta

adata = a.read_h5ad("/path/to/data.h5ad")
dataset = ta.TimeResolvedAnnDataset(adata, time_key="Time point")

Returns the initial datapoint, X0 as a torch.Tensor, the entire sample of the dataset as a dictionary of data with values as torch.Tensor and keys as each timepoint indicated by the time_key. Sampled adata.obs is again returned as a pandas.DataFrame.

# create a dummy index
idx = np.random.choice(range(dataset.__len__()), 5)
X0, X_dict, t, obs = dataset.__getitem__(idx)

Installation

Install from PYPI:

pip install torch-adata

Install the developer version:

git clone https://github.com/mvinyard/torch-adata.git; cd torch-adata;
pip install -e .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch-adata-0.0.11.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

torch_adata-0.0.11-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page