sqjin / scAI

An unsupervised approach for the integrative analysis of single-cell multi-omics data
GNU General Public License v3.0
29 stars 8 forks source link

Can't run selectK #14

Closed f6v closed 4 years ago

f6v commented 4 years ago

I'd appreciate if you could help me out with running selectK. Here's my code:

LIB_PATH = "./R_libs/R-4.0.0/"

library(Seurat)
library(ggplot2)
library(scAI, lib.loc = LIB_PATH)
library(swne, lib.loc = LIB_PATH)

data <- Read10X_h5("./data/multiome_human_brain_3k/human_brain_3k_filtered_feature_bc_matrix.h5")
rna_counts <- data$`Gene Expression`
atac_counts <- data$Peaks
labels <- data.frame(foo = rep(1, dim(atac_counts)[2]))
scAI_outs <- create_scAIobject(raw.data = list("RNA" = rna_counts, "ATAC" = atac_counts), do.sparse = F)
scAI_outs@options$paras$nrun <- 5
scAI_outs <- preprocessing(scAI_outs, assay = NULL)
scAI_outs <- addpData(scAI_outs, pdata = labels, pdata.name = "Cell types")

k_plot <- selectK(scAI_outs)
ggsave("./results/k_plot.pdf", k_plot)

It fails with following:

Error in { : task 1 failed - "invalid arguments"
Calls: selectK -> run_scAI -> %dopar% -> <Anonymous>

I guess I'm doing something wrong, but I didn't find an example for selecting k, maybe you could point me to it? Also I had to add scAI_outs@options$paras$nrun <- 5, otherwise it fails when referencing nrun somewhere in the library.

Thanks in advance!

sqjin commented 4 years ago

Hi @f6v , I just check the details of the function selectK, and found that it uses the parameters such as nrun that was previously set when running run_scAI. In another word, you should first run run_scAI by presetting a k. If you set a larger k (e.g., k = 20, k= 30), it is ok if you only have 15 clusters. Thus you can try a relative larger K to run the analysis. The selectK step often take a while.

f6v commented 4 years ago

Thank you for the tip @sqjin! I'm almost there, I had just one error in the end:

Error in labs(title = feature.name) : object 'feature.name' not found
Calls: selectK -> labs -> list2

I can see feature.name referenced here, but where does it come from?

sqjin commented 4 years ago

Hi @f6v , it is a bug. I just deleted labs(title = feature.name). You can re-install the package to fix the issue. Thanks!

f6v commented 4 years ago

Thanks a lot! I can run selectK now.