Closed JoyOtten closed 1 year ago
Hi, I've also ran it on the tutorial code and I'm getting the same error code:
library(Seurat)
library(SeuratData)
library(tidyverse) library(cowplot) library(patchwork)
library(WGCNA) library(hdWGCNA)
library(proxy)
enableWGCNAThreads(nThreads = 8)
theme_set(theme_cowplot())
set.seed(12345)
SeuratData::InstallData("stxBrain")
brain <- LoadData("stxBrain", type = "anterior1") brain$region <- 'anterior' brain2 <- LoadData("stxBrain", type = "posterior1") brain2$region <- 'posterior'
seurat_obj <- merge(brain, brain2) seurat_obj$region <- factor(as.character(seurat_obj$region), levels=c('anterior', 'posterior'))
image_df <- do.call(rbind, lapply(names(seurat_obj@images), function(x){ seurat_obj@images[[x]]@coordinates }))
new_meta <- merge(seurat_obj@meta.data, image_df, by='row.names')
rownames(new_meta) <- new_meta$Row.names ix <- match(as.character(colnames(seurat_obj)), as.character(rownames(new_meta))) new_meta <- new_meta[ix,]
seurat_obj@meta.data <- new_meta
head(image_df)
seurat_subset <- SCTransform(seurat_obj, assay = "Spatial", verbose = FALSE) seurat_obj <- RunPCA(seurat_subset, verbose = FALSE, assay = "SCT")
seurat_obj <- FindNeighbors(seurat_obj, dims = 1:30) seurat_obj <- FindClusters(seurat_obj,verbose = TRUE) seurat_obj <- RunUMAP(seurat_obj, dims = 1:30)
seurat_subset <- SetupForWGCNA( seurat_obj, features = GetWGCNAGenes(seurat_subset, 'SCT'), wgcna_name = "SCT_meta" )
seurat_obj <- MetaspotsByGroups( seurat_subset, group.by = c("seurat_clusters", "region"), ident.group = "seurat_clusters", assay = 'Spatial', slot = 'counts', min_spots = 5 )
Error in t.default(agg_X) : argument is not a matrix In addition: Warning message: In MetaspotsByGroups(seurat_subset, group.by = c("seurat_clusters", : Removing the following groups that did not meet min_spots: 12#anterior, 17#anterior
Hi,
Thank you for posting the issue, I am looking into it now.
Hi,
I was wondering how it goes and if I could be of any help. Thank you
Hi again,
At this time I have not been able to reproduce your error on my side so it's hard for me to figure out what's going on. Based on the error message it might be a data type issue under the hood. I made a small change in the newest version that might fix your issue if you give it a try, please try running the code again with the newest version.
Hi Sam,
I have found that there is probably an issue with the col_bounds. In my data I have col_bounds from: 28 29 30 When I then continue to the following lines of code:
col_bounds <- col_bounds[which(1:length(col_bounds)%%4 == 0)]
That results in "NA" integer(empty)
Do you have any ideas on how to solve this? I don't follow necessary why you divide it by 4 which implies that you need at least 4 col_bounds. Could you help me out to solve this problem or am I doing something wrong with my code?
It seems like you may be trying this on a cluster that is too spatially constrained. The metaspots algorithm works by aggregating the transcriptome information for neighboring spots. There's a space of 4 spots between each metaspot, that's why we have the %%4
in that line of code. You can see a diagram of this in Fig S5 of the hdWGCNA paper. So it seems like in your case, the selected group is very thin with only 3 spots wide.
I updated the hdWGCNA package to add a more informative warning message when for this case, and now when there are fewer than 4 col_bounds
to start, the algorithm picks one of them to continue forward with for aggregation, but in my testing it just fails later on. You may wish to choose group.by
parameters that would result in larger groupings due to this limitation.
Hi Sam, I encountered a similar issue when running MetaspotsByGroups. After deleting spots less than min_spots (25) for each clusters in each sample(orig.ident), it still showed an error. I'm not sure whether it's for the same reason.
seurat_subset <- MetaspotsByGroups( seurat_subset, group.by = c("orig.ident","seurat_clusters"), ident.group = c("seurat_clusters"), min_spots = 25, wgcna_name = "SCT_meta", assay = 'Spatial', slot = 'counts' ) Error in Matrix(from, sparse = TRUE, doDiag = FALSE) : invalid 'data'
When I performed by 'group.by = c("orig.ident"), ident.group = c("orig.ident")', it's OK.
I further performed MetaspotsByGroups in one single slide.
seurat_subset <- seurat_subset[,seurat_subset$orig.ident=="t2"] seurat_subset <- MetaspotsByGroups( seurat_subset, group.by = c("seurat_clusters"), ident.group = c("seurat_clusters"), min_spots = 25, wgcna_name = "SCT_meta", assay = 'Spatial', slot = 'counts' ) Error in Matrix(from, sparse = TRUE, doDiag = FALSE) : invalid 'data' In addition: Warning message: In MetaspotsByGroups(seurat_subset, group.by = c("seurat_clusters"), : Removing the following groups that did not meet min_spots: 12, 13, 14, 16, 7
After selecting 2 major cluster in the slide for analysis, there is no error or warning. seurat_subset <- seurat_subset[,seurat_subset$seurat_clusters%in%c("17", "3")]
It seems because some spots from one cluster scattered spatially separately. In this case, could I build metaspots via adjacent/random 4(or more) spots, or any method to ignore such cluster in any slides?
Hi Sam,
I encountered another problem with the min_spots parameter. If you set it to default (50) it works perfectly but with anything else I'm getting the following error: Error in t.default(agg_X) : argument is not a matrix
I will check if I have the same issue with the tutorial data.
seurat_subset <- MetaspotsByGroups(