smorabit/hdWGCNA

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

Dazcam opened this issue · 2 comments

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
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

# get the expression matrix
if(CheckSeurat5()){
expr_mat <- SeuratObject::LayerData(seurat_obj, layer='counts', assay=assay)
} else{
expr_mat <- Seurat::GetAssayData(seurat_obj, slot='counts', assay=assay)
}
# handle different selection strategies
if(gene_select == "fraction"){
# binarize counts matrix in chunks to save memory
n_chunks <- ceiling(ncol(expr_mat) / 10000)
if(n_chunks == 1){
chunks <- factor(rep(1), levels=1)
} else{
chunks <- cut(1:nrow(expr_mat), n_chunks)
}
expr_mat <- do.call(rbind, lapply(levels(chunks), function(x){
cur <- expr_mat[chunks == x,]
cur[cur > 0] <- 1
cur
}))

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

Code
> 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
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?

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.

@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.