I have been provided with the gene expression matrices produced by spaceranger (matrix, feature and barcodes) and also the lower res images generated by spaceranger and the image alignment information (the spatial folder). However I do not have the h5 file generated to be loaded in Load10X function for the analysis. Do you know any way I can load these data for the analysis of Spatial Transcriptomics?
I have read this previous post (Spatial transcriptomics data). I have tried to generate a h5 file with the rhdf5, but when I try to write in the h5 file the matrix I have the following error:
Error in UseMethod("h5writeDataset") :
no applicable method for 'h5writeDataset' applied to an object of class "c('dgTMatrix', 'TsparseMatrix', 'dsparseMatrix', 'generalMatrix', 'dMatrix', 'sparseMatrix', 'compMatrix', 'Matrix', 'xMatrix', 'mMatrix', 'replValueSp')"
Any idea about how to proceed?. Is the h5 file needed for the Spatial using the Satija lab tutorial?
I didn't find a method to directly write the sparse matrix into a .h5 file. But as workaround you can store the raw values in a .h5 file.
Just store x,i,j and Dim in the h5 file and use the sparse matrix constructor with the stored values.
I hope I was able to help you
Load10X_Spatial is a convenient wrapper, but you don't need to use a h5 file.
Similar to all the other technologies (e.g. CITE-SEq, RNA-Seq), seurat stores the data inside different slots. If you read the How is the spatial data stored within Seurat section of the documentation, you find that:
In the Seurat object, the spot by gene expression matrix is similar to a typical “RNA” Assay but contains spot level, not single-cell level data.
The image itself is stored in a new images slot in the Seurat object. The images slot also stores the information necessary to associate spots with their physical position on the tissue image.
You can load your spot matrix (Read10X) and images separately (Read10X_Image), create a seurat object and add the data to the right slots.
You have to give input your count_matrix where rownames are the barcode names and colnames are the gene name. Coordinate matrix will contain the X and Y coordinate of the spatial data. If you want to use seurat write the ANN object into h5ad then convert it into seurat object.
If you still have the problem,
I have established a simple code for you to read any spatial expression using gene expression and spatial coordinates. You should read your matrices first and also modify tissue positions file as well as make sure about your adata object vars.