smorabit / hdWGCNA

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

Error in if (!(multi.group.by %in% names(seurat_obj@meta.data))) { : argument is of length zero #253

Open Carl6231 opened 1 month ago

Carl6231 commented 1 month ago

Describe the bug when I run the code of hdWGCNA, a error can not be solved by myself. Whether I use official website's files or my own data, I get the same error.. Please help me.

Steps to reproduce

Put code in this box

seurat_obj <- readRDS('Zhou_2020_control.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) Performing log-normalization 0% 10 20 30 40 50 60 70 80 90 100% [----|----|----|----|----|----|----|----|----|----| **| seurat_obj <- SetDatExpr(

  • seurat_obj,
  • group_name = "INH", # the name of the group of interest in the group.by column
  • group.by='cell_type', # the metadata column containing the cell type info. This same column should have also been used in MetacellsByGroups
  • assay = 'RNA', # using RNA assay
  • slot = 'data' # using normalized data
  • ) Error in if (!(multi.group.by %in% names(seurat_obj@meta.data))) { : argument is of length zero seurat_obj <- SetDatExpr(
  • seurat_obj,
  • group_name = c("INH", "EX"),
  • group.by='cell_type'
  • ) Error in SetDatExpr(seurat_obj, group_name = c("INH", "EX"), group.by = "cell_type") : object 's_obj' not found

R session info R version 4.3.1 (2023-06-16) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.6 LTS

smorabit commented 1 month ago

Hi,

There seems to be a problem with your markdown formatting so it is difficult to read your code, can you please re-enter your code into a properly formatted box? Please consult the markdown style guide.