-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFindSubClusters.R
33 lines (28 loc) · 1.54 KB
/
FindSubClusters.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
FindSubClusters<- function(seu, idents, clusters.to.refine, new.cluster.name, resolution){
RenormalizeData<-function(seu, resolution, npcs=20){
DefaultAssay(seu) <- "RNA"
seu <- FindVariableFeatures(seu, selection.method = "vst", nfeatures = 1000,verbose = F)
seu <- ScaleData(seu, features=VariableFeatures(object=seu),verbose = F)
seu <- RunPCA(seu, npcs=npcs, features=VariableFeatures(object=seu),verbose=F)
seu <- FindNeighbors(seu, dims=1:npcs, graph.name ="tmp",verbose = F)
seu <- FindClusters(seu, algorithm=4, resolution=resolution, group.singletons=T, verbose=F, graph.name = "tmp")
return (seu)
}
Idents(seu)<- idents
[email protected][ ,new.cluster.name] <-as.character([email protected][ ,idents] )
message(paste("working on clustername=",idents))
for (cl in clusters.to.refine){
message(paste("processing cluster",cl))
sub <- subset(seu, idents = cl)
sub <- RenormalizeData(sub, resolution=1.0, npcs=20)
tmp_cluster <- paste("tmp_res.",resolution,sep="")
[email protected][,tmp_cluster] <- paste(cl, [email protected][,tmp_cluster] ,sep=".")
metachanged<- [email protected]
cellchanged<- rownames([email protected])
metachanged[cellchanged, new.cluster.name]<[email protected][cellchanged,tmp_cluster]
metachanged-> [email protected]
}
return(seu)
}
FindSubClusters(T.cells, idents="sub_res.1.5", clusters.to.refine=c(9,11),
new.cluster.name="sub_res.1.5_ref1.0",resolution=1.0)[[]]