satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.3k stars 918 forks source link

Spatial Transcriptomic analysis tutorial: error when loading data #9446

Closed RenhaoL closed 2 weeks ago

RenhaoL commented 3 weeks ago

Hi all, I am trying to follow the 10X Visium tutorial, and when I load the data from SeuratData, the brain <- LoadData("stxBrain", type = "posterior1") generated error:

Error in `[<-.data.frame`(`*tmp*`, , i, value = new("Assay5", layers = list( : 
  replacement has 31053 rows, data has 3353

I am using stxBrain.SeuratData_0.1.2 and SeuratData_0.2.2.9001. Any suggestions on how to fix this? I think this is a version issue. Maybe the dataset got updated recently?

Thanks in advance.

Chrisdoan9 commented 3 weeks ago

Try seurat v5. It worked for me.

yoyoong commented 2 weeks ago

You can download the data and create a Seurat object. Read the documentation of the stxBrain function, which contains the code. For example, to use posterior1:

# Load the expression data
  expr.url <- 'http://cf.10xgenomics.com/samples/spatial-exp/1.0.0/V1_Mouse_Brain_Sagittal_Posterior/V1_Mouse_Brain_Sagittal_Posterior_filtered_feature_bc_matrix.h5'
  curl::curl_download(url = expr.url, destfile = basename(path = expr.url))
  expr.data <- Seurat::Read10X_h5(filename = basename(path = expr.url))
  posterior1 <- Seurat::CreateSeuratObject(counts = expr.data, project = 'posterior1', assay = 'Spatial')
  posterior1$slice <- 1
  posterior1$region <- 'posterior'
  # Load the image data
  img.url <- 'http://cf.10xgenomics.com/samples/spatial-exp/1.0.0/V1_Mouse_Brain_Sagittal_Posterior/V1_Mouse_Brain_Sagittal_Posterior_spatial.tar.gz'
  curl::curl_download(url = img.url, destfile = basename(path = img.url))
  untar(tarfile = basename(path = img.url))
  img <- Seurat::Read10X_Image(image.dir = 'spatial')
  Seurat::DefaultAssay(object = img) <- 'Spatial'
  img <- img[colnames(x = posterior1)]
  posterior1[['posterior1']] <- img
  # Clean up downloaded files
  unlink(x = c(basename(path = c(expr.url, img.url)), 'spatial'), recursive = TRUE)

It works for me no matter seurat v4 or v5.

RenhaoL commented 2 weeks ago

Both method works for me. Seurat 5.1.0 worked if you used the first method. Thank you guys!!