suppressPackageStartupMessages({
library(magrittr)
library(igraph)
})
library(RColorBrewer)
n <- 60
qual_col_pals <- brewer.pal.info[brewer.pal.info$category == 'qual',]
col_vector <- unlist(mapply(brewer.pal, qual_col_pals$maxcolors, rownames(qual_col_pals)))
Select top 20 PCs of 8 training datasets from CRC paper
wd <- "~/data2/Genomic_Super_Signature/refinebio/data"
data <- readRDS(file.path(wd, "crc_allZ.rds"))
## Select top 10 PCs
ind <- c()
for (i in 1:8) {new_ind = c(1:20)+20*(i-1); ind = c(ind, new_ind)}
dat <- data[,ind] %>% t
res.cor <- stats::cor(t(dat), method = "pearson")
library(reshape2)
df <- melt(as.matrix(res.cor), varnames = c("row", "col"))
df <- df[-which(df$value == 1),] # remove self-comparison
df$value <- abs(df$value) # switch to absolute value
df <- df[which(df$value >= 0.5),]
g <- graph_from_data_frame(df, directed = FALSE)
eb <- cluster_edge_betweenness(g)
plot_dendrogram(eb, mode = "hclust")
col <- col_vector[1:length(unique(eb$membership))]
a <- eb$membership
names(a) <- eb$names
plot.igraph(g, mark.groups = names(a[order(a)]))
##
## Warning: The input is a data frame, convert it to the matrix.
res.cor <- stats::cor(t(dat), method = "spearman")
library(reshape2)
df <- melt(as.matrix(res.cor), varnames = c("row", "col"))
df <- df[-which(df$value == 1),] # remove self-comparison
df$value <- abs(df$value) # switch to absolute value
df <- df[which(df$value >= 0.5),]
g <- graph_from_data_frame(df, directed = FALSE)
eb <- cluster_edge_betweenness(g)
plot_dendrogram(eb, mode = "hclust")
col <- col_vector[1:length(unique(eb$membership))]
a <- eb$membership
names(a) <- eb$names
plot.igraph(g, mark.groups = names(a[order(a)]))
## Warning: The input is a data frame, convert it to the matrix.