GreenleafLab / MPAL-Single-Cell-2019

Publication Page for MPAL Paper 2019
77 stars 39 forks source link

Seurat v3 #5

Closed edward130603 closed 4 years ago

edward130603 commented 4 years ago

Several functions do not work with Seurat v3. Will the code provided be maintained for compatibility with Seurat v3?

jgranja24 commented 4 years ago

I think this should work for seurat v3, let me know.

seuratSNN <- function(matSVD, dims.use = 1:50, ...){ set.seed(1) message("Making Seurat Object...") tmp <- matrix(rnorm(nrow(matSVD) * 3, 10), ncol = nrow(matSVD), nrow = 3) colnames(tmp) <- rownames(matSVD) rownames(tmp) <- paste0("t",seqlen(nrow(tmp))) obj <- Seurat::CreateSeuratObject(tmp, project='scATAC', min.cells=0, min.features=0) obj[['pca']] <- Seurat::CreateDimReducObject(embeddings=mat, key='PC', assay='RNA') clustParams <- list() clustParams$object <- obj clustParams$reduction <- "pca" clustParams$object <- suppressWarnings(do.call(Seurat::FindNeighbors, clustParams)) obj <- suppressWarnings(do.call(Seurat::FindClusters, clustParams))

Get Output

clust <- obj@meta.data[,ncol(obj@meta.data)]
clust <- paste0("Cluster",match(clust, unique(clust)))
names(clust) <- rownames(mat)
clust

}

mohit1997 commented 4 years ago

Edit, mat is not defined error will appear with the above edit. I am using matSVD instead of mat.

seuratSNN <- function(matSVD, dims.use = 1:50, ...){
set.seed(1)
message("Making Seurat Object...")
tmp <- matrix(rnorm(nrow(matSVD) * 3, 10), ncol = nrow(matSVD), nrow = 3)
colnames(tmp) <- rownames(matSVD)
rownames(tmp) <- paste0("t",seq_len(nrow(tmp)))
obj <- Seurat::CreateSeuratObject(tmp, project='scATAC', min.cells=0, min.features=0)
obj[['pca']] <- Seurat::CreateDimReducObject(embeddings=matSVD, key='PC_', assay='RNA')
clustParams <- list()
clustParams$object <- obj
clustParams$reduction <- "pca"
clustParams$object <- suppressWarnings(do.call(Seurat::FindNeighbors, clustParams))
obj <- suppressWarnings(do.call(Seurat::FindClusters, clustParams))
#Get Output
clust <- obj@meta.data[,ncol(obj@meta.data)]
clust <- paste0("Cluster",match(clust, unique(clust)))
names(clust) <- rownames(matSVD)
clust
}