phillipnicol / scDist

Robust identification of perturbed cell types in single-cell RNA-seq data
MIT License
24 stars 1 forks source link

Error: grouping factors must have > 1 sampled level #12

Closed yecotoo closed 2 weeks ago

yecotoo commented 1 month ago

out <- scDist(normalized_counts = sim$Y,

phillipnicol commented 1 month ago

My first guess would be that there is a cluster in seurat_clusters such that all of the cells belong to one group. You can check this by table(sim$meta.data$group, seurat_clusters).

In this case, you can just remove that cluster... But I can also edit the code to just return 0 for that cell type if this happens.

yecotoo commented 1 month ago

Thanks for reply! I checked my data and find cluster 6 in such that all of the cells belong to one group. table(sim$meta.data$group, sim$meta.data$seurat_clusters)
0 1 2 3 4 5 6 7 8 9 SCI_3dpi 1663 2152 260 593 381 90 0 19 26 9 SCI_1dpi 15 6 1441 696 100 95 163 106 4 16 I would be appreciated if you could edit the code. Thanks!

yecotoo commented 1 month ago

My first guess would be that there is a cluster in such that all of the cells belong to one group. You can check this by .seurat_clusters``table(sim$meta.data$group, seurat_clusters)

In this case, you can just remove that cluster... But I can also edit the code to just return 0 for that cell type if this happens.

Hello! I met this error again after I remove cluster 6. And I don't know why. I put my data information below. out <- scDist(normalized_counts = sim$Y,

image

yecotoo commented 1 month ago

Interesting, When the "random.effects = c("celltype", "orig.ident")" was commented out. It worked and show me this warning below. I wonder if the code of the "random.effect" function need to be fixed as the "fixed.effects"? out <- scDist(normalized_counts = sim$Y,

yecotoo commented 1 month ago

Sorry to bother, when I tried this in another data, something new happened. The normalization method I used is not SCT, Could it be the reason of this error?

> out <- scDist(normalized_counts = sim$Y, + meta.data = sim$meta.data, + d = 15, + fixed.effects = "group", + #random.effects = c("celltype", "orig.ident"), + clusters="seurat_clusters", + min.counts.per.cell = 1, + ) ============================================================(function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth = TRUE, Warning Here: You're computing too large a percentage of total singular values, use a standard svd instead. ===============Error in (function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth = TRUE, : max(nu, nv) must be strictly less than min(nrow(A), ncol(A)).
phillipnicol commented 1 month ago

First, the errors and warnings in function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth = TRUE) are related to the PCA step. Basically, if there is a cluster with less than d=15 cells then it is not possible to get 15 PCs. I will go into the code and make sure min.counts.per.cell is greater than d. It is fine to use the method without scTransform, we just wanted to make a recommendation.

Regarding the previous error, it would definitely be the case that cluster 6 would cause the grouping factor to have only one sampled level. But I'm not sure why it would persist after cluster 6 was removed like you said. One thing to try would be moving orig.ident to a fixed effect by writing fixed.effects=c("group, orig.ident"). The reason is that the mixed model might not have much power when you only have 2 samples in one group, I also wrote about that in Issue #4. Also, can I ask what is the celltype variable? If it is really the cell type, then that should be what goes in the cluster argument.

phillipnicol commented 1 month ago

I have edited some code that I think will automatically detect if any of the random or fixed effects have only level for a particular cell type. You can install this developmental version of the package with devtools::install_github("phillipnicol/scDist", ref="sampling_level"). This also checks that the minimum number of cells is larger than the chosen number of PCs, so it should also address the other errors that you encountered.

Let me know if it works for you and then I can integrate it into the main package.

phillipnicol commented 2 weeks ago

The code fixing this is included in the updated package.