Closed yamihn closed 5 months ago
Are you able to provide a reproduce this error using the tutorial dataset or just on your own data? It would help me to better understand your problem if you could provide all of the hdWGCNA codde that you ran.
YES of course. It never happened before with clusters with more than 2 modules. anyway, here is the code:
library(Seurat)
library(igraph)
# plotting and data science packages
library(corrplot)
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(123)
# optionally enable multithreading
enableWGCNAThreads(nThreads = 20)
setwd("/home/moduli_trascrizionali/")
# #prepare data
mesp1= readRDS(file= "/home/moduli_trascrizionali/mesp1.rds")
mesp1$condition = mesp1$Set
mesp1@meta.data <- separate(mesp1@meta.data, condition, into = c("genotype", "rep"), sep = 2)
DefaultAssay(mesp1) <- "RNA"
#
genes= mesp1@assays$RNA@data@Dimnames[1]
genes= unlist(genes)
#
mesp1 <- SetupForWGCNA(
mesp1,
gene_select = "fraction", #se metti custom serve la lista di geni
#gene_list= genes, # the gene selection approach
fraction = 0.05, # fraction of cells that a gene needs to be expressed in order to be included
wgcna_name = "mesp1_aSHF" # the name of the hdWGCNA experiment
)
#
#
# # construct metacells in each group
mesp1 <- MetacellsByGroups( seurat_obj = mesp1, assay = "RNA", reduction = "FA",
group.by = c("Cluster", "Set", "genotype"), # specify the columns in mesp1@meta.data to group by
k = 10, # nearest-neighbors parameter,
min_cells = 10,
max_shared = 10, # maximum number of shared cells between two metacells
ident.group = 'Cluster' # set the Idents of the metacell seurat object
)
#
#
# # normalize metacell expression matrix:
mesp1 <- NormalizeMetacells(mesp1)
setwd("/home/moduli_trascrizionali/TOM")
mesp1_C = names(table(mesp1$Cluster))
mesp1 <- SetDatExpr(
mesp1,
group_name = mesp1_C[2],
group.by='Cluster',
assay = 'RNA', # using RNA assay
slot = 'data' # using normalized data
)
#
mesp1 <- TestSoftPowers(
mesp1,
networkType = 'signed' # you can also use "unsigned" or "signed hybrid"
)
# # # plot the results:
plot_list <- PlotSoftPowers(mesp1)
# #
# # # assemble with patchwork
wrap_plots(plot_list, ncol=2)
GetPowerTable(mesp1)
# #
mesp1 <- ConstructNetwork(
mesp1, soft_power=13,
setDatExpr=FALSE,
tom_name = mesp1_C[2],
overwrite_tom= T
# name of the topoligical overlap matrix written to disk
)
# need to run ScaleData first or else harmony throws an error:
mesp1 <- ScaleData(mesp1, features=VariableFeatures(mesp1))
#gc()
PlotDendrogram(mesp1, main='SoM-aSHF hdWGCNA Dendrogram')
# # compute all MEs in the full single-cell dataset
mesp1 <- ModuleEigengenes(
mesp1,
group.by.vars="Cluster"
)
# #
# #
Hi, could you please install the newest version of hdWGCNA and try this again? I found that there was a problem in this function when there is only one module but I think that I resolved it.
Hi, I was running the codes, but in one specific Cluster I got only one module (turquoise) At this point, i get this error:
obj1 <- ModuleConnectivity( obj1, group.by = 'Cluster', group_name = "SoM-aSHF" ) Error in kMEs[cur_gene, ] : incorrect number of dimensions