Closed cathalgking closed 1 year ago
I also have this problem. And I edit the original Load10x_sample code and it works.
my_Load10X_Spatial <- function( data.dir, filename = 'filtered_feature_bc_matrix.h5', assay = 'Spatial', slice = 'slice1', filter.matrix = TRUE, to.upper = FALSE, image = NULL, ... ) { data <- Read10X_h5(filename = file.path(data.dir, filename)) if (to.upper) { rownames(x = data) <- toupper(x = rownames(x = data)) } object <- CreateSeuratObject(counts = data, assay = assay) image <- Read10X_Image( image.dir = file.path(data.dir, 'spatial'), filter.matrix = filter.matrix ) image <- image[Cells(x = object)] DefaultAssay(object = image) <- assay object[[slice]] <- image return(object) }
This works, thanks! Do you know why this issue arose? Is it the new Seurat version? I dont remember this happening before.
@LiangMingxuan00 Is there a way to use your above function to read in the hires image instead of the lores one? It seems to default to the lowres image.
When I specify "hires" in the function call it actually imports the low res image. I know this because I read both into 2 objects and plot them side by side. Also, when I remove the lowres image from the spaceranger folder and specify hires in the function call I get an error stating that it is looking for the lowres image png.
A1_grey_hires <- my_Load10X_Spatial(data.dir = sample, image = "hires")
Both are actually lowres even though the one on the right should be hires
Hi,
I guess it is the SeuratV5 problem. If you want to read hires image, I think you may should rewrite the Read10X_Image function again because the default input parameter is the lower resolution image
Read10X_Image <- function(image.dir, image.name = "tissue_lowres_image.png", filter.matrix = TRUE, ...) { image <- readPNG(source = file.path(image.dir, image.name)) scale.factors <- fromJSON(txt = file.path(image.dir, 'scalefactors_json.json')) tissue.positions.path <- Sys.glob(paths = file.path(image.dir, 'tissue_positions')) tissue.positions <- read.csv( file = tissue.positions.path, col.names = c('barcodes', 'tissue', 'row', 'col', 'imagerow', 'imagecol'), header = ifelse( test = basename(tissue.positions.path) == "tissue_positions.csv", yes = TRUE, no = FALSE ), as.is = TRUE, row.names = 1 ) if (filter.matrix) { tissue.positions <- tissue.positions[which(x = tissue.positions$tissue == 1), , drop = FALSE] } unnormalized.radius <- scale.factors$fiducial_diameter_fullres scale.factors$tissue_lowres_scalef spot.radius <- unnormalized.radius / max(dim(x = image)) return(new( Class = 'VisiumV1', image = image, scale.factors = scalefactors( spot = scale.factors$tissue_hires_scalef, fiducial = scale.factors$fiducial_diameter_fullres, hires = scale.factors$tissue_hires_scalef, scale.factors$tissue_lowres_scalef ), coordinates = tissue.positions, spot.radius = spot.radius )) }
When trying to read in data directly from the 10x Space Ranger outs folder I am getting an Error which seems to be related to the Visium Image.
The code I run which results in the Error is:
The files are un-touched and contain the required png images. The list of files in the outs folder look like:
And in the 'spatial' folder there is the following files:
I also tried to just read in the Image first with Read10X_Image() which seems to work but when I try to feed that into Load10X_Spatial I get a similar but different Error:
Read in image: