}) %>% t %>% data.frame %>% set_names(metrics) %>% mutate(Network = topoFiles %>% str_remove(".topo")) df <- sapply(topoFiles, function(topoFile) { freqDf <- read_csv(str_replace(topoFile, ".topo", "_finFlagFreq.csv"), col_types = cols(), lazy = F) %>% filter(flag == 1) if (nrow(freqDf) < 3) return(rep(NA, 17)) frust <- freqDf$frust0 freq <- freqDf$Avg0 coh <- freqDf$coherence0 frustration <- c(frust %>% min(na.rm = T), frust %>% max(na.rm = T), frust %>% mean(na.rm = T), frust*freq %>% sum(na.rm = T)) coherence <- c(coh %>% min(na.rm = T), coh %>% max(na.rm = T), coh %>% mean(na.rm = T), coh*freq %>% sum(na.rm = T)) cohFreq <- cor.test(coh, freq, method = "spearman") cohFrust <- cor.test(coh, frust, method = "spearman") freqFrust <- cor.test(freq, frust, method = "spearman") cors <- c(freqFrust$estimate, freqFrust$p.value, cohFreq$estimate, cohFreq$p.value, cohFrust$estimate, cohFrust$p.value) bimodalities <- c(bimodality_coefficient(freq), bimodality_coefficient(frust), bimodality_coefficient(coh)) c(frustration, coherence, cors, bimodalities) }) %>% t %>% data.frame View(df) topoFile <- topoFiles[1] freqDf <- read_csv(str_replace(topoFile, ".topo", "_finFlagFreq.csv"), col_types = cols(), lazy = F) %>% filter(flag == 1) if (nrow(freqDf) < 3) return(rep(NA, 17)) frust <- freqDf$frust0 freq <- freqDf$Avg0 coh <- freqDf$coherence0 frustration <- c(frust %>% min(na.rm = T), frust %>% max(na.rm = T), frust %>% mean(na.rm = T), frust*freq %>% sum(na.rm = T)) coherence <- c(coh %>% min(na.rm = T), coh %>% max(na.rm = T), coh %>% mean(na.rm = T), coh*freq %>% sum(na.rm = T)) cohFreq <- cor.test(coh, freq, method = "spearman") cohFrust <- cor.test(coh, frust, method = "spearman") freqFrust <- cor.test(freq, frust, method = "spearman") cors <- c(freqFrust$estimate, freqFrust$p.value, cohFreq$estimate, cohFreq$p.value, cohFrust$estimate, cohFrust$p.value) bimodalities <- c(bimodality_coefficient(freq), bimodality_coefficient(frust), bimodality_coefficient(coh)) c(frustration, coherence, cors, bimodalities) df <- sapply(topoFiles, function(topoFile) { freqDf <- read_csv(str_replace(topoFile, ".topo", "_finFlagFreq.csv"), col_types = cols(), lazy = F) %>% filter(flag == 1) if (nrow(freqDf) < 3) return(rep(NA, 17)) frust <- freqDf$frust0 freq <- freqDf$Avg0 coh <- freqDf$coherence0 frustration <- c(frust %>% min(na.rm = T), frust %>% max(na.rm = T), frust %>% mean(na.rm = T), frust*freq %>% sum(na.rm = T)) coherence <- c(coh %>% min(na.rm = T), coh %>% max(na.rm = T), coh %>% mean(na.rm = T), coh*freq %>% sum(na.rm = T)) cohFreq <- cor.test(coh, freq, method = "spearman") cohFrust <- cor.test(coh, frust, method = "spearman") freqFrust <- cor.test(freq, frust, method = "spearman") cors <- c(freqFrust$estimate, freqFrust$p.value, cohFreq$estimate, cohFreq$p.value, cohFrust$estimate, cohFrust$p.value) bimodalities <- c(bimodality_coefficient(freq), bimodality_coefficient(frust), bimodality_coefficient(coh)) c(frustration, coherence, cors, bimodalities) }) df[[1]] sapply(df, length) coh %>% min(na.rm = T) coh %>% max(na.rm = T) coh %>% mean(na.rm = T) coh*freq %>% sum(na.rm = T) coh*freq coh freq x <- coh*freq sum(x) coh*freq %>% sum(na.rm = T) coherence <- c(coh %>% min(na.rm = T), coh %>% max(na.rm = T), coh %>% mean(na.rm = T), sum(coh*freq,na.rm = T)) source("D:/Github/Rpackages/Teams/R/compileData.R") AllDataFile(net) source("D:/Github/Rpackages/Teams/R/utils.R") AllDataFile(net) AllDataFile(net) metrics <- c("minFrust", "maxFrust", "meanFrust", "meanNetFrust", "minCoh", "maxCoh", "meanCoh", "meanNetCoh", "corFreqFrust", "pFreqFrust", "corFreqCoh", "pFreqCoh", "corFrustCoh", "pFrustCoh", "bmSSF", "bmCoh", "bmFrust") topoFiles <- list.files(".", ".topo$") df <- sapply(topoFiles, function(topoFile) { freqDf <- read_csv(str_replace(topoFile, ".topo", "_finFlagFreq.csv"), col_types = cols(), lazy = F) %>% filter(flag == 1) if (nrow(freqDf) < 3) return(rep(NA, 17)) frust <- freqDf$frust0 freq <- freqDf$Avg0 coh <- freqDf$coherence0 frustration <- c(frust %>% min(na.rm = T), frust %>% max(na.rm = T), frust %>% mean(na.rm = T), sum(frust*freq,na.rm = T)) coherence <- c(coh %>% min(na.rm = T), coh %>% max(na.rm = T), coh %>% mean(na.rm = T), sum(coh*freq,na.rm = T)) cohFreq <- cor.test(coh, freq, method = "spearman") cohFrust <- cor.test(coh, frust, method = "spearman") freqFrust <- cor.test(freq, frust, method = "spearman") cors <- c(freqFrust$estimate, freqFrust$p.value, cohFreq$estimate, cohFreq$p.value, cohFrust$estimate, cohFrust$p.value) bimodalities <- c(bimodality_coefficient(freq), bimodality_coefficient(frust), bimodality_coefficient(coh)) c(frustration, coherence, cors, bimodalities) }) getwd() setwd("..") source("D:/Github/Rpackages/Teams/R/compileData.R") AllDataFile(net) AllDataFileNoFlag(net) # Multinode Perturbation setwd(gsCausation) setwd(net) topoFiles <- list.files(".", ".topo$") logDf <- read.csv("LogFile.csv") sapply(topoFiles, CoherenceAllNode, logDf = logDf) source("D:/Github/Rpackages/Teams/R/coherence.R") sapply(topoFiles, CoherenceAllNode, logDf = logDf) source("D:/Github/Rpackages/Teams/R/coherence.R") sapply(topoFiles, CoherenceAllNode, logDf = logDf) source("D:/Github/Rpackages/Teams/R/coherence.R") sapply(topoFiles, CoherenceAllNode, logDf = logDf) devtools::load_all() ?require devtools::install_github("askhari139/Teams") devtools::install_github("askhari139/Teams") devtools::install_github("askhari139/Teams") library(Teams) ### Setup data folder structure SetupFunc(mainFolder = "D:/TeamsTest", topoFolder = "D:/TopoFiles", numThreads = 3) Teams:: paths <- readRDS("C:/Users/askha/OneDrive/Documents/R/win-library/4.1/Teams/help/paths.rds") setwd("D:/Github/Projects/Ongoing/Canalilzation/topos/topoFiles") setwd("D:/Github/Projects/Ongoing/Canalilzation/RandomNetworkAnalysis/EffectivenessGs") Analysis <- function() { topoFiles <- list.files(".", ".topo$") sapply(topoFiles, function(x) { topoDf <- read.delim(x, sep = "", row.names = NULL) %>% mutate_if(is.character, str_replace_all, pattern = regex("\\W+"), replace = "") %>% mutate(Type = ifelse(Type == 1, 1, 2)) write_delim(topoDf, x, delim = " ", quote = "none") }) } library(tidyverse) library(miscFuncs) setwd("D:/Github/Projects/Ongoing/Canalilzation/RandomNetworkAnalysis/EffectivenessGs") dirs <- list.dirs(".", recursive = F) sapply(dirs, function(x) { setwd(x) Analysis() LogFileGen() GroupStrengthAll(x %>% str_remove("./"), plotOut = T) setwd("..") }) source("D:/Github/Rpackages/Teams/R/influenceAndGs.R") library(compiler) source("D:/Github/Rpackages/Teams/R/influenceAndGs.R") source("D:/Github/Rpackages/Teams/R/topoGenAndSim.R") setwd("D:/Github/Projects/Ongoing/Canalilzation/RandomNetworkAnalysis/EffectivenessGs") dirs <- list.dirs(".", recursive = F) sapply(dirs, function(x) { setwd(x) Analysis() LogFileGen() GroupStrengthAll(x %>% str_remove("./"), plotOut = T) setwd("..") }) source("D:/Github/Rpackages/Teams/R/utils.R") setwd("D:/Github/Projects/Ongoing/Canalilzation/RandomNetworkAnalysis/EffectivenessGs") dirs <- list.dirs(".", recursive = F) sapply(dirs, function(x) { setwd(x) Analysis() LogFileGen() GroupStrengthAll(x %>% str_remove("./"), plotOut = T) setwd("..") }) getwd() topoFiles <- list.files(".", ".topo") sapply(dirs[-1], function(x) { setwd(x) Analysis() LogFileGen() GroupStrengthAll(x %>% str_remove("./"), plotOut = T) setwd("..") }) setwd("D:/Github/Projects/Ongoing/Canalilzation/RandomNetworkAnalysis/EffectivenessGs") sapply(dirs[-1], function(x) { setwd(x) Analysis() LogFileGen() GroupStrengthAll(x %>% str_remove("./"), plotOut = T) setwd("..") }) setwd("D:/Github/Projects/Ongoing/Canalilzation/RandomNetworkAnalysis/EffectivenessGs") dirs <- list.dirs(".", recursive = F) sapply(dirs[-1], function(x) { setwd(x) Analysis() LogFileGen() GroupStrengthAll(x %>% str_remove("./"), plotOut = T) setwd("..") }) sapply(dirs, function(x) { x <- x %>% str_remove("./") df <- read_csv(paste0(x, "/CompiledData/", x, "_TeamStrengths.csv"), lazy = F) df$Type <- df$Network %>% str_extract("_del_.*") %>% str_remove("_del_") df$Type[is.na(df$Type)] <- "original" df$Network <- df$Network %>% str_remove("_del_.*") # df$Class <- ifelse(str_detect(df$Network, "_\\d"), "Rand", "WT") df1 <- df %>% gather(key = "Group", value = "Strength", -Network, -Type) %>% spread(key = Type, value = Strength) %>% drop_na %>% gather(key = "Type", value = "Strength",-Network, -Group) ggplot(df1, aes(x = Type, y = Strength)) + geom_boxplot() + facet_wrap(~Group, ncol = 2, scales = "free_y") + theme_Publication() + theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust = 1)) ggsave(paste0(x, "_strengthDist.png"), width = 7, height = 9) }) sapply(dirs, function(x) { x <- x %>% str_remove("./") df <- read_csv(paste0(x, "/CompiledData/", x, "_TeamStrengths.csv"), lazy = F) df$Type <- df$Network %>% str_extract("_del_.*") %>% str_remove("_del_") df$Type[is.na(df$Type)] <- "original" df$Network <- df$Network %>% str_remove("_del_.*") # df$Class <- ifelse(str_detect(df$Network, "_\\d"), "Rand", "WT") df1 <- df %>% gather(key = "Group", value = "Strength", -Network, -Type) %>% spread(key = Type, value = Strength) %>% drop_na %>% gather(key = "Type", value = "Strength",-Network, -Group) ggplot(df1, aes(x = Type, y = Strength)) + geom_boxplot() + facet_wrap(~Group, ncol = 2, scales = "free_y") + theme_Publication() + labs(title = x) + theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust = 1)) ggsave(paste0(x, "_strengthDist.png"), width = 7, height = 9) }) setwd("D:/Github/Rpackages/Teams") library(philentropy) library(tidyverse) discretFunc <- function(x) { x <- (x- mean(x))/sd(x) ifelse(x > 0, 1, 0) } naZero <- function(df) { df[is.na(df)] <- 0 df } jsdCalc <- function(WT, n2) { WTNodes <- read.delim(paste0(WT, ".prs")) %>% filter(str_detect(Parameter, "Prod")) %>% select(Parameter) %>% unlist %>% str_remove("Prod_of_") write.csv(WTNodes, "WTNodes.csv", row.names = F) WTSols <- read_delim(paste0(WT, "_solution.dat"), delim = "\t", col_names = F) %>% set_names(c("ParIndex", "nStates", "Basin", WTNodes)) write.csv(WTSols, "WTsols1.csv", row.names = F) WTSols[, -(1:3)] <- WTSols %>% select(all_of(WTNodes)) %>% sapply(discretFunc) WTSols <- WTSols %>% group_by(across(all_of(WTNodes))) %>% summarise(Count = n(), .groups = "drop") %>% mutate(Frequency = Count/sum(Count)) write.csv(WTSols, "WTsols2.csv", row.names = F) n2Nodes <- read.delim(paste0(n2, ".prs")) %>% filter(str_detect(Parameter, "Prod")) %>% select(Parameter) %>% unlist %>% str_remove("Prod_of_") write.csv(n2Nodes, "n2Nodes.csv", row.names = F) n2Sols <- read_delim(paste0(n2, "_solution.dat"), delim = "\t", col_names = F) %>% set_names(c("ParIndex", "nStates", "Basin", n2Nodes)) write.csv(n2Sols, "n2Sols.csv", row.names = F) n2Sols[, -(1:3)] <- n2Sols %>% select(all_of(WTNodes)) %>% sapply(discretFunc) n2Sols <- n2Sols %>% group_by(across(all_of(n2Nodes))) %>% summarise(Count = n(), .groups = "drop") %>% mutate(Frequency = Count/sum(Count)) write.csv(n2Sols, "n2Sols1.csv", row.names = F) if (all(WTNodes %in% n2Nodes)) { n2Sols <- n2Sols %>% select(all_of(WTNodes), Frequency) %>% unite("State", all_of(WTNodes), sep = "") WTSols <- WTSols %>% select(all_of(WTNodes), Frequency) %>% unite("State", all_of(WTNodes), sep = "") %>% merge(n2Sols, by = "State", all = T) %>% naZero %>% select(contains("Frequency")) %>% t%>% JSD } else { commons <- WTNodes[which(WTNodes %in% n2Nodes)] n2Sols <- n2Sols %>% select(all_of(commons), Frequency) %>% unite("State", all_of(commons), sep = "") WTSols <- WTSols %>% group_by(across(all_of(commons))) %>% summarise(Frequency = sum(Frequency), .groups = "drop") %>% select(all_of(commons), Frequency) %>% unite("State", all_of(commons), sep = "") %>% merge(n2Sols, by = "State", all = T) %>% naZero %>% select(contains("Frequency")) %>% t%>% JSD } WTSols } nets <- c("EMT_RACIPE", "EMT_RACIPE2", "SIL", "silviera2", "EMT_MET_reduced") df <- sapply(nets, function(net) { WT <- net n1 <- paste0(net, "_del_bottom5") n2 <- paste0(net, "_del_top5") jsd <- c(jsdCalc(WT, n1), jsdCalc(WT, n2), jsdCalc(n1, n2)) print(jsd) }) %>% t %>% data.frame %>% set_names(c("WTbottom", "WTtop", "bottomTop")) df <- sapply(nets, function(net) { print(net) WT <- net n1 <- paste0(net, "_del_bottom5") n2 <- paste0(net, "_del_top5") jsd <- c(jsdCalc(WT, n1), jsdCalc(WT, n2), jsdCalc(n1, n2)) }) %>% t %>% data.frame %>% set_names(c("WTbottom", "WTtop", "bottomTop")) debug(jsdCalc) df <- sapply(nets, function(net) { print(net) WT <- net n1 <- paste0(net, "_del_bottom5") n2 <- paste0(net, "_del_top5") jsd <- c(jsdCalc(WT, n1), jsdCalc(WT, n2), jsdCalc(n1, n2)) }) %>% t %>% data.frame %>% set_names(c("WTbottom", "WTtop", "bottomTop")) getwd() setwd("D:/Github/Projects/Ongoing/Canalilzation/RACIPE") df <- sapply(nets, function(net) { print(net) WT <- net n1 <- paste0(net, "_del_bottom5") n2 <- paste0(net, "_del_top5") jsd <- c(jsdCalc(WT, n1), jsdCalc(WT, n2), jsdCalc(n1, n2)) }) %>% t %>% data.frame %>% set_names(c("WTbottom", "WTtop", "bottomTop")) jsdCalc <- function(WT, n2) { WTNodes <- read.delim(paste0(WT, ".prs")) %>% filter(str_detect(Parameter, "Prod")) %>% select(Parameter) %>% unlist %>% str_remove("Prod_of_") write.csv(WTNodes, "WTNodes.csv", row.names = F) WTSols <- read_delim(paste0(WT, "_solution.dat"), delim = "\t", col_names = F) %>% set_names(c("ParIndex", "nStates", "Basin", WTNodes)) write.csv(WTSols, "WTsols1.csv", row.names = F) WTSols[, -(1:3)] <- WTSols %>% select(all_of(WTNodes)) %>% sapply(discretFunc) WTSols <- WTSols %>% group_by(across(all_of(WTNodes))) %>% summarise(Count = n(), .groups = "drop") %>% mutate(Frequency = Count/sum(Count)) write.csv(WTSols, "WTsols2.csv", row.names = F) n2Nodes <- read.delim(paste0(n2, ".prs")) %>% filter(str_detect(Parameter, "Prod")) %>% select(Parameter) %>% unlist %>% str_remove("Prod_of_") write.csv(n2Nodes, "n2Nodes.csv", row.names = F) n2Sols <- read_delim(paste0(n2, "_solution.dat"), delim = "\t", col_names = F) %>% set_names(c("ParIndex", "nStates", "Basin", n2Nodes)) write.csv(n2Sols, "n2Sols.csv", row.names = F) n2Sols[, -(1:3)] <- n2Sols %>% select(all_of(WTNodes)) %>% sapply(discretFunc) n2Sols <- n2Sols %>% group_by(across(all_of(n2Nodes))) %>% summarise(Count = n(), .groups = "drop") %>% mutate(Frequency = Count/sum(Count)) write.csv(n2Sols, "n2Sols1.csv", row.names = F) if (all(WTNodes %in% n2Nodes)) { n2Sols <- n2Sols %>% select(all_of(WTNodes), Frequency) %>% unite("State", all_of(WTNodes), sep = "") WTSols <- WTSols %>% select(all_of(WTNodes), Frequency) %>% unite("State", all_of(WTNodes), sep = "") %>% merge(n2Sols, by = "State", all = T) %>% naZero %>% select(contains("Frequency")) %>% t%>% JSD } else { commons <- WTNodes[which(WTNodes %in% n2Nodes)] n2Sols <- n2Sols %>% select(all_of(commons), Frequency) %>% unite("State", all_of(commons), sep = "") WTSols <- WTSols %>% group_by(across(all_of(commons))) %>% summarise(Frequency = sum(Frequency), .groups = "drop") %>% select(all_of(commons), Frequency) %>% unite("State", all_of(commons), sep = "") %>% merge(n2Sols, by = "State", all = T) %>% naZero %>% select(contains("Frequency")) %>% t%>% JSD } WTSols } nets <- c("EMT_RACIPE", "EMT_RACIPE2", "SIL", "silviera2", "EMT_MET_reduced") df <- sapply(nets, function(net) { print(net) WT <- net n1 <- paste0(net, "_del_bottom5") n2 <- paste0(net, "_del_top5") jsd <- c(jsdCalc(WT, n1), jsdCalc(WT, n2), jsdCalc(n1, n2)) }) %>% t %>% data.frame %>% set_names(c("WTbottom", "WTtop", "bottomTop")) df <- sapply(nets, function(net) { print(net) WT <- net n1 <- paste0(net, "_del_bottom5") n2 <- paste0(net, "_del_top5") jsd <- c(jsdCalc(WT, n1), jsdCalc(WT, n2), jsdCalc(n1, n2)) }) jsdCalc <- function(WT, n2) { WTNodes <- read.delim(paste0(WT, ".prs")) %>% filter(str_detect(Parameter, "Prod")) %>% select(Parameter) %>% unlist %>% str_remove("Prod_of_") write.csv(WTNodes, "WTNodes.csv", row.names = F) WTSols <- read_delim(paste0(WT, "_solution.dat"), delim = "\t", col_names = F) %>% set_names(c("ParIndex", "nStates", WTNodes)) write.csv(WTSols, "WTsols1.csv", row.names = F) WTSols[, -(1:3)] <- WTSols %>% select(all_of(WTNodes)) %>% sapply(discretFunc) WTSols <- WTSols %>% group_by(across(all_of(WTNodes))) %>% summarise(Count = n(), .groups = "drop") %>% mutate(Frequency = Count/sum(Count)) write.csv(WTSols, "WTsols2.csv", row.names = F) n2Nodes <- read.delim(paste0(n2, ".prs")) %>% filter(str_detect(Parameter, "Prod")) %>% select(Parameter) %>% unlist %>% str_remove("Prod_of_") write.csv(n2Nodes, "n2Nodes.csv", row.names = F) n2Sols <- read_delim(paste0(n2, "_solution.dat"), delim = "\t", col_names = F) %>% set_names(c("ParIndex", "nStates", n2Nodes)) write.csv(n2Sols, "n2Sols.csv", row.names = F) n2Sols[, -(1:3)] <- n2Sols %>% select(all_of(WTNodes)) %>% sapply(discretFunc) n2Sols <- n2Sols %>% group_by(across(all_of(n2Nodes))) %>% summarise(Count = n(), .groups = "drop") %>% mutate(Frequency = Count/sum(Count)) write.csv(n2Sols, "n2Sols1.csv", row.names = F) if (all(WTNodes %in% n2Nodes)) { n2Sols <- n2Sols %>% select(all_of(WTNodes), Frequency) %>% unite("State", all_of(WTNodes), sep = "") WTSols <- WTSols %>% select(all_of(WTNodes), Frequency) %>% unite("State", all_of(WTNodes), sep = "") %>% merge(n2Sols, by = "State", all = T) %>% naZero %>% select(contains("Frequency")) %>% t%>% JSD } else { commons <- WTNodes[which(WTNodes %in% n2Nodes)] n2Sols <- n2Sols %>% select(all_of(commons), Frequency) %>% unite("State", all_of(commons), sep = "") WTSols <- WTSols %>% group_by(across(all_of(commons))) %>% summarise(Frequency = sum(Frequency), .groups = "drop") %>% select(all_of(commons), Frequency) %>% unite("State", all_of(commons), sep = "") %>% merge(n2Sols, by = "State", all = T) %>% naZero %>% select(contains("Frequency")) %>% t%>% JSD } WTSols } nets <- c("EMT_RACIPE", "EMT_RACIPE2", "SIL", "silviera2", "EMT_MET_reduced") df <- sapply(nets, function(net) { print(net) WT <- net n1 <- paste0(net, "_del_bottom5") n2 <- paste0(net, "_del_top5") jsd <- c(jsdCalc(WT, n1), jsdCalc(WT, n2), jsdCalc(n1, n2)) }) %>% t %>% data.frame %>% set_names(c("WTbottom", "WTtop", "bottomTop")) jsdCalc <- function(WT, n2) { WTNodes <- read.delim(paste0(WT, ".prs")) %>% filter(str_detect(Parameter, "Prod")) %>% select(Parameter) %>% unlist %>% str_remove("Prod_of_") write.csv(WTNodes, "WTNodes.csv", row.names = F) WTSols <- read_delim(paste0(WT, "_solution.dat"), delim = "\t", col_names = F) %>% set_names(c("ParIndex", "nStates", WTNodes)) write.csv(WTSols, "WTsols1.csv", row.names = F) WTSols[, -(1:2)] <- WTSols %>% select(all_of(WTNodes)) %>% sapply(discretFunc) WTSols <- WTSols %>% group_by(across(all_of(WTNodes))) %>% summarise(Count = n(), .groups = "drop") %>% mutate(Frequency = Count/sum(Count)) write.csv(WTSols, "WTsols2.csv", row.names = F) n2Nodes <- read.delim(paste0(n2, ".prs")) %>% filter(str_detect(Parameter, "Prod")) %>% select(Parameter) %>% unlist %>% str_remove("Prod_of_") write.csv(n2Nodes, "n2Nodes.csv", row.names = F) n2Sols <- read_delim(paste0(n2, "_solution.dat"), delim = "\t", col_names = F) %>% set_names(c("ParIndex", "nStates", n2Nodes)) write.csv(n2Sols, "n2Sols.csv", row.names = F) n2Sols[, -(1:2)] <- n2Sols %>% select(all_of(WTNodes)) %>% sapply(discretFunc) n2Sols <- n2Sols %>% group_by(across(all_of(n2Nodes))) %>% summarise(Count = n(), .groups = "drop") %>% mutate(Frequency = Count/sum(Count)) write.csv(n2Sols, "n2Sols1.csv", row.names = F) if (all(WTNodes %in% n2Nodes)) { n2Sols <- n2Sols %>% select(all_of(WTNodes), Frequency) %>% unite("State", all_of(WTNodes), sep = "") WTSols <- WTSols %>% select(all_of(WTNodes), Frequency) %>% unite("State", all_of(WTNodes), sep = "") %>% merge(n2Sols, by = "State", all = T) %>% naZero %>% select(contains("Frequency")) %>% t%>% JSD } else { commons <- WTNodes[which(WTNodes %in% n2Nodes)] n2Sols <- n2Sols %>% select(all_of(commons), Frequency) %>% unite("State", all_of(commons), sep = "") WTSols <- WTSols %>% group_by(across(all_of(commons))) %>% summarise(Frequency = sum(Frequency), .groups = "drop") %>% select(all_of(commons), Frequency) %>% unite("State", all_of(commons), sep = "") %>% merge(n2Sols, by = "State", all = T) %>% naZero %>% select(contains("Frequency")) %>% t%>% JSD } WTSols } nets <- c("EMT_RACIPE", "EMT_RACIPE2", "SIL", "silviera2", "EMT_MET_reduced") df <- sapply(nets, function(net) { print(net) WT <- net n1 <- paste0(net, "_del_bottom5") n2 <- paste0(net, "_del_top5") jsd <- c(jsdCalc(WT, n1), jsdCalc(WT, n2), jsdCalc(n1, n2)) }) %>% t %>% data.frame %>% set_names(c("WTbottom", "WTtop", "bottomTop")) df$Network <- nets df1 <- df %>% gather(key = "Comparision", value = "JSD", -Network) ggplot(df1, aes(x = Network, y = JSD, color = Comparision)) + geom_point(size = 3) + theme(legend.position = "top", axis.text.x = element_text(angle = 60, vjust = 1, hjust = 1)) + ylim(c(0, 1.1)) ggplot(df1, aes(x = Network, y = JSD, color = Comparision)) + geom_point(size = 3) + theme_Publication() + theme(legend.position = "top", axis.text.x = element_text(angle = 60, vjust = 1, hjust = 1)) + ylim(c(0, 1.1)) ggsave("JSDPlot.png", width = 5.5, height = 6) write.csv(df, "JSDDat.csv", row.names = F) setwd("D:/Github/Rpackages/Teams") setwd("D:/Github/Projects/Ongoing/Canalilzation/RandomNetworkAnalysis/EffectivenessGs") devtools::install_github("askhari139/Teams") devtools::install_github("askhari139/Teams") devtools::install_github("askhari139/Teams")