suppressPackageStartupMessages({
library(igraph)
library(dplyr)
})
bs_dir <- "~/data2/Genomic_Super_Signature/refinebio/bootstrap/data"
pos <- readRDS(file.path(bs_dir, "bootstrap_PCs_rowNorm_Pos.rds"))
neg <- readRDS(file.path(bs_dir, "bootstrap_PCs_rowNorm_Neg.rds"))
data <- lapply(c(pos, neg), function(x) x$rotation) %>% Reduce(cbind,.) %>% t
topPCs = 20
numOfDataset = 20
PCsToInclude = 5
ind <- c()
for (i in 1:numOfDataset) {new_ind = c(1:PCsToInclude)+topPCs*(i-1); ind = c(ind, new_ind)}
dat <- data[ind,]
Use absolute value of Spearman correlation for graph buildling.
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)]),
mark.col = rep(col, table(a)))
Use absolute value of Pearson correlation for graph buildling.
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)]),
mark.col = rep(col, table(a)))