STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
187 stars 64 forks source link

annh5ad2rds.R throwing error #149

Closed GokceOGUZ closed 1 year ago

GokceOGUZ commented 1 year ago

I am using stereopy version 0.13.0b1 and trying to create the Seurat object.

I got an error following this minimal example from https://stereopy.readthedocs.io/en/latest/Tutorials/Format_Conversion.html#Working-with-Seurat which gave this error at the LoadH5Seurat line (extracted from your annh5ad2rds.R).

Error in if (!x[[i]]$dims) { : argument is of length zero

This code worked with h5ad files saved using previous versions of stereopy (also following the same steps). I would be grateful for your guidance.

image

tanliwei-coder commented 1 year ago

Hi, this error is caused because we add some scalar values into anndata at version 0.13.0b1, if you only want to get a rds, you can downgrade to 0.12.1 and run again, we will fix this bug as soon as possible.

Somnvs commented 1 year ago

To load the H5Seurat object, set the misc parameter to False. The code for loading the object is as follows: object <- LoadH5Seurat(h5file, misc = F) You can find more information about this issue on the following GitHub page: https://github.com/mojaveazure/seurat-disk/issues/82

Zjianglin commented 7 months ago

Hi, this error is caused because we add some scalar values into anndata at version 0.13.0b1, if you only want to get a rds, you can downgrade to 0.12.1 and run again, we will fix this bug as soon as possible.

Hi, have you fix this bug in the lastest release version? I still have this error in stereopy v1.0 and v1.1 and v0.12.1. However, as suggested by Somnvs, I set the misc parameterer to FALSE seems bypass this error. Here is my running output:


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

Warning message:
package ‘dplyr’ was built under R version 4.3.2 
Attaching SeuratObject
‘SeuratObject’ was built with package ‘Matrix’ 1.6.4 but the current
version is 1.6.5; it is recomended that you reinstall ‘SeuratObject’ as
the ABI for ‘Matrix’ may have changed
Warning message:
package ‘Seurat’ was built under R version 4.3.2 
Warning message:
package ‘argparser’ was built under R version 4.3.2 
Registered S3 method overwritten by 'SeuratDisk':
  method            from  
  as.sparse.H5Group Seurat
Warning message:
package ‘SeuratDisk’ was built under R version 4.3.2 
[1] "Seurat Version is 4.4.0"
Warning: Unknown file type: h5ad
Creating h5Seurat file for version 3.1.5.9900
Adding X as data
Adding raw/X as counts
Adding meta.features from raw/var
Adding spatial as cell embeddings for spatial
Adding bin_size to miscellaneous data
Adding bin_type to miscellaneous data
Adding raw_cellname to miscellaneous data
Adding raw_counts to miscellaneous data
Adding raw_genename to miscellaneous data
Adding resolution to miscellaneous data
Adding sn to miscellaneous data
[1] "Finished! Converting h5ad to h5seurat file at:"
[2] "High_CF142_raw_bin50_seurat.h5seurat"          
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
Adding tool-specific results
Warning message:
Cannot add objects with duplicate keys (offending key: spatial_), setting key to 'spatialvt_' 
[1] "Successfully load h5seurat:"         
[2] "High_CF142_raw_bin50_seurat.h5seurat"
Performing log-normalization
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
[1] "Finished! Got raw counts only, auto create log-normalize data."
[1] "Start add image...This may take some minutes...(~.~)"
[1] "Finished add image...Start to saveRDS..."
[1] "Finished RDS."

the previous stereopy codes are:

#stereopy version is v0.12.1

vx = st.io.read_gef(high_cf142_geffp, bin_size=binsize)
vx.tl.cal_qc() 
vx.tl.raw_checkpoint()
print("{} (Bin{}) : {}\n".format(kx, binsize, vx))
ofp = os.path.join(processed_data_odir, '{}_raw_bin{}_seurat.h5ad'.format(kx, binsize))
adata = st.io.stereo_to_anndata(vx, flavor='seurat',output=ofp, sample_id=kx, reindex=True)

Is this process correct or not?. If I want to use the lastest version of stereopy for some analysis and converted results to Seurat style RDS data, how could I do this? thanks.