Newman mod in main and new dynamic tree cut plots

This commit is contained in:
Noah L. Schrick 2022-03-24 01:01:49 -05:00
parent 3bbc17aa62
commit 3c4b29b4bc
2 changed files with 31 additions and 2 deletions

View File

@ -7,6 +7,7 @@
library(igraph)
library(igraphdata)
library(WGCNA)
source("self_newman_mod.R")
data(karate)
data(yeast)
@ -49,7 +50,8 @@ plot(g2, main=paste(g2.netname, " Laplace Spectral Clustering"),
########################## Part 2: Newman Modularity ##########################
list(Q=Q,max.lam=max.lam,weights=weights,clusters=clusters) <- newman_mod(g1)
list(Q=Q,max.lam=max.lam,weights=weights,clusters=clusters) <- newman_mod(g2)
##################### Part 3: Recursive Newman Modularity #####################
# Using igraph
@ -105,6 +107,33 @@ g2.TOM
TOMplot(g1.TOM, lap_tree1, main=paste(g1.netname, " Heatmap Plot"))
TOMplot(g2.TOM, lap_tree2, main=paste(g2.netname, " Heatmap Plot"))
# dynamic tree cut
minModuleSize = 2
# degree = 1
dynamicMods1 = cutreeDynamic(dendro = lap_tree1, distM = lap_dist1, deepSplit = 2,
pamRespectsDendro = FALSE, minClusterSize = minModuleSize)
init_mod_sizes <- table(dynamicMods)
# you will have to work through finding and installing labels2colors.
dynamicColors = labels2colors(dynamicMods1)
table(dynamicColors)
plotDendroAndColors(lap_tree1, dynamicColors, "Dynamic Tree Cut", dendroLabels = FALSE,
hang = 0.03, addGuide = TRUE, guideHang = 0.05,
main = paste(g1.netname, "dendogram and dynamic cut modules, degree = 1"))
# degree = 1
dynamicMods2 = cutreeDynamic(dendro = lap_tree2, distM = lap_dist2, deepSplit = 2,
pamRespectsDendro = FALSE, minClusterSize = minModuleSize)
init_mod_sizes <- table(dynamicMods)
# you will have to work through finding and installing labels2colors.
dynamicColors = labels2colors(dynamicMods2)
table(dynamicColors)
plotDendroAndColors(lap_tree2, dynamicColors, "Dynamic Tree Cut", dendroLabels = FALSE,
hang = 0.03, addGuide = TRUE, guideHang = 0.05,
main = paste(g2.netname, "dendogram and dynamic cut modules, degree = 1"))
################################ Part 5: UMAP ################################
g1.dist2 <- 1- as.matrix(g1.adj)
g2.dist2 <- 1- as.matrix(g2.adj)

View File

@ -22,7 +22,7 @@ newman_mod <- function(g, weights=NULL){
#V(g)$color <- ifelse(B[1,]>0,"green","yellow")
V(g)$color <- ifelse(B.eigs$vectors[,1]>0,"green","yellow")
V(g)$size <- 10
plot(g, main=paste(g1.netname, " Newman Modularity"))
plot(g, main=paste(g.netname, " Newman Modularity"))
clust1 = list()
clust2 = list()
clusters = list()