scvi.external.CellAssign

class scvi.external.CellAssign(adata, cell_type_markers, size_factor_key, **model_kwargs)[source]

Reimplementation of CellAssign for reference-based annotation [Zhang19].

Parameters
adata : AnnDataAnnData

single-cell AnnData object that has been registered via setup_anndata(). The object should be subset to contain the same genes as the cell type marker dataframe.

cell_type_markers : DataFrameDataFrame

Binary marker gene DataFrame of genes by cell types. Gene names corresponding to adata.var_names should be in DataFrame index, and cell type labels should be the columns.

size_factor_key : strstr

Key in adata.obs with continuous valued size factors.

**model_kwargs

Keyword args for CellAssignModule

Examples

>>> adata = scvi.data.read_h5ad(path_to_anndata)
>>> library_size = adata.X.sum(1)
>>> adata.obs["size_factor"] = library_size / np.mean(library_size)
>>> marker_gene_mat = pd.read_csv(path_to_marker_gene_csv)
>>> bdata = adata[:, adata.var.index.isin(marker_gene_mat.index)].copy()
>>> scvi.data.setup_anndata(bdata)
>>> model = CellAssign(bdata, marker_gene_mat, size_factor_key='size_factor')
>>> model.train()
>>> predictions = model.predict(bdata)

Notes

Size factors in the R implementation of CellAssign are computed using scran. An approximate approach computes the sum of UMI counts (library size) over all genes and divides by the mean library size.

Attributes

device

history

Returns computed metrics during training.

is_trained

test_indices

train_indices

validation_indices

Methods

load(dir_path[, adata, use_gpu])

Instantiate a model from the saved output.

predict()

Predict soft cell type assignment probability for each cell.

save(dir_path[, overwrite, save_anndata])

Save the state of the model.

to_device(device)

Move model to device.

train([max_epochs, lr, use_gpu, train_size, …])

Trains the model.