Format Conversion#

This section introduces how to do format conversion, so that you can work with other spatial tools while using Stereopy.

Working with Scanpy#

IO module provides the function stereo.io.stereo_to_anndata to convert StereoExpData object into Anndata and output the corresponding .h5ad file.

[ ]:
import stereo as st
import warnings
warnings.filterwarnings('ignore')

# read the GEF file
data_path = './SS200000135TL_D1.tissue.gef'
data = st.io.read_gef(file_path=data_path, bin_size=50)
data.tl.raw_checkpoint()

# remember to set flavor as scanpy
adata = st.io.stereo_to_anndata(data,flavor='scanpy',output='scanpy_out.h5ad')

Working with Seurat#

If you want to get the normalizetion result and convert the output .h5ad into the .rds file, you need to save raw data before performing normalization. Otherwise, it will raise errors during conversion. Conversion process mainly includes two steps.

Ouput H5ad#

[ ]:
import stereo as st
import warnings
warnings.filterwarnings('ignore')

# read the GEF file
data_path = './SS200000135TL_D1.tissue.gef'
data = st.io.read_gef(file_path=data_path, bin_size=50)
data.tl.cal_qc()
data.tl.raw_checkpoint()

# remember to set flavor as seurat
adata = st.io.stereo_to_anndata(data,flavor='seurat',output='seurat_out.h5ad')

H5ad to RDS#

The output .h5ad could be converted into .rds file by h5ad2rds.R.

Run this command line in your own R environment:

[ ]:
Rscript h5ad2rds.R --infile <h5ad file> --outfile <rds file>