smorabit / hdWGCNA

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

"RunPCAMetaCells" function in the Seurat Wrapper of the "Optional: Process the MetaCell Seurat Object" step of single-cell dataset vignette doesn't run #192

Closed kevynjackson closed 3 months ago

kevynjackson commented 5 months ago

Hello, thank you for developing this exciting tool! I am running the vignette "hdWGCNA in single-cell data" and the "RunPCAMetaCells" function of the Seurat wrapper in the optional step of "Process the Metacell Seurat Object".

I pasted the code directly from the vignette so I don't believe I typed anything incorrectly:

# single-cell analysis package
library(Seurat)

# plotting and data science packages
library(tidyverse)
library(cowplot)
library(patchwork)

# co-expression network analysis packages:
library(WGCNA)
library(hdWGCNA)

# using the cowplot theme for ggplot
theme_set(theme_cowplot())

# set random seed for reproducibility
set.seed(12345)

# optionally enable multithreading
enableWGCNAThreads(nThreads = 3)

# load the Zhou et al snRNA-seq dataset
seurat_obj <- readRDS('/Users/kev/Dropbox (EinsteinMed)/hdWGCNA/Tutorial/Zhou_2020.rds')
p <- DimPlot(seurat_obj, group.by='cell_type', label=TRUE) +
   umap_theme() + ggtitle('Zhou et al Control Cortex') + NoLegend()

p
seurat_obj <- SetupForWGCNA(
  seurat_obj,
  gene_select = "fraction", # the gene selection approach
  fraction = 0.05, # fraction of cells that a gene needs to be expressed in order to be included
  wgcna_name = "tutorial" # the name of the hdWGCNA experiment
)
# construct metacells  in each group
seurat_obj <- MetacellsByGroups(
  seurat_obj = seurat_obj,
  group.by = c("cell_type", "Sample"), # specify the columns in seurat_obj@meta.data to group by
  reduction = 'harmony', # select the dimensionality reduction to perform KNN on
  k = 25, # nearest-neighbors parameter
  max_shared = 10, # maximum number of shared cells between two metacells
  ident.group = 'cell_type' # set the Idents of the metacell seurat object
)

# normalize metacell expression matrix:
seurat_obj <- NormalizeMetacells(seurat_obj)
metacell_obj <- GetMetacellObject(seurat_obj)

seurat_obj <- NormalizeMetacells(seurat_obj)
seurat_obj <- ScaleMetacells(seurat_obj, features=VariableFeatures(seurat_obj))
seurat_obj <- RunPCAMetacells(seurat_obj, features=VariableFeatures(seurat_obj))

This is where it gets to when the below error is thrown.

Screenshot 2023-12-08 at 10 36 34 AM

R session info R version 4.2.3 (2023-03-15) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: macOS Big Sur ... 10.16

Matrix products: default LAPACK: /Users/kev/opt/anaconda3/envs/hdWGCNA/lib/libopenblasp-r0.3.21.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] hdWGCNA_0.2.26 ggrepel_0.9.4 harmony_1.2.0 Rcpp_1.0.10 WGCNA_1.72-5
[6] fastcluster_1.2.3 dynamicTreeCut_1.63-1 patchwork_1.1.3 cowplot_1.1.1 lubridate_1.9.2
[11] forcats_1.0.0 stringr_1.5.0 dplyr_1.1.0 purrr_1.0.1 readr_2.1.4
[16] tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.3 tidyverse_2.0.0 SeuratObject_4.1.3
[21] Seurat_4.3.0

