smorabit / hdWGCNA

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

SetupForWGCNA: Error in cur[cur > 0] <- 1 : object of type 'S4' is not subsettable #289

Closed Dazcam closed 2 weeks ago

Dazcam commented 2 weeks ago

I'm running the basic hdWGCNA pipeline using a set of large Seurat 5 objects that were generated using BP Cells to allow storage of large expression matrices on disk rather than in memory.

When running the SetupForWGCNA() with recommended settings in the vignette I get the following error:

Code ```r 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 ) #> SetupForWGCNA: Error in cur[cur > 0] <- 1 : object of type 'S4' is not subsettable ```

I think this error is being thrown by line 63 of the SelectNetworkGenes() function:

Code https://github.com/smorabit/hdWGCNA/blob/4f2da14ec4bdbe5013679ae65a9d4a612a0c77e2/R/SelectNetworkGenes.R#L43-L65

I suspect this is caused as expr_mat stored in lines 43-47 is not an expression matrix as expected, but the following:

Code ```r > SeuratObject::LayerData(seurat_obj, layer='counts', assay='RNA') 27379 x 66782 IterableMatrix object with class RenameDims Row names: ABCA13, PENK-AS1 ... SLC7A7 Col names: 10X318_7:GGGTTTAGTTACGATC, 10X318_8:CCCGGAAGTGACTGAG ... 10X145_3:AACAGGGCAGCCGTCA Data type: double Storage order: column major Queued Operations: 1. Concatenate cols of 12 matrix objects with classes: RenameDims, RenameDims ... RenameDims (threads=0) 2. Select rows: 1, 2 ... 27379 and cols: 1, 5345 ... 49485 3. Reset dimnames ```

However, the function runs as expected when using the pared down Seurat sketch object (DefaultAssay(seurat_obj) <- 'sketch') which is stored in memory, but then it chokes when running MetacellsByGroups():

Code ```r seurat_obj <- hdWGCNA::MetacellsByGroups( seurat_obj = seurat_obj, group.by = c("cellIDs", "Sample"), # specify the columns in seurat_obj@meta.data to group by reduction = 'umap', # 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 = 'cellIDs', # set the Idents of the metacell seurat object ) #> Error in `as.Graph()`: #> ! Please provide rownames to the matrix before converting to a Graph ```

Not 100% sure what is going on with this one. Could it be that Seurat 5 sketch objects, by necessity, have NAs in the metadata?

Is there functionality (current or proposed) to handle Seurat 5 BPCells and sketch objects with hdWGCNA?

smorabit commented 2 weeks ago

Hi, thanks for taking the time to write this issue.

Is there functionality (current or proposed) to handle Seurat 5 BPCells and sketch objects with hdWGCNA?

hdWGCNA was built prior to Seurat v5, and thus we don't have any way to handle BPCells or sketch objects. I don't have any experience using these data types and I don't have any plans to get them to work with hdWGNCA.

Dazcam commented 2 weeks ago

@smorabit Thanks for the quick response.

No problem. These new methods were introduced as part of Seurat 5 to handle very large datasets. One wonders whether they will be widely adopted by the community or not.