From 53bea533decdf592b61b0c31de014b45931408f1 Mon Sep 17 00:00:00 2001 From: Franck SIMON Date: Tue, 27 Aug 2024 18:40:17 +0200 Subject: [PATCH] Rename all.edges.xx and orientations.prob data frames --- R/miic.R | 18 +++++++++--------- R/miic.plot.R | 6 +++--- R/miic.reconstruct.R | 10 +++++----- R/tmiic.plot.R | 18 +++++++++--------- R/tmiic.wrapper.R | 10 +++++----- R/write.cytoscape.R | 4 ++-- man/miic.Rd | 6 +++--- src/reconstruct.cpp | 2 +- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/R/miic.R b/R/miic.R index e992210..31ab034 100755 --- a/R/miic.R +++ b/R/miic.R @@ -369,7 +369,7 @@ #' #' @return A \emph{miic-like} object that contains: #' \itemize{ -#' \item{\emph{all.edges.summary:} a data frame with information about the +#' \item{\emph{summary:} a data frame with information about the #' relationship between relevant pair of variables. #' #' As returning the information on all possible pairs of variables could lead @@ -400,7 +400,7 @@ #' retained edges. If the true graph is supplied in the \emph{true_edges} #' parameter, 'P' becomes 'TP' (True Positive) or 'FP' (False Positive), #' while 'N' becomes 'TN' (True Negative) or 'FN' (False Negative). -#' Note that, as the \emph{all.edges.summary} does not contain all the +#' Note that, as the \emph{summary} does not contain all the #' removed edges, edges not present have to be considered as 'N' #' and, if the true graph is supplied, as 'TN'.} #' \item{ \emph{ai:} the contributing nodes found by the method which @@ -508,7 +508,7 @@ #' the C++ core function. This data frame is used internally by MIIC to #' produce the summary and contains all pairs of variables (\emph{x, y}). } #' -#' \item{\emph{orientations.prob:} this data frame lists the orientation +#' \item{\emph{triples:} this data frame lists the orientation #' probabilities of the two edges of all unshielded triples of the #' reconstructed network with the structure: node1 -- mid-node -- node2: #' \itemize{ @@ -859,7 +859,7 @@ miic <- function(input_data, # Post-traitment # post_start = Sys.time() - res$all.edges.summary <- summarizeResults ( + res$summary <- summarizeResults ( observations = input_data, results = res, true_edges = true_edges, @@ -871,9 +871,9 @@ miic <- function(input_data, if (!is.null (true_edges)) { - tp = sum (res$all.edges.summary$type == "TP") - fp = sum (res$all.edges.summary$type == "FP") - fn = sum (res$all.edges.summary$type == "FN") + tp = sum (res$summary$type == "TP") + fp = sum (res$summary$type == "FP") + fn = sum (res$summary$type == "FN") precision = tp / (tp + fp) recall = tp / (tp + fn) fscore = (2 * (precision * recall) ) / (precision + recall) @@ -907,13 +907,13 @@ miic <- function(input_data, # The output of the reconstruction is the "raw" temporal graph, without # edges identical by stationarity. To have the "real" temporal graph, # we duplicate the edges using the stationary assumption and this "real" - # graph is stored the "all.edges.stationarity" data frame. + # graph is stored the "stationarity" data frame. # edges_dup_stat = tmiic_repeat_edges_over_history (res) res$tmiic <- list (lagged_state_order = state_order, lagged_black_box = black_box, lagged_true_edges = true_edges, - all.edges.stationarity = edges_dup_stat) + stationarity = edges_dup_stat) } miic_end = Sys.time() diff --git a/R/miic.plot.R b/R/miic.plot.R index 0ef7c9b..dd4f76d 100644 --- a/R/miic.plot.R +++ b/R/miic.plot.R @@ -139,7 +139,7 @@ export <- function (miic_res, method="igraph", pcor_palette=NULL, display="compact", show_self_loops=TRUE) { - if ( is.null(miic_res$all.edges.summary) ) + if ( is.null(miic_res$summary) ) stop("The inferred network does not exist") if ( (!is.null(method)) && (method != "igraph") ) stop("Method not supported") @@ -180,14 +180,14 @@ export <- function (miic_res, method="igraph", pcor_palette=NULL, #' plotting parameters and \code{\link[igraph]{layout}} for different layouts. #------------------------------------------------------------------------------- getIgraph <- function(miic_res, pcor_palette = NULL) { - if (is.null(miic_res$all.edges.summary)) { + if (is.null(miic_res$summary)) { stop("The inferred network does not exist.") } if (!base::requireNamespace("igraph", quietly = TRUE)) { stop("Package 'igraph' is required.") } - summary = miic_res$all.edges.summary[miic_res$all.edges.summary$type %in% c('P', 'TP', 'FP'), ] + summary = miic_res$summary[miic_res$summary$type %in% c('P', 'TP', 'FP'), ] if (nrow(summary) > 0) { # Re-order summary so that all edges go from "x" to "y" for(row in 1:nrow(summary)){ diff --git a/R/miic.reconstruct.R b/R/miic.reconstruct.R index 8750dcf..2f6e093 100755 --- a/R/miic.reconstruct.R +++ b/R/miic.reconstruct.R @@ -179,13 +179,13 @@ miic.reconstruct <- function(input_data = NULL, ) # create the data frame of the structures after orientation - orientations_prob <- res$orientations.prob + orientations_prob <- res$triples - if (length(res$orientations.prob) > 0) { + if (length(res$triples) > 0) { a <- length(orientations_prob[[1]]) b <- length(unlist(orientations_prob)) - tmp <- unlist(res$orientations.prob)[1:a] - res1 <- unlist(res$orientations.prob)[(a + 1):b] + tmp <- unlist(res$triples)[1:a] + res1 <- unlist(res$triples)[(a + 1):b] orientations_prob <- data.frame(matrix( res1, nrow = length(orientations_prob) - 1, @@ -200,7 +200,7 @@ miic.reconstruct <- function(input_data = NULL, orientations_prob[, c(8:9)] <- sapply(orientations_prob[, c(8:9)], as.numeric) } # update the returned matrix - res$orientations.prob <- orientations_prob + res$triples <- orientations_prob res$interrupted <- FALSE diff --git a/R/tmiic.plot.R b/R/tmiic.plot.R index dfdfbc3..be90488 100644 --- a/R/tmiic.plot.R +++ b/R/tmiic.plot.R @@ -71,7 +71,7 @@ tmiic_getIgraph <- function (tmiic_res, display="compact", show_self_loops=TRUE, pcor_palette=NULL) { if (display == "lagged") - tmiic_res$all.edges.summary = tmiic_res$tmiic$all.edges.stationarity + tmiic_res$summary = tmiic_res$tmiic$stationarity else if (display != "raw") tmiic_res <- tmiic_flatten_network (tmiic_res, flatten_mode=display, keep_edges_on_same_node=show_self_loops) @@ -86,8 +86,8 @@ tmiic_getIgraph <- function (tmiic_res, display="compact", else { igraph::E(graph)$curved = FALSE - if ( "lag" %in% colnames(tmiic_res$all.edges.summary) ) - igraph::E(graph)$label <- tmiic_res$all.edges.summary$lag + if ( "lag" %in% colnames(tmiic_res$summary) ) + igraph::E(graph)$label <- tmiic_res$summary$lag } return(graph) } @@ -108,7 +108,7 @@ tmiic_getIgraph <- function (tmiic_res, display="compact", #----------------------------------------------------------------------------- tmiic_prepare_edges_for_plotting <- function (tmiic_res) { - df_edges <- tmiic_res$all.edges.summary[tmiic_res$all.edges.summary$type %in% c('P', 'TP', 'FP'), ] + df_edges <- tmiic_res$summary[tmiic_res$summary$type %in% c('P', 'TP', 'FP'), ] if (nrow(df_edges) <= 0) df_edges$xy = character(0) else @@ -145,7 +145,7 @@ tmiic_prepare_edges_for_plotting <- function (tmiic_res) } } } - tmiic_res$all.edges.summary <- df_edges + tmiic_res$summary <- df_edges return (tmiic_res) } @@ -165,7 +165,7 @@ tmiic_prepare_edges_for_plotting <- function (tmiic_res) #------------------------------------------------------------------------------- tmiic_get_multiple_edges_for_plotting <- function (tmiic_res) { - df_mult <- tmiic_res$all.edges.summary + df_mult <- tmiic_res$summary if (nrow(df_mult) <= 0) df_mult$count <- numeric(0) else @@ -434,7 +434,7 @@ tmiic_compute_row_layout_greedy <- function (tmiic_res) # Filter out self edges, count and summarize edges regardless their lags # tmiic_flat <- tmiic_flatten_network (tmiic_res) - df_edges <- tmiic_flat$all.edges.summary + df_edges <- tmiic_flat$summary df_edges <- df_edges[(df_edges$x != df_edges$y),] if (nrow (df_edges) == 0) df_edges$count <- integer() @@ -560,7 +560,7 @@ tmiic_compute_row_layout_sugiyama <- function (tmiic_res) # Filter out self edges, count and summarize edges regardless their lags # tmiic_flat <- tmiic_flatten_network(tmiic_res) - df_edges <- tmiic_flat$all.edges.summary + df_edges <- tmiic_flat$summary df_edges <- df_edges[(df_edges$x != df_edges$y),] if (nrow(df_edges) == 0) df_edges$count <- integer() @@ -953,7 +953,7 @@ plot.tmiic = function(x, method='igraph', pcor_palette=NULL, # If we have a least on case with multiple edges between the same nodes, # draw iteratively # - df_edges <- x$all.edges.summary + df_edges <- x$summary edges_colors_iter <- igraph::E(graph)$color edges_labels_iter <- igraph::E(graph)$label # diff --git a/R/tmiic.wrapper.R b/R/tmiic.wrapper.R index 56eb670..29949bc 100644 --- a/R/tmiic.wrapper.R +++ b/R/tmiic.wrapper.R @@ -482,12 +482,12 @@ tmiic_flatten_network <- function (tmiic_res, flatten_mode="compact", # # Keep only edges found by miic # - df_edges <- tmiic_res$all.edges.summary[tmiic_res$all.edges.summary$type %in% c('P', 'TP', 'FP'), ] + df_edges <- tmiic_res$summary[tmiic_res$summary$type %in% c('P', 'TP', 'FP'), ] if (nrow(df_edges) <= 0) { if (flatten_mode != "drop") df_edges$lag = numeric(0) - tmiic_res$all.edges.summary <- df_edges + tmiic_res$summary <- df_edges return (tmiic_res) } # @@ -539,7 +539,7 @@ tmiic_flatten_network <- function (tmiic_res, flatten_mode="compact", { if (flatten_mode == "drop") df_edges$lag <- NULL - tmiic_res$all.edges.summary <- df_edges + tmiic_res$summary <- df_edges return (tmiic_res) } # @@ -645,7 +645,7 @@ tmiic_flatten_network <- function (tmiic_res, flatten_mode="compact", # # returns the tmiic structure where network summary has been flattened # - tmiic_res$all.edges.summary <- df_edges + tmiic_res$summary <- df_edges return (tmiic_res) } @@ -668,7 +668,7 @@ tmiic_repeat_edges_over_history <- function (tmiic_res) { # Consider only edges found by miic type = "P", "TP", "FP" # - df_edges <- tmiic_res$all.edges.summary[tmiic_res$all.edges.summary$type %in% c('P', 'TP', 'FP'), ] + df_edges <- tmiic_res$summary[tmiic_res$summary$type %in% c('P', 'TP', 'FP'), ] if (nrow(df_edges) <= 0) return (df_edges) # diff --git a/R/write.cytoscape.R b/R/write.cytoscape.R index 2bddc70..3fe0e68 100755 --- a/R/write.cytoscape.R +++ b/R/write.cytoscape.R @@ -28,11 +28,11 @@ writeCytoscapeNetwork <- function(g, file, layout = NULL) { stop("The file path is necessary") } - if (is.null(g$all.edges.summary)) { + if (is.null(g$summary)) { stop("The result of the miic execution is required") } - summary <- g$all.edges.summary + summary <- g$summary adj_matrix <- g$adj_matrix if (is.null(layout)) { diff --git a/man/miic.Rd b/man/miic.Rd index 5fd4abe..3dbccf3 100644 --- a/man/miic.Rd +++ b/man/miic.Rd @@ -361,7 +361,7 @@ If TRUE, debugging output is printed.} \value{ A \emph{miic-like} object that contains: \itemize{ - \item{\emph{all.edges.summary:} a data frame with information about the + \item{\emph{summary:} a data frame with information about the relationship between relevant pair of variables. As returning the information on all possible pairs of variables could lead @@ -392,7 +392,7 @@ A \emph{miic-like} object that contains: retained edges. If the true graph is supplied in the \emph{true_edges} parameter, 'P' becomes 'TP' (True Positive) or 'FP' (False Positive), while 'N' becomes 'TN' (True Negative) or 'FN' (False Negative). - Note that, as the \emph{all.edges.summary} does not contain all the + Note that, as the \emph{summary} does not contain all the removed edges, edges not present have to be considered as 'N' and, if the true graph is supplied, as 'TN'.} \item{ \emph{ai:} the contributing nodes found by the method which @@ -500,7 +500,7 @@ A \emph{miic-like} object that contains: the C++ core function. This data frame is used internally by MIIC to produce the summary and contains all pairs of variables (\emph{x, y}). } - \item{\emph{orientations.prob:} this data frame lists the orientation + \item{\emph{triples:} this data frame lists the orientation probabilities of the two edges of all unshielded triples of the reconstructed network with the structure: node1 -- mid-node -- node2: \itemize{ diff --git a/src/reconstruct.cpp b/src/reconstruct.cpp index fd1f9a7..b013b04 100644 --- a/src/reconstruct.cpp +++ b/src/reconstruct.cpp @@ -139,7 +139,7 @@ List reconstruct(List input_data, List arg_list) { _["proba_adj_matrix"] = getProbaAdjMatrix(environment.edges), _["edges"] = getEdgesInfoTable(environment.edges, environment.nodes), - _["orientations.prob"] = orientations, + _["triples"] = orientations, _["time"] = vector{time.init, time.iter, time.cut, time.ori, time.getTotal()}, _["interrupted"] = false);