combine_layers: Combine layers

View source: R/combine_layers.R

combine_layersR Documentation

Combine layers

Description

Return a merged graph from two graph layers.

Usage

combine_layers(graph1, graph2 = NULL, interaction.df = NULL)

Arguments

graph1

an igraph object or list of igraph (list.igraph).

graph2

an igraph object or list of igraph (list.igraph) with the same length as graph1.

interaction.df

(optional) a 2 colomns data.frame (from, to) describing the edges between vertices from both graphs.

Details

If graph2 is a single graph, it will be merged to each element of graph1 (igraph or list.igraph).

If graph2 is a list of graph (list.igraph), each element of graph1 and each element of graph2 are merged in pairs.

Optionally, interaction.df should be provide if any vertex are shared between graphs. It can also be used to extend the first graph.

In both scenarios, vertex attributes are kept. If a vertex attribute is missing from graph1 or graph2, NULL value is added. Otherwise, if there is an overlap between attribute values for the same vertex, attribute from graph2 is dropped.

Value

a merged graph with both vertex attributes from graph1 and graph2.

Examples

# with single graphs
graph1 <- igraph::graph_from_data_frame(list(from = c('A', 'B'),
                                             to = c('B', 'C')),
                                        directed = FALSE)
graph2 <- igraph::graph_from_data_frame(list(from = c(1), 
                                             to = c(2)),
                                        directed = FALSE)
res <- combine_layers(graph1 = graph1,
                      graph2 = graph2)

# with list of graphs
graph1.list <- list(graph1, graph1)
graph2.list <- list(graph2, graph2)
class(graph1.list) <- class(graph2.list) <- 'list.igraph'

res <- combine_layers(graph1 = graph1.list, 
                      graph2 = graph2)
res <- combine_layers(graph1 = graph1.list, 
                      graph2 = graph2.list)

# with interaction dataframe
interaction.df1 <- as.data.frame(list(from = c('C', 'B'), to = c(1, 2)))
res <- combine_layers(graph1 = graph1.list, 
                      graph2 = graph2, 
                      interaction.df = interaction.df1)



abodein/netOmics documentation built on Oct. 20, 2024, 9:25 a.m.