## ------------------------------------------------------------------------------------------------------------------ suppressPackageStartupMessages({ library(DuoClustering2018) }) scename <- "sce_filteredExpr10_Koh" sce <- sce_filteredExpr10_Koh()方法< - “ PCAHC” ## ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ##加载参数文件。常规数据集和方法参数以及##数据集/方法特定参数参数参数params params <-duo_clustering_all_all_parameter_settings_v2()[[paste0(sceameame ,,“ _”,method)]] params ## -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------###设置每个k#n_rep <-5####运行clustering#set.seed(1234)#l <-lapply(seq_len(n_rep),,function(i){##对于每个运行#cat(paste0(“ run =”,i,“ \ n”))#(分辨率){###对于每个分辨率#cat(paste0(“ andosolution =”,“分辨率”,“ \ n”))###运行clustering#res <-get(paste0(“ apply_”,method))(sce)= sce,params = params,#resolution = resolution = resolution)######数据框架中的输出#df < - data.frame(dataSet = sipeame,#method = method = method = cell = cell = names(res $ cluster),#run= i,#k =长度(unique(res $ cluster)),#分辨率=分辨率,#cluster = res $ cluster,#stringsasfactors = false,row.names = null)#tm < - data.frame(dataSet = sceamem,#method = method = run = i,#k = length(unique(res $ cluster)),#resolution = resolution = resolution,#user.self = res $ st [res $ st [[“ user.self”]],#sys.self = res $ st [[“ sys.sers”],#user.child = res $ st [[“ user.child''],#sys.child = res$st[["sys.child"]], # elapsed = res$st[["elapsed"]], # stringsAsFactors = FALSE, row.names = NULL) # kest <- data.frame(dataset = scename, # method = method, # run = i, # k = length(unique(res$cluster)), # resolution = resolution, # est_k = res$est_k, # stringsAsFactors = FALSE, row.names = NULL) # list(clusters = df, timing = tm, kest = kest) # }) ## End for each resolution # } else { # tmp <- lapply(params$range_clusters, function(k) { ## For each k # cat(paste0("k = ", k, "\n")) # ## Run clustering # res <- get(paste0("apply_", method))(sce = sce, params = params, k = k) # # ## Put output in data frame # df <- data.frame(dataset = scename, # method = method, # cell = names(res$cluster), # run = i, # k = k, # resolution = NA, # cluster = res$cluster, # stringsAsFactors = FALSE, row.names = NULL) # tm <- data.frame(dataset = scename, # method = method, # run = i, # k = k, # resolution = NA, # user.self = res$st[["user.self"]], # sys.self = res$st[["sys.self"]], # user.child = res$st[["user.child"]], # sys.child = res$st[["sys.child"]], # elapsed = res$st[["elapsed"]], # stringsAsFactors = FALSE, row.names = NULL) # kest <- data.frame(dataset = scename, # method = method, # run = i, # k = k, # resolution = NA, # est_k = res$est_k, # stringsAsFactors = FALSE, row.names = NULL) # list(clusters = df, timing = tm, kest = kest) # }) ## End for each k # } # # ## Summarize across different values of k # assignments <- do.call(rbind, lapply(tmp, function(w) w$clusters)) # timings <- do.call(rbind, lapply(tmp, function(w) w$timing)) # k_estimates <- do.call(rbind, lapply(tmp, function(w) w$kest)) # list(assignments = assignments, timings = timings, k_estimates = k_estimates) # }) ## End for each run # # ## Summarize across different runs # assignments <- do.call(rbind, lapply(L, function(w) w$assignments)) # timings <- do.call(rbind, lapply(L, function(w) w$timings)) # k_estimates <- do.call(rbind, lapply(L, function(w) w$k_estimates)) # # ## Add true group for each cell # truth <- data.frame(cell = as.character(rownames(colData(sce))), # trueclass = as.character(colData(sce)$phenoid), # stringsAsFactors = FALSE) # assignments$trueclass <- truth$trueclass[match(assignments$cell, truth$cell)] # # ## Combine results # res <- list(assignments = assignments, timings = timings, # k_estimates = k_estimates) # # df <- dplyr::full_join(res$assignments %>% # dplyr::select(dataset, method, cell, run, k, # resolution, cluster, trueclass), # res$k_estimates %>% # dplyr::select(dataset, method, run, k, # resolution, est_k) # ) %>% dplyr::full_join(res$timings %>% dplyr::select(dataset, method, run, k, # resolution, elapsed)) ## ----------------------------------------------------------------------------- sessionInfo()