In [ ]:
import scgen
import scanpy as sc 

Reading the train data

In [ ]:
train ="./tests/data/pancreas.h5ad",

We need two observation labels "batch" and "cell_type" for our batch_removal procedure. There exist a "batch" obs but no "cell_type", so we add it as a .obs of adata

In [ ]:
train.obs["cell_type"] = train.obs["celltype"].tolist()

UMAP Visualization of the original uncorrected data

In [ ]:
In [6]:, color=["batch", "cell_type"], wspace=.5, frameon=False)

Creating and training the model

In [7]:
network = scgen.VAEArith(x_dimension= train.shape[1], model_path="./models/batch" )

We train the model for 100 epochs

In [8]:
network.train(train_data=train, n_epochs=100)

Batch Removal

Now, we pass our train (uncorected) adata and network object to batch_removal fucntion which returns adata of batch corrected data

In [ ]:
corrected_adata =  scgen.batch_removal(network, train, batch_key="batch", cell_label_key="cell_type")

Visualization of the corrected data

In [10]:
WARNING: You’re trying to run this on 2448 dimensions of `.X`, if you really want this, set `use_rep='X'`.
         Falling back to preprocessing with `sc.pp.pca` and default params.
In [15]:, color=["batch", "cell_type"], wspace=.5, frameon=False)

Using uncorrected data

Note that original adata.raw for the adata.raw is saved to corrected_adata.raw and you can use that for fruther analaysis

In [12]:
<anndata.core.anndata.Raw at 0x7f4da4313390>
In [14]:, color=["TMEM66", "cell_type"], wspace=.5, frameon=False, use_raw=True)