STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
184 stars 63 forks source link

Problems with data format conversion #305

Closed ultraypy closed 1 month ago

ultraypy commented 1 month ago

I'm sorry,I conducted stereoseq sequencing with BTU's instrument, and obtained gef files of cellbin and tissuetype with SAW7.0. But there is no complete pipeline available that explains how to convert objects from Stereopy to Seurat , especially with specific versions of Seurat and Stereopy. The official documentation on data format conversion is not very detailed and lacks sufficient content.

could you please help me with a more detailed pipeline

谢谢!

ultraypy commented 1 month ago

As well as convert to scanpy data format

tanliwei-coder commented 1 month ago

Do you mean you create a RDS file following the gide Format Conversion but can't use it in Seurat?

ultraypy commented 1 month ago

When I run:

# stereopy to seurat
data_path = '/home/user/yanpeiyi/project/stereo513/outDir/resultA03386A4/041.cellcut/A03386A4.cellbin.gef'
data = st.io.read_gef(file_path=data_path, bin_type='cell_bins')
# data.tl.cal_qc()
# data.tl.raw_checkpoint()

# remember to set flavor as seurat
adata = st.io.stereo_to_anndata(data,flavor='seurat',output='/home/user/yanpeiyi/project/stereo513/outDir/Seurat/format/seurat_out.h5ad')

Rscript /home/user/yanpeiyi/project/stereo513/outDir/Seurat/format/h5ad2rd.R --infile /home/user/yanpeiyi/project/stereo513/outDir/Seurat/format/seurat_out.h5ad --outfile /home/user/yanpeiyi/project/stereo513/outDir/Seurat/format/A03386A4.rds

Errors are as follows:

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

filter, lag

The following objects are masked from ‘package:base’:

intersect, setdiff, setequal, union

Attaching SeuratObject Attaching sp Registered S3 method overwritten by 'SeuratDisk': method from
as.sparse.H5Group Seurat Warning: Unknown file type: h5ad Creating h5Seurat file for version 3.1.5.9900 Adding X as data Adding X as counts Adding meta.features from var Adding spatial as cell embeddings for spatial Adding sn to miscellaneous data [1] "Finished! Converting h5ad to h5seurat file at:" [2] "./seurat_out.h5seurat"
[1] "h5seurat time consuming: 3.263" Validating h5Seurat file Initializing Spatial with data Adding counts for Spatial Adding feature-level metadata for Spatial Adding reduction spatial Adding cell embeddings for spatial Adding miscellaneous information for spatial Adding command information Adding cell-level metadata Warning: Invalid name supplied, making object name syntactically valid. New object name is XindexareadnbCountorig.identxy; see ?make.names for more details on syntax validity Adding tool-specific results Warning message: Cannot add objects with duplicate keys (offending key: spatial), setting key to 'spatialwo_' [1] "Successfully load h5seurat:" "./seurat_out.h5seurat"
Error: package or namespace load failed for ‘rhdf5’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/home/user/yanpeiyi/anaconda3/envs/h5ad2rds/lib/R/library/rhdf5/libs/rhdf5.so': libcrypto.so.1.1: cannot open shared object file: No such file or directory Execution halted

tanliwei-coder commented 1 month ago

That was caused by lacking a necessary library libcrypto.so.1.1, I think your environment lacks some R packages that are necessary for h5ad2rds.R.

r-41.zip

Uncompress r-41.zip to get r-41.yml which defines a conda environment suitable for running h5ad2rds.R

use conda to create R enviroment by running command:

conda env create -n r-41 -f r-41.yml

After creating , you also need to activate the environment and type R to enter R environment to install two necessary packages by remotes:

remotes::install_github("mojaveazure/seurat-disk", upgrade="never") remotes::install_github('grimbough/rhdf5', upgrade="never")

ultraypy commented 1 month ago

When I run remotes::install_github('grimbough/rhdf5', upgrade="never") Error as follows:

installing to /home/user/yanpeiyi/anaconda3/envs/r-41/lib/R/library/00LOCK-rhdf5/00new/rhdf5/libs
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  namespace ‘rhdf5filters’ 1.6.0 is being loaded, but >= 1.15.5 is required
Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
ERROR: lazy loading failed for package ‘rhdf5’
* removing ‘/home/user/yanpeiyi/anaconda3/envs/r-41/lib/R/library/rhdf5’
Warning message:
In i.p(...) :
  installation of package ‘/tmp/RtmpALJqo8/file7fa22f37f1a6/rhdf5_2.47.7.tar.gz’ had non-zero exit status
tanliwei-coder commented 1 month ago

rhdf5 may have been done some updates officially, you can do like below in the conda environment which was created following my suggestion above:

conda install -c conda-forge -y python=3.8

conda install -c bioconda -y bioconductor-rhdf5=2.38.1

I have done a test, it is successful on converting h5ad to rds.