smorabit / hdWGCNA

High dimensional weighted gene co-expression network analysis
https://smorabit.github.io/hdWGCNA/
Other
315 stars 31 forks source link

"Error: 'RNA' is not an assay" in SetDatExpr #221

Closed learning-MD closed 2 months ago

learning-MD commented 2 months ago

Thanks for this interesting package. I have a processed dataset of ~140k PBMCs from two conditions. It has both "RNA" and "SCT" assays:

image

However, when I run the following code:

SetDatExpr( seurat_obj, group_name = c("CD4+ T cells"), group.by='cluster', assay = 'RNA', slot = 'data' )

I get the following error:

Error: 'RNA' is not an assay

I'm not sure what exactly the reason for this may be. Any suggestions? Thank you.

smorabit commented 2 months ago

Hi,

Can you please provide the other hdWGCNA code that you ran before SetDatExpr?

Thanks

learning-MD commented 2 months ago

Thanks for the quick response - it was exactly as in the tutorial:

library(tidyverse) library(Seurat) library(WGCNA) library(hdWGCNA) library(cowplot) theme_set(theme_cowplot())

setwd()

theme_set(theme_cowplot())

set.seed(12345)

enableWGCNAThreads(nThreads = 16)

seurat_obj <- readRDS("pbmc.rds") seurat_obj$cluster <- Idents(seurat_obj)

seurat_obj <- SetupForWGCNA( seurat_obj, gene_select = "fraction", fraction = 0.05, wgcna_name = "WGCNA" # the name of the hdWGCNA experiment )

seurat_obj <- MetacellsByGroups( seurat_obj = seurat_obj, group.by = c("cluster", "Sample_ID"), reduction = 'harmony', k = 25, max_shared = 10, ident.group = 'cluster' )

seurat_obj <- NormalizeMetacells(seurat_obj)

Assays(seurat_obj) DefaultAssay(seurat_obj) <- "SCT"

Prior to this, I used SCT v2 for normalization and batch-corrected with Harmony. Please let me know if you need anything else. Thanks!

smorabit commented 2 months ago

I think I see your problem. You specified assay='RNA when running SetDatExpr, but I am guessing that SCT was your active assay. When you run MetacellsByGroups, the DefaultAssay is used unless you specify assay in the function call (which you did not).

Try this code instead:

SetDatExpr( seurat_obj, group_name = c("CD4+ T cells"), group.by='cluster', assay = 'SCT', slot = 'data' )
learning-MD commented 2 months ago

I actually had changed it to "RNA" as the DefaultAssay and it still gets the same error.

Using SCT assay instead (as you provided) works and has worked previously as well - I typically use the "RNA" assay for all DE analyses and other downstream analyses for single-cell data. Is SCT okay to use for hdWGCNA? I did note the SCT tutorial as well (https://smorabit.github.io/hdWGCNA/articles/sctransform.html), but maybe I'm being too rigid in how I initially learned scRNA-seq analyses and can be flexible here.

Regardless, the error with the "RNA" assay is still present even when it's changed to the default assay.

smorabit commented 2 months ago

I generally do not recommend SCTransform for hdWGCNA, but a lot of users in the past insist on using it and that's why I made a tutorial for it.

One more thing you can try, can you re-run the MetacellsByGroups function but this time use the argument assay='RNA'.

learning-MD commented 2 months ago

Ah, that seems to have done the trick. Thanks so much! Excited to see the results.