You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无NA值运行Slingshot仍报'Error in if (!useNames)'错误求助

解决Slingshot运行时"missing value where TRUE/FALSE needed"错误

问题背景

在snRNA-seq数据上运行Slingshot工具时,执行以下代码持续报错,已排查确认数据无NA值、聚类标签匹配,更换聚类标签后仍出现相同错误:

sce <- slingshot(sce, clusterLabels = sce$seurat_clusters, reducedDim = "UMAP")
Error in if (!useNames) { : missing value where TRUE/FALSE needed

调用栈信息:

> sce <- slingshot(sce, clusterLabels = sce$slingshot_clusters, reducedDim = "UMAP")
Error in if (!useNames) { : missing value where TRUE/FALSE needed

Enter a frame number, or 0 to exit   

 1: slingshot(sce, clusterLabels = sce$slingshot_clusters, reducedDim = "UMAP")
 2: slingshot(sce, clusterLabels = sce$slingshot_clusters, reducedDim = "UMAP")
 3: .local(data, clusterLabels, ...)
 4: slingshot(data = rd, clusterLabels = cl, reducedDim = NULL, start.clus = start.clus, end.clus = 
 5: slingshot(data = rd, clusterLabels = cl, reducedDim = NULL, start.clus = start.clus, end.clus = 
 6: .local(data, clusterLabels, ...)
 7: getLineages(data, clusterLabels, reducedDim = reducedDim, start.clus = start.clus, end.clus = en
 8: getLineages(data, clusterLabels, reducedDim = reducedDim, start.clus = start.clus, end.clus = en
 9: getLineages(data = data, clusterLabels = clusWeight, ...)
10: getLineages(data = data, clusterLabels = clusWeight, ...)
11: .local(data, clusterLabels, ...)
12: createClusterMST(x = X[use, , drop = FALSE], clusters = clusterLabels[use, , drop = FALSE], outg
13: createClusterMST(x = X[use, , drop = FALSE], clusters = clusterLabels[use, , drop = FALSE], outg
14: .local(x, ...)
15: FUN(x, clusters)
16: .rowstats_w(DelayedArray::DelayedArray(x), group, FUN = DelayedMatrixStats::colWeightedMeans)
17: FUN(x, w = group[, i], ...)
18: FUN(x, w = group[, i], ...)
19: .local(x, w, rows, cols, na.rm, ..., useNames = useNames)
20: .smart_seed_dispatcher(x, generic = MatrixGenerics::colWeightedMeans, blockfun = .DelayedMatrix_
21: candidate(S, ...)
22: matrixStats::colWeightedMeans(x, w = w, rows = rows, cols = cols, na.rm = na.rm, ..., useNames =

解决方法

  • 更新相关依赖包:该错误常因matrixStats、slingshot或DelayedArray版本不兼容导致,优先更新这些包:

    update.packages(c("slingshot", "matrixStats", "DelayedArray"), ask = FALSE)
    
  • 转换降维矩阵为普通矩阵:如果UMAP降维结果是DelayedArray类型,可能引发参数传递问题,转换为常规矩阵后重试:

    reducedDim(sce, "UMAP") <- as.matrix(reducedDim(sce, "UMAP"))
    sce <- slingshot(sce, clusterLabels = sce$seurat_clusters, reducedDim = "UMAP")
    
  • 规范聚类标签类型:确保聚类标签是因子或字符型,避免数值型可能引发的隐式转换问题:

    sce$seurat_clusters <- as.factor(sce$seurat_clusters)
    # 再次确认无NA值
    table(is.na(sce$seurat_clusters))
    
  • 手动指定发育起始/结束聚类:自动推断 lineage 时可能出现异常,手动指定起始和结束聚类缩小计算范围:

    # 替换为实际的聚类ID
    sce <- slingshot(sce, clusterLabels = sce$seurat_clusters, reducedDim = "UMAP", 
                     start.clus = "0", end.clus = c("4", "6"))
    
  • 简化数据测试:取少量细胞子集运行,排查是否因数据量过大或个别异常细胞导致:

    set.seed(123)
    sce_sub <- sce[, sample(ncol(sce), 1000)]
    sce_sub <- slingshot(sce_sub, clusterLabels = sce_sub$seurat_clusters, reducedDim = "UMAP")
    

内容的提问来源于stack exchange,提问作者Toon Leroy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 05:25:54