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

[Seurat5]: SCTModel.list contains only a subset of feature attributes after calling SCTransform #7557

Closed
Gilquin opened this issue Jul 12, 2023 · 2 comments
Assignees

Comments

@Gilquin
Copy link

Gilquin commented Jul 12, 2023

Running SCTransform on a Seurat v5 object (Assay5 class for RNA assay) will return an SCT assay where any of the SCTModel may miss some feature.attributes if the number of cells is less than the argument ncells (default to 5000). In this case, the following subset of feature.attributes is lost: detection_rate, gmean and variance.

The culprit is a call to the function SCTModel_to_vst which skips the fields detection_rate, gmean and variance.

This removes the possibility of using the function VariableFeaturePlot on the newly created SCT assay (which calls HVFInfo.SCTAssay which itself searches for gmean and variance, see the corresponding line).

Is this intended or not? If not, a possible solution would be to add the following line:

vst_out.reference$gene_attr <- local.reference.SCT.model@feature.attributes

there, in the SCTransform.StdAssay function body.

Here is a reproducible example:

options(Seurat.object.assay.version = "v5")

# Load data
Sobject <- Seurat::UpdateSeuratObject(pbmc3k.SeuratData::pbmc3k)

# Create Seurat v5 object
SobjectV5 <- SeuratObject::CreateSeuratObject(
  counts = SeuratObject::CreateAssay5Object(counts = Sobject[["RNA"]]@counts),
  assay = "RNA",
  meta.data = Sobject@meta.data,
  project = Sobject@project.name
)

# SCT normalization
SobjectV5 <- Seurat::PercentageFeatureSet(SobjectV5, pattern = "^MT-", col.name = "percent.mt")
SobjectV5 <- Seurat::SCTransform(
  SobjectV5,
  vst.flavor = "v2",
  vars.to.regress = "percent.mt",
  seed.use = 404,
  ncells = 2000
  )

# Check the missing columns
str(SobjectV5[["SCT"]]@SCTModel.list$model1@feature.attributes)

Note that running the example with ncells = 5000 returns the full set of feature.attributes as an "edge" case.

@saketkc
Copy link
Collaborator

saketkc commented Jul 12, 2023

Thank you @Gilquin for a reproducible example. We should support it and will release a fix soon.

@saketkc saketkc self-assigned this Jul 12, 2023
@saketkc
Copy link
Collaborator

saketkc commented Sep 15, 2023

Hi @Gilquin, thanks for the reproducible example. This has been fixed internally and will be in the official Seurat V5 release.

@saketkc saketkc closed this as completed Sep 15, 2023
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

No branches or pull requests

2 participants