240 发简信
IP属地:江苏
  • 我顺便把LouvainKRange 也写一下,方便后来人复现。感谢楼主
    LouvainKRange <- function(data.obj, kmin = 5, kmax = 50, kstep = 5) {
    require(igraph, quietly = TRUE)
    # check if seurat object
    if (class(data.obj)[1] == "Seurat") {
    dist.mat <- data.obj@assays[[data.obj@active.assay]]@misc$dist.mat
    } else {
    dist.mat <- data.obj
    }
    # create lists
    cluster.list <- list()
    sil.list <- list()
    # setup iteration
    k <- kmin
    while (k <= kmax) {
    print(paste("Clustering with k = ", k, "...", sep = ''))
    # generate clustering and silhouette score
    clust.vec <- LouvainClust(dist.mat, k)
    sil.score <- cluster::silhouette(clust.vec, dist.mat)
    # add to list
    k.ind <- paste('k', k, sep = '.')
    cluster.list[[k.ind]] <- clust.vec
    sil.list[[k.ind]] <- mean(sil.score[,3])
    # iterate
    k <- k + kstep
    }
    # identify optimal cluster
    opt.clust <- cluster.list[[which.max(sil.list)]]
    # add to data.object
    if (class(data.obj)[1] == "Seurat") {
    data.obj@assays[[data.obj@active.assay]]@misc[['pisces.cluster']] <- opt.clust
    data.obj@assays[[data.obj@active.assay]]@misc[['clustering.obj']] <- list('clusterings' = cluster.list, 'sils' = sil.list)
    return(data.obj)
    } else {
    return(list('pisces.cluster' = opt.clust, 'clustering.obj' = list('clusterings' = cluster.list, 'sils' = sil.list)))
    }
    }

    基于单细胞测序的蛋白活性推断(PISCES)分析流程笔记,凎!

    写在前面 感谢califano-lab[https://github.com/califano-lab]团队将代码无私的分享出来=。=! 本流程需要一点点R语言与linux基...