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

Fix GroupCorrelation and GroupCorrelationPlot for Seurat V5 compatibility #9625

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

joesphbeller
Copy link

Discussed in issue #9483

Problem

In spatial_vignette.Rmd, GroupCorrelation() and GroupCorrelationPlot() would both generate the following error:

"Error in object[[assay]][] <- grp.cors: object of type 'S4' is not subsettable"

This is because the correlation was being stored in metafeatures, which is no longer an element of the assay in V5.

Solution

Insert 2 try() statements to make it compatible for previous and most recent versions of Seurat

@dcollins15 dcollins15 changed the base branch from master to develop January 22, 2025 19:15
Copy link
Contributor

@dcollins15 dcollins15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joesphbeller. thank you for taking the time and effort to translate your solution into a PR 🙌

I was not sure if this would cause any other functions that depend on GroupCorrelation or GroupCorrelationPlot to fail

AFAIK the blast radius for these two methods should be pretty small. In any case, your solution works well 🎉 That said, the fix could be refined further, so I’ve suggested a couple of improvements.

Thanks again!

Comment on lines +4703 to +4704
try(data <- object[[assay]]@meta.data[, c(feature.group, cor)], silent=T)
try(data <- object[[assay]]@meta.features[, c(feature.group, cor)], silent=T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +989 to +990
try(object[[assay]]@meta.data <- grp.cors, silent = T)
try(object[[assay]]@meta.features <- grp.cors, silent = T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try(object[[assay]]@meta.data <- grp.cors, silent = T)
try(object[[assay]]@meta.features <- grp.cors, silent = T)
object[[assay]] <- AddMetaData(object[[assay]], grp.cors)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants