satijalab / seurat

R toolkit for single cell genomics
http://www.satijalab.org/seurat
Other
2.26k stars 904 forks source link

Way to load Integrated Seurat object into WGCNA tutorial format #4939

Closed ksaunders73 closed 3 years ago

ksaunders73 commented 3 years ago

Hello!

As far as I can find, there is only one tutorial about loading Seurat objects into WGCNA (https://ucdavis-bioinformatics-training.github.io/2019-single-cell-RNA-sequencing-Workshop-UCD_UCSF/scrnaseq_analysis/scRNA_Workshop-PART6.html). I am really new to programming so it's probably just my inexperience, but I am not sure how to load my Seurat object into a format that works with WGCNA's tutorials (https://horvath.genetics.ucla.edu/html/CoexpressionNetwork/Rpackages/WGCNA/Tutorials/).

Here is what I have tried thus far - I am also working from an integrated Seurat object.

This tries to replicate datExpr and datTraits from part I.1:

library(WGCNA)
DefaultAssay(integrated.object) <- "RNA"
sobjwgcna <- integrated.object

sobjwgcna <- FindVariableFeatures(sobjwgcna, selection.method = "vst", nfeatures = 2000,
                                  verbose = FALSE, assay = "RNA")
options(stringsAsFactors = F)
sobjwgcnamat <- GetAssayData(sobjwgcna)
datExpr <- t(sobjwgcnamat)[,VariableFeatures(sobjwgcna)]

datTraits <- integrated.object@meta.data
datTraits = subset(datTraits, select = -c(nCount_RNA, nFeature_RNA, log10GenesPerUMI, mitoRatio, percent.mito, RNA_snn_res.1.1))

I then copy-paste the code as written in the WGCNA I.2a tutorial (https://horvath.genetics.ucla.edu/html/CoexpressionNetwork/Rpackages/WGCNA/Tutorials/FemaleLiver-02-networkConstr-auto.pdf), and that all works until I get to this line in the I.3 tutorial (https://horvath.genetics.ucla.edu/html/CoexpressionNetwork/Rpackages/WGCNA/Tutorials/FemaleLiver-03-relateModsToExt.pdf):

MEList = moduleEigengenes(datExpr, colors = moduleColors)
Error in t.default(expr[, restrict1]) : argument is not a matrix

I tried converting both moduleColors and datExpr into a matrix with as.matrix(), but the error still persists.

Hopefully this makes sense, and thanks for reading!

saketkc commented 3 years ago

I think you will need as.matrix(datExpr) to convert the sparse matrix to normal matrix (expected by WGCNA).

ksaunders73 commented 3 years ago

Hello @saketkc !

So doing as.matrix(datExpr) right after datExpr <- t(sobjwgcnamat)[,VariableFeatures(sobjwgcna)] worked! I had been trying it right before MEList = moduleEigengenes(datExpr, colors = moduleColors) and that didn't work. Seems simple but order matters I guess. Thank you very much for your help!