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

Seurat fails to create meta.features slot when building from raw counts #8214

Closed
Rohit-Satyam opened this issue Dec 21, 2023 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@Rohit-Satyam
Copy link

Rohit-Satyam commented Dec 21, 2023

Hi

I am trying to create seurat object from count matrix and metadata but for some reason the latest version of Seurat (v5) creates meta.data slot instead of meta.features slot. The code to reproduce this behaviour is given below

library(Seurat)
library(SeuratData)
sobj <- CreateSeuratObject(counts = pbmc3k@assays$RNA@counts, project = "MCA")
## OR
sobj <- CreateSeuratObject(counts = as.sparse(pbmc3k@assays$RNA@counts), project = "MCA")
> sobj@assays$RNA@meta.data
data frame with 0 columns and 13714 rows

This should be the meta.features slot not meta.data (maybe typo error in your code). This small error is causing error in conversion of Seurat object to anndata (see issue)

If there is a workaround kindly let me know!

@Rohit-Satyam Rohit-Satyam added the bug Something isn't working label Dec 21, 2023
@Rohit-Satyam
Copy link
Author

Though I am able to view slotnames using

slotNames(sobj@assays$RNA)
[1] "layers"     "cells"      "features"   "default"    "assay.orig" "meta.data" 
[7] "misc"       "key"  

But I am not able to change them

slotNames(sobj@assays$RNA)[6] <- "meta.features"
Error in slotNames(sobj@assays$RNA)[6] <- "meta.features" : 
  could not find function "slotNames<-"

Besides, whenever I try to sobj@assays$RNA@ I get the following error even before I could type anything after @

> sobj@assays$RNA@
Error in names(x) <- paste("V", seq_along(x), sep = "") : 
  'names' attribute [1] must be the same length as the vector [0]

@Gesmira
Copy link
Contributor

Gesmira commented Dec 21, 2023

Hi,
This is expected. The Assay5 object replaced meta.features with meta.data, so what you're seeing is correct. The meta.data slot at the assay level now contains feature-level metadata, while the meta.data slot at the object level contains cell-level metadata.

Sceasy has yet to offer support for the v5 assay.

For now, I would reccomend converting your assay to a v3 assay. This can be done like so:
sobj[["RNA"]] <- as(sobj[["RNA"]], "Assay")
At that point, conversion should run normally.

@samuel-marsh
Copy link
Collaborator

@Rohit-Satyam

In case it helps simplify workflow I have added new function as.anndata to scCustomize that will work for either v3/4 or v5 objects without need to convert assay first.

https://samuel-marsh.github.io/scCustomize/articles/Object_Conversion.html#convert-seurat-or-liger-objects-to-anndata-objects

Best,
Sam

@JZL
Copy link

JZL commented Apr 22, 2024

Thanks @samuel-marsh and all the Seurat contributors, you save the day again :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants