Подключаем требуемые пакеты

library(igraph)
library(pagoda2)
library(ggplot2)
#library(magrittr)
library(pbapply)

theme_set(theme_bw())

set.seed(2018)

Меняем PCA

path_floder <- DataPath("filtered_gene_bc_matrices/GRCh38")

load_matrix <- pagoda2::read.10x.matrices(path_floder)
load_matrix <- load_matrix[!duplicated(rownames(load_matrix)),]
p2 <- pagoda2::basicP2proc(load_matrix, n.cores=10)

Уточнение произведенное по кластеризации multilevel

p2up <- UpdatePagoda(primary.data = load_matrix, pagoda.obj = p2, clustering.type = 'multilevel',
                      k = c(30, 30, 30, 30, 30), n.cores = 25, embeding.type = 'largeVis')
p2up$getKnnClusters(method = igraph::infomap.community, type = "PCA", name = "infomap")

Validation

conos::embeddingPlot(p2$embeddings$PCA$tSNE, groups=p2$clusters$PCA$multilevel)
conos::embeddingPlot(p2$embeddings$PCA$tSNE, groups=p2$clusters$PCA$infomap)
conos::embeddingPlot(p2$embeddings$PCA$tSNE, groups=p2up$clusters$PCA$infomap)
conos::embeddingPlot(p2$embeddings$PCA$tSNE, groups=p2up$clusters$PCA$multilevel)
conos::embeddingPlot(p2$embeddings$PCA$largeVis, groups=p2$clusters$PCA$infomap)
conos::embeddingPlot(p2up$embeddings$PCA$largeVis,
                     groups=p2$clusters$PCA$infomap)

conos::embeddingPlot(p2$embeddings$PCA$largeVis,
                     groups=p2up$clusters$PCA$infomap)
conos::embeddingPlot(p2up$embeddings$PCA$largeVis,
                     groups=p2up$clusters$PCA$infomap)
change_edge <- CountEdgeChanges(p2$graphs$PCA, p2up$graphs$PCA, 20)
count_change_edge <- unlist(lapply(1:4340, function(i) return(change_edge[[i]][[4]])))
names_ <- unlist(lapply(1:4340, function(i) return(change_edge[[i]][[1]])))

count_change_edge <- as.matrix(x=count_change_edge)
names(count_change_edge) <- names_

print(sum(count_change_edge > 0))
print(sum(count_change_edge < 0))
plot(count_change_edge, panel.last=grid(nx=22, col='red'))
palitre <- scales::rescale(count_change_edge[count_change_edge > -80 & count_change_edge< 80],
                           to=c(-0.5, 0.5))
suppressMessages(
  conos::embeddingPlot(p2$embeddings$PCA$tSNE, colors=palitre, size=0.5, alpha=0.5) + 
        scale_fill_distiller(palette = "Spectral")
)



ficusss/Pagoda2GraphImprovement documentation built on May 8, 2019, 8:58 p.m.