loaded via a namespace (and not attached): [1] backports_1.4.1 Hmisc_5.1-0 plyr_1.8.8 igraph_1.5.1 lazyeval_0.2.2
[6] sp_2.0-0 splines_4.2.3 listenv_0.9.0 scattermore_1.2 GenomeInfoDb_1.34.9
[11] digest_0.6.31 foreach_1.5.2 htmltools_0.5.4 GO.db_3.16.0 fansi_1.0.4
[16] checkmate_2.2.0 magrittr_2.0.3 memoise_2.0.1 tensor_1.5 cluster_2.1.4
[21] doParallel_1.0.17 ROCR_1.0-11 tzdb_0.3.0 globals_0.16.2 Biostrings_2.66.0
[26] tester_0.1.7 matrixStats_1.0.0 timechange_0.2.0 spatstat.sparse_3.0-3 colorspace_2.1-0
[31] blob_1.2.4 xfun_0.37 RCurl_1.98-1.10 crayon_1.5.2 jsonlite_1.8.4
[36] progressr_0.14.0 spatstat.data_3.0-3 impute_1.72.3 survival_3.5-7 zoo_1.8-12
[41] iterators_1.0.14 glue_1.6.2 polyclip_1.10-6 gtable_0.3.3 zlibbioc_1.44.0
[46] XVector_0.38.0 leiden_0.4.3.1 future.apply_1.11.0 BiocGenerics_0.44.0 abind_1.4-5
[51] scales_1.2.1 DBI_1.1.3 spatstat.random_3.2-1 miniUI_0.1.1.1 htmlTable_2.4.1
[56] viridisLite_0.4.2 xtable_1.8-4 reticulate_1.34.0 foreign_0.8-84 bit_4.0.5
[61] preprocessCore_1.60.2 Formula_1.2-5 stats4_4.2.3 htmlwidgets_1.6.2 httr_1.4.5
[66] FNN_1.1.3.2 RColorBrewer_1.1-3 ellipsis_0.3.2 ica_1.0-3 farver_2.1.1
[71] pkgconfig_2.0.3 nnet_7.3-19 uwot_0.1.16 deldir_2.0-2 utf8_1.2.3
[76] labeling_0.4.2 tidyselect_1.2.0 rlang_1.1.0 reshape2_1.4.4 later_1.3.0
[81] AnnotationDbi_1.60.0 munsell_0.5.0 tools_4.2.3 cachem_1.0.7 cli_3.6.0
[86] generics_0.1.3 RSQLite_2.3.1 ggridges_0.5.4 evaluate_0.20 fastmap_1.1.1
[91] yaml_2.3.7 goftest_1.2-3 knitr_1.42 bit64_4.0.5 fitdistrplus_1.1-11
[96] RANN_2.6.1 KEGGREST_1.38.0 pbapply_1.7-2 future_1.33.0 nlme_3.1-163
[101] mime_0.12 compiler_4.2.3 rstudioapi_0.14 plotly_4.10.3 png_0.1-8
[106] spatstat.utils_3.0-4 stringi_1.7.12 lattice_0.20-45 Matrix_1.5-3 vctrs_0.6.0
[111] pillar_1.8.1 lifecycle_1.0.3 spatstat.geom_3.2-7 lmtest_0.9-40 RcppAnnoy_0.0.21
[116] bitops_1.0-7 data.table_1.14.8 irlba_2.3.5.1 httpuv_1.6.9 R6_2.5.1
[121] promises_1.2.0.1 KernSmooth_2.23-22 gridExtra_2.3 IRanges_2.32.0 parallelly_1.36.0
[126] codetools_0.2-19 MASS_7.3-60 withr_2.5.0 sctransform_0.4.1 GenomeInfoDbData_1.2.9 [131] S4Vectors_0.36.0 parallel_4.2.3 hms_1.1.2 rpart_4.1.19 grid_4.2.3
[136] rmarkdown_2.20 Rtsne_0.16 spatstat.explore_3.2-5 base64enc_0.1-3 Biobase_2.58.0
[141] shiny_1.7.4

Thanks again!

smorabit commented 5 months ago

Hi,

As of this time I have tried running the code you provided above but I am unfortunately not able to reproduce this error on my computer. The RunPCAMetacells function is basically just running the Seurat function RunPCA on the metacell dataset. It looks like other people have had this issue with Seurat before, see satijalab/seurat#1788.

It looks like this error can occur when you don't provide the proper features argument. This should be a list of genes from your dataset. For example, I was able to reproduce your error message when I run this line of code:

seurat_obj <- RunPCAMetacells(seurat_obj, features="")
smorabit commented 3 months ago

Closing for now due to inactivity.

xyzheng123 commented 3 months ago

I ran into the same issue you can try: seurat_obj <- FindVariableFeatures(seurat_obj)

before running ScaleMetacells function. This will hopefully resolve the issue. Mentioned by huxiaoti in #15