smorabit / hdWGCNA

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

Module Eigengenes: Adjust the function to permit fewer pcs to be calculated #247

Closed jhaberbe closed 2 weeks ago

jhaberbe commented 1 month ago

Hi,

I've used the hdWGCNA method for a few different analyses, and have run into some issues when trying to use it on a small sample set. From what I've read online, WGCNA can get away with as little as 15 sample and still provide useful results, but when trying to run it on a macrophage dataset (31 samples), I've run into an error computing the ModuleEigengenes, the example code would look like:

seurat_obj <- ModuleEigengenes(seurat_obj, group.by.vars = "specimen")

the seurat object I have prints out the following:

An object of class Seurat 
28206 features across 31 samples within 1 assay 
Active assay: RNA (28206 features, 2000 variable features)
 3 layers present: counts, data, scale.data
 1 dimensional reduction calculated: pca

I would receive an error stating that the number of rows I had was fewer than the number of PCs that I was calculating. I managed to fix the issue pretty quickly by adjusting the number of principal components I was calculating in the ComputeModuleEigengene function. From line 83, I just add the npcs argument:

  cur_pca <- Seurat::RunPCA(
    cur_seurat,
    features = cur_genes,
    reduction.key=paste0('pca', cur_mod),
    verbose=verbose, 
    npcs = 20, ... # added this new argument
  )@reductions$pca

From what I understand about WGCNA, the module eigengene is typically just using the first principal component, I was wondering if the script could be updated to have a standard argument of something like npcs = pc_dim, since you allow the user to choose the PC they want to use themselves.

I will probably put in a pull request where I do that, I hope this explains the issue that I was having and why I'm proposing the change. Please let me know if there is any additional information that would be useful.

smorabit commented 1 month ago

Hi,

I think that you should be able to use the npcs argument already, I tried this:

seurat_obj <- ModuleEigengenes(seurat_obj, npcs=2)

and it runs just fine.

Aside from this, I am very confused as to why you would run hdWGCNA on such a small dataset? You say that you have 31 samples, and ModuleEigengenes works on the single-cell level matrix, so surely you should have enough cells (at least hundreds or thousands) such that this error should not be arising... Can you please clarify?