Skip to content

Instantly share code, notes, and snippets.

@kieranrcampbell
Created May 14, 2020 14:38
Show Gist options
  • Save kieranrcampbell/c1d8b4cd0200bf74bef2f6d9e431aa0b to your computer and use it in GitHub Desktop.
Save kieranrcampbell/c1d8b4cd0200bf74bef2f6d9e431aa0b to your computer and use it in GitHub Desktop.
seurat_cluster <- function(sce,
resolution = 0.8,
dims = 1:10,
reduction = "mnn",
algorithm = 1,
return_SCE = TRUE) {
seu <- as.Seurat(sce, counts = "counts", data = "logcounts")
seu <- FindNeighbors(seu, dims = dims, reduction = reduction)
seu <- FindClusters(seu, resolution = resolution, algorithm = algorithm)
sce2 <- as.SingleCellExperiment(seu)
sce$seurat_clusters <- sce2$seurat_clusters
if(return_SCE) {
return(sce)
} else {
return(sce$seurat_clusters)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment