Format Conversion¶
This section introduces how to do format conversion, so that you can work with other spatial tools while using Stereopy.
Note
Now we can add image information to the converted AnnData object, refer to API for more details.
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.
Note
The image information will be automatically added to the converted RDS file if the input h5ad file which is converted by using st.io.stereo_to_anndata contains the image information.
Run this command line in your own R environment:
Rscript h5ad2rds.R --infile <h5ad file> --outfile <rds file>
If your own R enviroment fails to run the h5ad2rds.R, you can use r-env-linux.yml or r-env-win.yml to create a new enviroment:
Linux: conda env create -n r-env -f r-env-linux.yml
Windows: conda env create -n r-env -f r-env-win.yml
Then you need to switch to the new enviroment, start R and run the following command to install seurat-disk:
remotes::install_github("mojaveazure/seurat-disk", upgrade="never")
In addition, you also need to install rhdf5 in windows:
BiocManager::install("rhdf5", update=FALSE, ask=FALSE)