Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MetacellsByGroups -> "Error in apply(cell_sample, 1, function(x) { : dim(X) must have a positive length" #290

Open
MJD-BlanckGroup opened this issue Jul 9, 2024 · 5 comments
Labels
question Further information is requested

Comments

@MJD-BlanckGroup
Copy link

Hi all,

Currently running into some difficulty generating metacell groupings. I am working with a relatively small single-cell dataset (dim = 23684 x 3515), but did not expect to run into this much trouble... unable to generate metacells, despite having the pca reduction input, and confirmed "seurat_clusters" metadata loaded into the seurat_obj@meta.data slot. Might anyone have any insight into this error code?

Warning: Data is of class dgeMatrix. Coercing to dgCMatrix.
Error in apply(cell_sample, 1, function(x) { :
dim(X) must have a positive length

Thanks much in advance!!

dat <- read.table("dat, log2tpm.csv", sep = ",", header = 1, row.names = 1)

dat <- (2^dat - 1)
seurat_obj <- CreateSeuratObject(counts = dat, project = "SingleCellProject", assay = "RNA")
if (!inherits(seurat_obj@assays$RNA@layers[["counts"]], "dgCMatrix")) {
  seurat_obj@assays$RNA@layers[["counts"]] <- as(seurat_obj@assays$RNA@layers[["counts"]], "dgCMatrix")
}
seurat_obj <- NormalizeData(seurat_obj)

seurat_obj <- FindVariableFeatures(seurat_obj, selection.method = "vst", nfeatures = 2000)
seurat_obj <- ScaleData(seurat_obj)
seurat_obj <- RunPCA(seurat_obj, features = VariableFeatures(object = seurat_obj))
seurat_obj <- FindNeighbors(seurat_obj, dims = 1:10)
seurat_obj <- FindClusters(seurat_obj, resolution = 0.5)
seurat_obj <- RunUMAP(seurat_obj, dims = 1:10)
seurat_obj <- RunTSNE(seurat_obj, dims = 1:10)

seurat_obj <- SetupForWGCNA(
  seurat_obj,
  gene_select = "fraction"
  fraction = 0.05, 
  wgcna_name = "AOA"
)

seurat_obj <- MetacellsByGroups(
  seurat_obj = seurat_obj,
  group.by = c("seurat_clusters"),
  reduction = "pca",
  k = 20,
  min_cells = 20,
  max_shared = 10,
  ident.group = "seurat_clusters"
)
@MJD-BlanckGroup MJD-BlanckGroup added the question Further information is requested label Jul 9, 2024
@smorabit
Copy link
Owner

smorabit commented Jul 9, 2024

Hi, I have not seen this particular error so I don't know the exact source of your problem. Not sure if this will work but can you please try to raise min_cells such that it is greater than k? Maybe just try the default settings for this function and see if it works.

@sandy627
Copy link

Hi,@smorabit,I also meet this trouble. This problem is also encountered with a large seruat object, but taking a subset of it works perfectly well. Large seurat object with about 100w cells.

@Li-ZhiD
Copy link

Li-ZhiD commented Oct 14, 2024

Same problem. @sandy627 downsampling solved the problem? Thank you!

@smorabit
Copy link
Owner

@sandy627
@Li-ZhiD

Can you please show me the code and error message?

@Li-ZhiD
Copy link

Li-ZhiD commented Oct 15, 2024

Setting ”min_cells = 100“ can solve this problem for my data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants