From 86d12cf45a2ee26e46568ea975895edbf4942541 Mon Sep 17 00:00:00 2001 From: Franck SIMON Date: Wed, 4 Sep 2024 17:47:58 +0200 Subject: [PATCH] OD review: replace mo, tmo by miic_obj, tmiic_obj --- R/miic.plot.R | 24 ++++++------- R/tmiic.plot.R | 68 ++++++++++++++++++------------------ R/tmiic.wrapper.R | 54 ++++++++++++++-------------- R/write.cytoscape.R | 10 +++--- man/export.Rd | 4 +-- man/writeCytoscapeNetwork.Rd | 4 +-- 6 files changed, 82 insertions(+), 82 deletions(-) diff --git a/R/miic.plot.R b/R/miic.plot.R index f805c42..a504baa 100644 --- a/R/miic.plot.R +++ b/R/miic.plot.R @@ -17,7 +17,7 @@ #' and their width is based on the conditional mutual information #' minus the complexity cost. #' -#' @param mo [a miic object, required] +#' @param miic_obj [a miic object, required] #' #' The object returned by the \code{\link{miic}} execution. #' @@ -144,18 +144,18 @@ #' #' } #------------------------------------------------------------------------------- -export <- function (mo, method="igraph", pcor_palette=NULL, +export <- function (miic_obj, method="igraph", pcor_palette=NULL, display="compact", show_self_loops=TRUE) { - if ( is.null(mo$summary) ) + if ( is.null(miic_obj$summary) ) stop("The inferred network does not exist") if ( (!is.null(method)) && (method != "igraph") ) stop("Method not supported") - if ( is.null(mo$tmiic) ) - return (getIgraph(mo, pcor_palette=pcor_palette)) + if ( is.null(miic_obj$tmiic) ) + return (getIgraph(miic_obj, pcor_palette=pcor_palette)) else - return (tmiic_getIgraph (mo, pcor_palette=pcor_palette, + return (tmiic_getIgraph (miic_obj, pcor_palette=pcor_palette, display=display, show_self_loops=show_self_loops)) } @@ -173,7 +173,7 @@ export <- function (mo, method="igraph", pcor_palette=NULL, #' (negative is blue, null is gray and positive is red) and their width is #' based on the conditional mutual information minus the complexity cost. #' -#' @param mo [a miic object] +#' @param miic_obj [a miic object] #' The object returned by the \code{\link{miic}} execution. #' @param pcor_palette The color palette used to represent the partial correlations #' (the color of the edges). The palette must be able to handle 201 shades @@ -189,15 +189,15 @@ export <- function (mo, method="igraph", pcor_palette=NULL, #' \code{\link[igraph]{igraph.plotting}} for the detailed description of the #' plotting parameters and \code{\link[igraph]{layout}} for different layouts. #------------------------------------------------------------------------------- -getIgraph <- function(mo, pcor_palette = NULL) { - if (is.null(mo$summary)) { +getIgraph <- function(miic_obj, pcor_palette = NULL) { + if (is.null(miic_obj$summary)) { stop("The inferred network does not exist.") } if (!base::requireNamespace("igraph", quietly = TRUE)) { stop("Package 'igraph' is required.") } - summary = mo$summary[mo$summary$type %in% c('P', 'TP', 'FP'), ] + summary = miic_obj$summary[miic_obj$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)){ @@ -218,8 +218,8 @@ getIgraph <- function(mo, pcor_palette = NULL) { } # Create igraph object from summary - ig_graph = igraph::graph_from_data_frame(summary, - vertices=colnames(mo$adj_matrix)) + ig_graph = igraph::graph_from_data_frame (summary, + vertices=colnames(miic_obj$adj_matrix) ) # Set nodes visuals igraph::V(ig_graph)$color <- "lightblue" diff --git a/R/tmiic.plot.R b/R/tmiic.plot.R index 664166a..0c3dafa 100644 --- a/R/tmiic.plot.R +++ b/R/tmiic.plot.R @@ -22,7 +22,7 @@ # conditional mutual information minus the complexity cost. # # params: -# - tmo: a tmiic object, returned by the miic execution in temporal mode +# - tmiic_obj: a tmiic object, returned by the miic execution in temporal mode # # - display: string. Optional, default value "compact". # Possible values are "raw", "lagged", "compact", "combine", "unique", "drop": @@ -67,15 +67,15 @@ # # returns: an igraph graph object. #------------------------------------------------------------------------------- -tmiic_getIgraph <- function (tmo, display="compact", +tmiic_getIgraph <- function (tmiic_obj, display="compact", show_self_loops=TRUE, pcor_palette=NULL) { if (display == "lagged") - tmo$summary = tmo$tmiic$stationarity + tmiic_obj$summary = tmiic_obj$tmiic$stationarity else if (display != "raw") - tmo <- tmiic_flatten_network (tmo, flatten_mode=display, + tmiic_obj <- tmiic_flatten_network (tmiic_obj, flatten_mode=display, keep_edges_on_same_node=show_self_loops) - graph <- getIgraph (tmo, pcor_palette=pcor_palette) + graph <- getIgraph (tmiic_obj, pcor_palette=pcor_palette) if (display %in% c("raw", "lagged") ) { @@ -86,8 +86,8 @@ tmiic_getIgraph <- function (tmo, display="compact", else { igraph::E(graph)$curved = FALSE - if ( "lag" %in% colnames(tmo$summary) ) - igraph::E(graph)$label <- tmo$summary$lag + if ( "lag" %in% colnames(tmiic_obj$summary) ) + igraph::E(graph)$label <- tmiic_obj$summary$lag } return(graph) } @@ -106,9 +106,9 @@ tmiic_getIgraph <- function (tmo, display="compact", # # @return [a tmiic object] The modified tmiic object #----------------------------------------------------------------------------- -tmiic_prepare_edges_for_plotting <- function (tmo) +tmiic_prepare_edges_for_plotting <- function (tmiic_obj) { - df_edges <- tmo$summary[tmo$summary$type %in% c('P', 'TP', 'FP'), ] + df_edges <- tmiic_obj$summary[tmiic_obj$summary$type %in% c('P', 'TP', 'FP'), ] if (nrow(df_edges) <= 0) df_edges$xy = character(0) else @@ -145,8 +145,8 @@ tmiic_prepare_edges_for_plotting <- function (tmo) } } } - tmo$summary <- df_edges - return (tmo) + tmiic_obj$summary <- df_edges + return (tmiic_obj) } #------------------------------------------------------------------------------- @@ -163,9 +163,9 @@ tmiic_prepare_edges_for_plotting <- function (tmo) # # @return df_mult [a dataframe] The dataframe containing the multiple edges #------------------------------------------------------------------------------- -tmiic_get_multiple_edges_for_plotting <- function (tmo) +tmiic_get_multiple_edges_for_plotting <- function (tmiic_obj) { - df_mult <- tmo$summary + df_mult <- tmiic_obj$summary if (nrow(df_mult) <= 0) df_mult$count <- numeric(0) else @@ -423,17 +423,17 @@ tmiic_compute_row_layout_greedy_recurs <- function (node_left, node_right, # The layout is completed with nodes without edges to produce the final # layer 0 layout. # -# param: tmo, the object returned by the miic execution in temporal mode +# param: tmiic_obj, the object returned by the miic execution in temporal mode # # returns: a list, the position along an axis for each node #------------------------------------------------------------------------------- -tmiic_compute_row_layout_greedy <- function (tmo) +tmiic_compute_row_layout_greedy <- function (tmiic_obj) { - list_nodes_not_lagged <- tmo$state_order$var_names + list_nodes_not_lagged <- tmiic_obj$state_order$var_names # # Filter out self edges, count and summarize edges regardless their lags # - tmiic_flat <- tmiic_flatten_network (tmo) + tmiic_flat <- tmiic_flatten_network (tmiic_obj) df_edges <- tmiic_flat$summary df_edges <- df_edges[(df_edges$x != df_edges$y),] if (nrow (df_edges) == 0) @@ -490,15 +490,15 @@ tmiic_compute_row_layout_greedy <- function (tmo) # This function computes the layout so that the less layers # has a node, the more to the exteriors it will be placed. # -# param: tmo, a tmiic object returned by the execution of miic +# param: tmiic_obj, a tmiic object returned by the execution of miic # in temporal mode ("raw" graph_type) # # returns: a list, the position along an axis for each node #------------------------------------------------------------------------------- -tmiic_compute_row_layout_layers <- function (tmo) +tmiic_compute_row_layout_layers <- function (tmiic_obj) { - n_nodes_not_lagged <- nrow(tmo$state_order) - list_n_layers_back <- tmo$state_order$n_layers - 1 + n_nodes_not_lagged <- nrow(tmiic_obj$state_order) + list_n_layers_back <- tmiic_obj$state_order$n_layers - 1 n_layers_back_max <- max (list_n_layers_back) # # Precompute the rows on the grid, putting nodes with the less lags @@ -547,19 +547,19 @@ tmiic_compute_row_layout_layers <- function (tmo) # This function computes the layout using Sugiyama algorithm to # minimize crossing edges # -# param: tmo, a tmiic object returned by the execution of miic +# param: tmiic_obj, a tmiic object returned by the execution of miic # in temporal mode ("raw" graph_type) # # returns: a list, the position along an axis for each node #------------------------------------------------------------------------------- -tmiic_compute_row_layout_sugiyama <- function (tmo) +tmiic_compute_row_layout_sugiyama <- function (tmiic_obj) { - list_nodes_not_lagged <- tmo$state_order$var_names + list_nodes_not_lagged <- tmiic_obj$state_order$var_names n_nodes_not_lagged <- length(list_nodes_not_lagged) # # Filter out self edges, count and summarize edges regardless their lags # - tmiic_flat <- tmiic_flatten_network(tmo) + tmiic_flat <- tmiic_flatten_network(tmiic_obj) df_edges <- tmiic_flat$summary df_edges <- df_edges[(df_edges$x != df_edges$y),] if (nrow(df_edges) == 0) @@ -596,7 +596,7 @@ tmiic_compute_row_layout_sugiyama <- function (tmo) # graphs # # params: -# - tmo, a tmiic object returned by the miic's execution in temporal mode. +# - tmiic_obj, a tmiic object returned by the miic's execution in temporal mode. # # - display: string. optional, default value "raw". # Possible values are "raw" and "lagged". @@ -625,7 +625,7 @@ tmiic_compute_row_layout_sugiyama <- function (tmo) # # returns: a matrix, the layout to use for drawing #------------------------------------------------------------------------------- -tmiic_compute_grid_layout <- function (tmo, display="raw", +tmiic_compute_grid_layout <- function (tmiic_obj, display="raw", positioning="greedy", orientation="L") { if (! display %in% c("raw", "lagged") ) @@ -635,7 +635,7 @@ tmiic_compute_grid_layout <- function (tmo, display="raw", if (! orientation %in% c("L", "P") ) stop ("Error: Invalid orientation parameter") - nodes_not_lagged <- tmo$state_order$var_names + nodes_not_lagged <- tmiic_obj$state_order$var_names n_nodes_not_lagged <- length (nodes_not_lagged) # # Precompute the layer 0 layout @@ -652,18 +652,18 @@ tmiic_compute_grid_layout <- function (tmo, display="raw", list_pos_of_nodes <- unlist (list_pos_of_nodes) } if (positioning == "layers") - list_pos_of_nodes <- tmiic_compute_row_layout_layers (tmo) + list_pos_of_nodes <- tmiic_compute_row_layout_layers (tmiic_obj) if (positioning == "greedy") - list_pos_of_nodes <- tmiic_compute_row_layout_greedy (tmo) + list_pos_of_nodes <- tmiic_compute_row_layout_greedy (tmiic_obj) if (positioning == "sugiyama") - list_pos_of_nodes <- tmiic_compute_row_layout_sugiyama (tmo) + list_pos_of_nodes <- tmiic_compute_row_layout_sugiyama (tmiic_obj) if ( is.null (list_pos_of_nodes) ) stop ("Error: Layout can not be infered") # # As contextual nodes are placed in an extra column/row when display is "raw", # here we update the nodes positions to maintain a "nice" display # - is_contextual <- tmo$state_order$is_contextual + is_contextual <- tmiic_obj$state_order$is_contextual if ( (display == "raw") & (sum(is_contextual) > 0) ) { list_pos_upd <- list_pos_of_nodes @@ -708,9 +708,9 @@ tmiic_compute_grid_layout <- function (tmo, display="raw", # # Place contextual and lag0 nodes # - list_n_layers_back <- tmo$state_order$n_layers - 1 + list_n_layers_back <- tmiic_obj$state_order$n_layers - 1 n_layers_back_max <- max (list_n_layers_back) - list_delta_t <- tmo$state_order$delta_t + list_delta_t <- tmiic_obj$state_order$delta_t max_lags <- max (list_n_layers_back * list_delta_t) df_layout <- data.frame ( col=integer(), row=integer() ) diff --git a/R/tmiic.wrapper.R b/R/tmiic.wrapper.R index ca23bc1..5ca0b67 100644 --- a/R/tmiic.wrapper.R +++ b/R/tmiic.wrapper.R @@ -213,7 +213,7 @@ tmiic_lag_input_data <- function (list_ts, state_order, keep_max_data=FALSE) # Utility function to precompute lags, layers and shifts of nodes in the # lagged network # -# params: tmo [a tmiic object] The object returned by miic's +# params: tmiic_obj [a tmiic object] The object returned by miic's # execution in temporal mode. # # returns: a dataframe with lagged nodes as row name and 3 columns: @@ -221,13 +221,13 @@ tmiic_lag_input_data <- function (list_ts, state_order, keep_max_data=FALSE) # - corresp_nodes: the corresponding non lagged node # - shifts: the shift to apply to find the next lagged node #----------------------------------------------------------------------------- -tmiic_precompute_lags_layers_and_shifts <- function (tmo) +tmiic_precompute_lags_layers_and_shifts <- function (tmiic_obj) { - list_nodes_not_lagged = tmo$state_order$var_names - is_contextual = tmo$state_order$is_contextual + list_nodes_not_lagged = tmiic_obj$state_order$var_names + is_contextual = tmiic_obj$state_order$is_contextual n_nodes_not_lagged = length (list_nodes_not_lagged) - list_n_layers_back <- tmo$state_order$n_layers - 1 - list_delta_t <- tmo$state_order$delta_t + list_n_layers_back <- tmiic_obj$state_order$n_layers - 1 + list_delta_t <- tmiic_obj$state_order$delta_t # # Identify lag and layer of each node # @@ -430,7 +430,7 @@ tmiic_combine_probas <- function (df, comb_orient) # is reduced to non lagged nodes and filled with NA during the process # # params: -# - tmo: a tmiic object, returned by tmiic +# - tmiic_obj: a tmiic object, returned by tmiic # # - flatten_mode: string, optional, default value "compact". # Possible values are "compact", "combine", "unique", "drop": @@ -470,30 +470,30 @@ tmiic_combine_probas <- function (df, comb_orient) # as input where the summary dataframe has been flattened and the adjacency # matrix reduced to the non lagged nodes #----------------------------------------------------------------------------- -tmiic_flatten_network <- function (tmo, flatten_mode="compact", +tmiic_flatten_network <- function (tmiic_obj, flatten_mode="compact", keep_edges_on_same_node=TRUE) { # Reduce size of adj_matrix to non lagged nodes # (we don't care about content as it is not used for plotting) # - list_nodes <- tmo$state_order$var_names - tmo$adj_matrix <- matrix(NA, nrow=0, ncol=length (list_nodes)) - colnames(tmo$adj_matrix) <- list_nodes + list_nodes <- tmiic_obj$state_order$var_names + tmiic_obj$adj_matrix <- matrix(NA, nrow=0, ncol=length (list_nodes)) + colnames(tmiic_obj$adj_matrix) <- list_nodes # # Keep only edges found by miic # - df_edges <- tmo$summary[tmo$summary$type %in% c('P', 'TP', 'FP'), ] + df_edges <- tmiic_obj$summary[tmiic_obj$summary$type %in% c('P', 'TP', 'FP'), ] if (nrow(df_edges) <= 0) { if (flatten_mode != "drop") df_edges$lag = numeric(0) - tmo$summary <- df_edges - return (tmo) + tmiic_obj$summary <- df_edges + return (tmiic_obj) } # # Precompute lag and layer of each node # - df_precomputed <- tmiic_precompute_lags_layers_and_shifts (tmo) + df_precomputed <- tmiic_precompute_lags_layers_and_shifts (tmiic_obj) # # First step, perform flatten_mode="compact": # from summary, remove lag info from nodes names and put it into a lag column @@ -539,8 +539,8 @@ tmiic_flatten_network <- function (tmo, flatten_mode="compact", { if (flatten_mode == "drop") df_edges$lag <- NULL - tmo$summary <- df_edges - return (tmo) + tmiic_obj$summary <- df_edges + return (tmiic_obj) } # # "compact" mode is done @@ -628,10 +628,10 @@ tmiic_flatten_network <- function (tmo, flatten_mode="compact", { # For contextual variable, we clean the lag info # - is_contextual <- tmo$state_order$is_contextual + is_contextual <- tmiic_obj$state_order$is_contextual if (!is.null(is_contextual)) { - list_nodes_not_lagged = tmo$state_order$var_names + list_nodes_not_lagged = tmiic_obj$state_order$var_names for ( edge_idx in 1:nrow(df_edges) ) { one_edge <- df_edges[edge_idx,] @@ -645,8 +645,8 @@ tmiic_flatten_network <- function (tmo, flatten_mode="compact", # # returns the tmiic structure where network summary has been flattened # - tmo$summary <- df_edges - return (tmo) + tmiic_obj$summary <- df_edges + return (tmiic_obj) } #----------------------------------------------------------------------------- @@ -660,23 +660,23 @@ tmiic_flatten_network <- function (tmo, flatten_mode="compact", # i.e: assuming that we used nlayers=4 and delta_t=1, the edge X_lag0-X_lag1 # will be copied as X_lag1-X_lag2 and X_lag2-X_lag3. # -# param: tmo, the object returned by tmiic +# param: tmiic_obj, the object returned by tmiic # # returns: a dataframe with edges completed by stationarity #----------------------------------------------------------------------------- -tmiic_repeat_edges_over_history <- function (tmo) +tmiic_repeat_edges_over_history <- function (tmiic_obj) { # Consider only edges found by miic type = "P", "TP", "FP" # - df_edges <- tmo$summary[tmo$summary$type %in% c('P', 'TP', 'FP'), ] + df_edges <- tmiic_obj$summary[tmiic_obj$summary$type %in% c('P', 'TP', 'FP'), ] if (nrow(df_edges) <= 0) return (df_edges) # # Precompute lag, layer and shift of each node # - df_precomp <- tmiic_precompute_lags_layers_and_shifts (tmo) - list_n_layers_back <- tmo$state_order$n_layers - 1 - list_nodes_not_lagged <- tmo$state_order$var_names + df_precomp <- tmiic_precompute_lags_layers_and_shifts (tmiic_obj) + list_n_layers_back <- tmiic_obj$state_order$n_layers - 1 + list_nodes_not_lagged <- tmiic_obj$state_order$var_names # # Duplicate the edges over all layers of history # diff --git a/R/write.cytoscape.R b/R/write.cytoscape.R index ddf8b96..876424a 100755 --- a/R/write.cytoscape.R +++ b/R/write.cytoscape.R @@ -11,7 +11,7 @@ fromStringToNumberArrowType <- function(val) { #' GraphML converting function for miic graph #' #' @description Convert miic graph to [GraphML format](http://graphml.graphdrawing.org/). -#' @param mo A miic object. The object returned by the \code{\link{miic}} execution. +#' @param miic_obj A miic object. The object returned by the \code{\link{miic}} execution. #' @param file A string. Path to the output file containing file name without #' extension (.graphml will be appended). #' @param layout An optional data frame of 2 (or 3) columns containing the @@ -23,18 +23,18 @@ fromStringToNumberArrowType <- function(val) { #' @useDynLib miic #' @md -writeCytoscapeNetwork <- function(mo, file, layout = NULL) { +writeCytoscapeNetwork <- function(miic_obj, file, layout = NULL) { ##################################### NETWORK IN GRAPHML if (missing(file)) { stop("The file path is necessary") } - if (is.null(mo$summary)) { + if (is.null(miic_obj$summary)) { stop("The result of the miic execution is required") } - summary <- mo$summary - adj_matrix <- mo$adj_matrix + summary <- miic_obj$summary + adj_matrix <- miic_obj$adj_matrix if (is.null(layout)) { line <- "\n" diff --git a/man/export.Rd b/man/export.Rd index f1f887d..1a7f6cb 100644 --- a/man/export.Rd +++ b/man/export.Rd @@ -5,7 +5,7 @@ \title{Export miic result for plotting (with igraph)} \usage{ export( - mo, + miic_obj, method = "igraph", pcor_palette = NULL, display = "compact", @@ -13,7 +13,7 @@ export( ) } \arguments{ -\item{mo}{[a miic object, required] +\item{miic_obj}{[a miic object, required] The object returned by the \code{\link{miic}} execution.} diff --git a/man/writeCytoscapeNetwork.Rd b/man/writeCytoscapeNetwork.Rd index e068c33..fbcc519 100644 --- a/man/writeCytoscapeNetwork.Rd +++ b/man/writeCytoscapeNetwork.Rd @@ -4,10 +4,10 @@ \alias{writeCytoscapeNetwork} \title{GraphML converting function for miic graph} \usage{ -writeCytoscapeNetwork(mo, file, layout = NULL) +writeCytoscapeNetwork(miic_obj, file, layout = NULL) } \arguments{ -\item{mo}{A miic object. The object returned by the \code{\link{miic}} execution.} +\item{miic_obj}{A miic object. The object returned by the \code{\link{miic}} execution.} \item{file}{A string. Path to the output file containing file name without extension (.graphml will be appended).}