Load the library and the data
# load the library
library(aKNNO)
library(data.table)
library(RColorBrewer)
# download the data from GEO
data<-data.frame(fread("https://ftp.ncbi.nlm.nih.gov/geo/series/GSE62nnn/GSE62270/suppl/GSE62270_data_counts_Whole_Organoid_Replicate_2.txt.gz"),row.names=1)
Process the data
# process the data using Seurat
obj<-CreateSeuratObject(counts=data,min.cells=3,min.features=200)
obj <- NormalizeData(obj) %>% FindVariableFeatures() %>% ScaleData() %>% RunPCA() %>% RunUMAP(dims=1:20)
Clustering based on aKNNO (the adaptive k-nearest neighbor graph
with optimization)
# build the optimized adaptive k-nearest neighbor graph
obj<-FindNeighbors_aKNNO(obj,verbose = F)
# clustering on the optimized adaptive k-nearest neighbor graph
obj<-FindClusters(obj,graph.name="aKNN_O",verbose=F)
# visualization
color_aknno <- c(brewer.pal(12,"Paired"))[-11][c(5,1,2,8,4,10,6)]
DimPlot(obj,label=T,repel = T,group.by="aKNN_O_res.0.8",cols = color_aknno)+ggtitle("aKNNO")+NoLegend() -> p_aKNNO
DotPlot(obj[,obj$aKNN_O_res.0.8 %in% 5:6],features=c("Neurog3--chr10","Chgb--chr2","Defa3--chr8","Defa5--chr8"))+theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) -> p_marker
p_aKNNO+p_marker

Comparision between aKNNO, KNN and KNN_high
# build the k-nearest neighbor graph using the same number of dims (1:50) and the method (rann) in the aKNNO
obj<-FindNeighbors(obj,nn.method="rann",dims=1:50,verbose=F)
# clustering based on kNN at the default resolution of 0.8 and a high resolution of 2
obj<-FindClusters(obj,verbose=F)
obj<-FindClusters(obj,resolution=2,verbose=F)
#visualization
color_knn <- c(brewer.pal(12,"Paired"))[-11][c(8,5,1,2)]
color_knn_high <- c(brewer.pal(12,"Paired"))[-c(11)][c(5,2,1,4,8,6,10)]
DimPlot(obj,label=T,repel = T,group.by="RNA_snn_res.0.8",cols = color_knn)+ggtitle("KNN")+NoLegend() -> p_KNN
DimPlot(obj,label=T,repel = T,group.by="RNA_snn_res.2",cols = color_knn_high)+ggtitle("KNN_high")+NoLegend() -> p_KNN_high
p_aKNNO+p_KNN+p_KNN_high

Comparsion between the optimized delta and the default delta
# use the default delta (-0.5) to build the aKNN
obj<-FindNeighbors_aKNN(obj)
# clustering based on the aKNN
obj<-FindClusters(obj,graph.name="aKNN",verbose=F)
#visualization
color_aknn <- brewer.pal(9, "Set1")[c(2,3,4,5,1)]
DimPlot(obj,label=T,repel = T,group.by="aKNN_res.0.8",cols = color_aknn)+ggtitle("aKNN")+NoLegend() -> p_aKNN
obj@misc$aKNNO_delta$plot_delta +ggtitle("delta optimization") -> p_delta
p_aKNNO+p_aKNN+p_delta
