Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in "Error in object[[assay]][] <- grp.cors: object of type 'S4' is not subsettable" as shown in spatial_vignette.Rmd because new Seurat assay required subset method #9483

Open
joesphbeller opened this issue Nov 14, 2024 · 0 comments
Labels
documentation Error in documentation

Comments

@joesphbeller
Copy link

#8125 and #8809 both touched this topic, but it appears that the problem still persists. It was encouraged in #8125 to open a new issue if it persisted. I made a comment that included a possible solution, but I did not receive a reply.

Here is the comment I made that is still applicable:

Hello,

I am currently encountering the same error on the Vignette with Seurat v5.1.0, SeuratObject v5.0.2, and Matrix v1.7-0.

brain <- GroupCorrelation(brain, group.assay="Spatial", assay="Spatial",slot="data", do.plot = FALSE) yields: Error in object[[assay]][] <- grp.cors : object of type 'S4' is not subsettable

I then found the definition for GroupCorrelation() in utilities.R as well as the docstring which states: @return A Seurat object with the correlation stored in metafeatures

This is when I came to the same realization as @shihsama that metafeatures was not an element of the assay (in recent versions). Additionally, it appears that the new Seurat assay can no longer be subsetted this way.

Fixes that work:

One potential fix is changing this line in GroupCorrelation object[[assay]][] <- grp.cors to try(object[[assay]]@meta.data <- grp.cors, silent = T) try(object[[assay]]@meta.features <- grp.cors, silent = T)

This will run GroupCorrelation() on the SCT and Spatial Assays successfully and do what the docstring says. However, this change does not fix all issues. When I run the next line: p1 <- GroupCorrelationPlot(brain, assay = "Spatial", feature.group = "feature.grp", cor = "nCount_Spatial_cor") + ggtitle("Log Norm") + theme(plot.title = element_text(hjust =0.5)) yields: Error in h(simpleError(msg, call)) : error in evaluating the argument 'i' in selecting a method for function '[': invalid 'type' (S4) of argument

This error is because the same subset technique is being used to load into the "data" variable in the GroupCorrelationPlot() function. You could change the following line in GroupCorrelationPlot():

data <- object[[assay]][c(feature.group, cor)] to try(data <- object[[assay]]@meta.data[, c(feature.group, cor)], silent=T) try(data <- object[[assay]]@meta.features[, c(feature.group, cor)], silent=T)

This successfully runs. Since the vignette does not contain what the code used to produce, I am not able to compare my results, but this is what I get: LogxSCT Although I cannot see what image the vignette had produced, the description in the vignette appears to agree with this plot.

I did not want to make this a pull request for two main reasons:

  • I am a novice R programmer
  • I was not sure if this would cause any other functions that depend on GroupCorrelation or GroupCorrelationPlot to fail

@igrabski please, get back to me regarding this issue when you have time. Let me know if this should be posted in a new issue as well.

Thank you in advance for your thorough review.

@joesphbeller joesphbeller added the documentation Error in documentation label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Error in documentation
Projects
None yet
Development

No branches or pull requests

1 participant