Working with scanpy package

Scanpy is a one of the best toolkit for single-cell RNA sequencing data analysis in Python. stLearn is created based on a part of scanpy and also our tool is partially compatible with scanpy.

We recommend to use both scanpy and stLearn for the analysis.

Convert AnnData from scanpy to work with stLearn function

stLearn also uses the AnnData as the core object like scanpy. However, we store the spatial data in different way.

Then if you read data by scanpy, you need to convert to stLearn AnnData format. But if you read the data by stLearn, you can use almost of all functions from scanpy.

[1]:
import stlearn as st
import scanpy as sc
[2]:
# Read Visium data by scanpy
adata = sc.datasets.visium_sge()
Variable names are not unique. To make them unique, call `.var_names_make_unique`.
Variable names are not unique. To make them unique, call `.var_names_make_unique`.
[3]:
adata
[3]:
AnnData object with n_obs × n_vars = 3798 × 36601
    obs: 'in_tissue', 'array_row', 'array_col'
    var: 'gene_ids', 'feature_types', 'genome'
    uns: 'spatial'
    obsm: 'spatial'
[4]:
# Convert AnnData object to work with stLearn
adata = st.convert_scanpy(adata)
[5]:
adata
[5]:
AnnData object with n_obs × n_vars = 3798 × 36601
    obs: 'in_tissue', 'array_row', 'array_col', 'imagecol', 'imagerow'
    var: 'gene_ids', 'feature_types', 'genome'
    uns: 'spatial'
    obsm: 'spatial'

After that you can work with all functions in scanpy and please check their tutorials for the detail processes.