diff --git a/Schrick-Noah_CS-7863_Homework-3.R b/Schrick-Noah_CS-7863_Homework-3.R index 599a1b7..c517ceb 100644 --- a/Schrick-Noah_CS-7863_Homework-3.R +++ b/Schrick-Noah_CS-7863_Homework-3.R @@ -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) diff --git a/self_newman_mod.R b/self_newman_mod.R index efa3ad9..26a0005 100644 --- a/self_newman_mod.R +++ b/self_newman_mod.R @@ -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()