Closed JoyOtten closed 1 year ago
Hi Joy, thanks for the information, I will look into this issue ASAP. Just wondering, do you run into the same issue on the tutorial dataset or just your own data?
Hi Sam, I will check today if I run into the same problem with the tutorial data, I can run the hdWGCNA if I choose to group the metaspots by samples (total 16) compared to the 35 brain regions.
Hi Sam,
I just tried it out and noticed that there are some typo's in your vignette from spatial transcriptomis. However, more importantly, I do run into the exact same error with the tutorial data.
seurat_obj <- MetaspotsByGroups(
- seurat_obj,
- group.by = c("seurat_clusters"),
- ident.group = "seurat_clusters",
- assay = 'Spatial',
- slot = 'counts'
- ) Error in
[[<-
(*tmp*
, cur_bc, value = cur_neighbors) : no such index at level 1
Hi Joy,
I found the source of your issue. If the Seurat object contains more than one ST slide, you have to specify a metadata column in group.by
to indicate the different slides/sample. In the tutorial, "region" indicates the anterior / posterior tissue sample, so we could do this with the tutorial dataset:
seurat_obj <- MetaspotsByGroups(
seurat_obj,
group.by = c("seurat_clusters", "region"), # make sure to include a column here containing info about the ST slides / samples
ident.group = "seurat_clusters",
assay='Spatial',
mode = 'sum'
)
I updated the package to throw a more informative error in the future. Please update to the newest version and try re-running, and let me know if this solution works for you.
Hi, I've tried it on my own data and I now got the following error:
test <- MetaspotsByGroups(
- seurat_obj,
- group.by = c("orig.ident", "sub_regions"),
- ident.group = "sub_regions",
- assay = 'Spatial',
- slot = 'counts'
- ) Error in (function (cur_seurat, mode = "sum", assay = "Spatial", slot = "counts") : More than one sample present in grouping. Please specify a metadata column with group.by indicating different ST samples.
I will try it directly on the tutorial data
On the tutorial data I had no problems at all
In your call to MetaspotsByGroups
, you set group.by = c("orig.ident", "sub_regions")
. Does either orig.ident
or sub_regions
correspond to the different ST samples present in your Seurat object? The error message is telling you that you need to include a column name from the seurat_obj@meta.data
indicating the different samples in your dataset. Previously you said that your dataset has 16 samples so you should check that you are supplying the correct metadata column for the sample name or sample ID etc.
the orig.ident is the samples but with groupings It concatenates sub_regions and orig.ident together. Not sure if that's why it goes wrong.
I have located the error/problem it's in the ConstructMetaspots function in the following line of code: if (sum(unlist(lapply(Images(cur_seurat), function(x) { nrow(cur_seurat@images[[x]]@coordinates) == 0 }))) != 1) { stop("More than one sample present in grouping. Please specify a metadata column with group.by indicating different ST samples.") }
Basically the unique groupings that I have is 560 (without filtering) the problem here is that I only have 16 samples where it would expect me to have 1 image, instead I have 16 images.
the problem here is that I only have 16 samples where it would expect me to have 1 image, instead I have 16 images.
Not sure that I understand. Are you saying that you have 16 images for each sample?
I Sam, no I have in total 16 images, each sample has 1 image. But it seems that this function only wants 1 image but in the whole object there are 16. When I skip this line of code everything works perfectly.
I had one more question that popped up, could you use the SCT normalised data also for spatial transcriptomics? Since it's less prone to lower/higher expression of genes compared to log normalization.
Hi Joy,
I made a slight change of the code so it should be fixed now if you update the package. I tried it on my own data with 80 different samples and it ran without an issue.
As for sctransform, I have not tried it myself but I think you could use it if you specify the correct assay
and slot
in the MetaSpotsByGroups
function.
Hi yes, I have used sctransform succesfull with assay = "SCT and slot = "scale.data". However, I was wondering if the slot counts makes more sense to use since the counts are corrected UMI counts and it might be that hdWGCNA is better suited for that.
I think that you can use the sctransform counts or data slot as you wish. I really have very little experience with sctransform in general or with hdWGCNA so I don't really have any recommendations at this point.
Hi,
First of all thank you for making this awesome package. I'm running into an error code by using Spatial Transcriptomics data with the following code:
test <- MetaspotsByGroups( seurat_obj, group.by = c("regions"), ident.group = "regions", assay = 'Spatial', slot = 'counts' ) Error in
[[<-
(*tmp*
, cur_bc, value = cur_neighbors) : no such index at level 1I can't get a Metaspotsbygroup object if I run the code on 35 subregions of the data however, if I perform this analysis by using the samples as group in total 16 it's running fine.
I could trace that the problem is in the following line of code: metaspot_list <- mapply(ConstructMetaspots, cur_seurat = seurat_list, MoreArgs = list(mode = mode, assay = assay, slot = slot)) More specifically in the ConstrucMetaspots function over here: cur_neighbors <- unlist(lapply(1:length(tmp), function(k) { tmp[[k]][[2]] }))
I'm unsure how to solve this problem.
Thanks for helping, Joy