# NOT RUN {
library(igraph)
library(WGCNA)
g_A <- sample_grg(200, 0.15, torus=FALSE, coords = FALSE)
A <- get.adjacency(g_A)
g_B = permute(g_A,c(sample(20),21:200))
B <- get.adjacency(g_B)
cosine_sim_A <- TOMsimilarity(as.matrix(A),TOMType = "unsigned",TOMDenom = "min");
cosine_sim_B <- TOMsimilarity(as.matrix(B),TOMType = "unsigned",TOMDenom = "min")
edgelist_A <- get.edgelist(g_A);
edgelist_B <- get.edgelist(g_B);
if (is.null(E(g_A)$weight))
{
edgelist_A <- cbind(edgelist_A,rep(1,nrow(edgelist_A)));
}else
{
edgelist_A <- cbind(edgelist_A,E(g_A)$weight);
}
if (is.null(E(g_B)$weight))
{
edgelist_B <- cbind(edgelist_B,rep(1,nrow(edgelist_B)));
}else
{
edgelist_B <- cbind(edgelist_B,E(g_B)$weight);
}
edgelist_A <- as.data.frame(edgelist_A);
edgelist_B <- as.data.frame(edgelist_B);
mink <- 7
#Noisy Difference in topological matrices
diff_topological_matrix <- abs(cosine_sim_A-cosine_sim_B);
#Order the nodes in topological graph using greedy approach
ordered_list <- order_topological_matrix(diff_topological_matrix,mink);
temp_output_adjacency <- diff_topological_matrix[ordered_list,ordered_list];
output_adjacency <- prune_edges(temp_output_adjacency,mink);
g_output <- graph_from_adjacency_matrix(output_adjacency,mode=c("undirected"),weighted=TRUE);
#Community detection using Louvain method
louvain_cluster_node_rank <- get_ordered_community_output(g_output,"Louvain",
output_adjacency);
output <- cbind(as.numeric(louvain_cluster_node_rank$NodeIds),
louvain_cluster_node_rank$Predicted_Label)
# }
Run the code above in your browser using DataCamp Workspace