Title: | Create, Modify and Visualize Multi-Layered Networks |
---|---|
Description: | Allows the user to create graphs with multiple layers. The user can also modify the layers, the nodes, and the edges. The graph can also be visualized. Zaynab Hammoud and Frank Kramer (2018) <doi:10.3390/genes9110519>. More about multilayered graphs and their usage can be found in our review paper: Zaynab Hammoud and Frank Kramer (2020) <doi:10.1186/s41044-020-00046-0>. |
Authors: | Zaynab Hammoud [aut, cre] |
Maintainer: | Zaynab Hammoud <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.1.38 |
Built: | 2025-02-25 04:15:39 UTC |
Source: | https://github.com/frankkramer-lab/mully |
R package to create, modify and visualize graphs with multiple layers.
Network theory has been used for many years in the modeling and analysis of complex systems, as epidemiology, biology and biomedicine . As the data evolves and becomes more heterogeneous and complex, monoplex networks become an oversimplification of the corresponding systems. This imposes a need to go beyond traditional networks into a richer framework capable of hosting objects and relations of different scales, called Multilayered Network **Mully**, **mul**ti**l**a**y**er networks, is an R package that provides a multilayer network framework. Using this package, the user can create, modify and visualize graphs with multiple layers. This package is an extension to the [igraph package](https://github.com/igraph/rigraph) that provides a monolayer graph framework. The package is implemented as a part of [the Multipath Project](https://www.sys-med.de/en/junior-research-groups/multipath/) directed by [Dr. Frank Kramer](https://www.uni-augsburg.de/de/fakultaet/fai/informatik/prof/misit/mitarbeiter/) .
mully, addLayer, addNode, addEdge, removeLayer, removeNode, removeEdge, getNodeAttributes, getEdgeAttributes
More information and references can be found in the mully paper:
https://www.mdpi.com/2073-4425/9/11/519
Add an edge
addEdge(g, nodeStart, nodeDest, attributes)
addEdge(g, nodeStart, nodeDest, attributes)
g |
The input graph |
nodeStart |
The first endpoint of the edge |
nodeDest |
The second endpoint of the edge |
attributes |
The attributes to assign to the edge |
The mully graph, with the added edge
g=mully::demo() addEdge(g,"dr3","g2",attributes=list(name="newEdge"))
g=mully::demo() addEdge(g,"dr3","g2",attributes=list(name="newEdge"))
Add a layer or a set of layers to a graph
addLayer(g, nameLayer)
addLayer(g, nameLayer)
g |
The input graph. |
nameLayer |
The name or the list of the names of the layers to be added. The layer names must be unique. |
The graph, with the layers added.
g = mully("MyFirstMully",direct = FALSE) g = addLayer(g, c("Gene", "Drug", "Disease"))
g = mully("MyFirstMully",direct = FALSE) g = addLayer(g, c("Gene", "Drug", "Disease"))
Add a node with assigned layer and attributes to a graph
addNode(g, nodeName, layerName, attributes = NA)
addNode(g, nodeName, layerName, attributes = NA)
g |
The input graph. |
nodeName |
The name of the node to add. |
layerName |
The name of the layer to be assigned to the node. |
attributes |
The attributes of the node to add. This argument must be a named list. |
The mully graph, with the new node.
g=mully::demo() attributes=list("specie"="Homo Sapiens") addNode(g = g,nodeName = "g3",layerName = "Gene",attributes = attributes)
g=mully::demo() attributes=list("specie"="Homo Sapiens") addNode(g = g,nodeName = "g3",layerName = "Gene",attributes = attributes)
A demo function to test the package
demo(name = "MyFirstMully")
demo(name = "MyFirstMully")
name |
Optional name for the graph to be created. By default set to "MyFirstMully" |
A mully test graph with few layers, nodes and edges
Export mully into CSV files
exportCSV(g, target)
exportCSV(g, target)
g |
The input graph |
target |
The target file in which the files will be generated. |
No return value. Exports the given graph into different CSV files saved in the target folder
## Not run: g=mully::demo() exportCSV(g,directory) ## End(Not run)
## Not run: g=mully::demo() exportCSV(g,directory) ## End(Not run)
Get the attributes of the edges connecting two nodes
getEdgeAttributes(g, nodeStart, nodeDest)
getEdgeAttributes(g, nodeStart, nodeDest)
g |
The input graph |
nodeStart |
The first endpoint of the edge |
nodeDest |
The second endpoint of the edge |
A dataframe containing the edges with their attributes. If both nodes' arguments are missing, it returns all the edges with their attributes.
g=mully::demo() #Print all Edges getEdgeAttributes(g) #Get a Single Edge getEdgeAttributes(g,"d2","g1")
g=mully::demo() #Print all Edges getEdgeAttributes(g) #Get a Single Edge getEdgeAttributes(g,"d2","g1")
Get the ids of the edges connecting two nodes
getIDEdge(g, nodeStart, nodeDest)
getIDEdge(g, nodeStart, nodeDest)
g |
The input graph |
nodeStart |
The first endpoint of the edge |
nodeDest |
The second endpoint of the edge |
A list containing the ids of the edges connecting the nodes
g=mully::demo() getIDEdge(g,"d2","dr1")
g=mully::demo() getIDEdge(g,"d2","dr1")
Get the id of a node
getIDNode(g, nameNode)
getIDNode(g, nameNode)
g |
The input graph |
nameNode |
The name of the node |
The id of the specified node as an integer
g=mully::demo() getIDNode(g,"g1")
g=mully::demo() getIDNode(g,"g1")
Get the nodes on a layer in a graph
getLayer(g, nameLayer)
getLayer(g, nameLayer)
g |
The input graph. |
nameLayer |
The name of the layer. |
A List of the nodes on the given layer.
g = mully::demo() getLayer(g,"gene")
g = mully::demo() getLayer(g,"gene")
Get the number of layers in a graph
getLayersCount(g)
getLayersCount(g)
g |
The input graph. |
The count of the layers.
g = mully("MyFirstMully",direct = FALSE) g = addLayer(g, c("Gene", "Drug", "Disease")) getLayersCount(g)
g = mully("MyFirstMully",direct = FALSE) g = addLayer(g, c("Gene", "Drug", "Disease")) getLayersCount(g)
Get a node from a graph
getNode(g, nameNode)
getNode(g, nameNode)
g |
The input graph. |
nameNode |
The name of the node. |
The node as igraph.vs
g=mully::demo() getNode(g,"g1")
g=mully::demo() getNode(g,"g1")
Get the attributes of a node
getNodeAttributes(g, nameNode, layerByName = FALSE)
getNodeAttributes(g, nameNode, layerByName = FALSE)
g |
The input graph |
nameNode |
The name of the node |
layerByName |
A boolean to specify whether to export the layers by name or by ID |
A dataframe containing the attributes of the specified node
g=mully::demo() getNodeAttributes(g,layerByName = TRUE)
g=mully::demo() getNodeAttributes(g,layerByName = TRUE)
Import Edges to a mully graph from a CSV file
importEdgesCSV(g, file)
importEdgesCSV(g, file)
g |
The mully graph to which the nodes will be added. The graph should already have the layers and the nodes. |
file |
The path to the CSV file containing the edges' information |
The mully graph with the added edges
Import a mully graph from CSV files
importGraphCSV(name = NA, direct = FALSE, layers, nodes, edges)
importGraphCSV(name = NA, direct = FALSE, layers, nodes, edges)
name |
The name of the graph |
direct |
A boolean to indicate if the graph is directed or not |
layers |
The path to the CSV file containing the layers' information |
nodes |
The path to the CSV file containing the nodes' information |
edges |
The path to the CSV file containing the edges' information |
A new mully graph
Import Layers to a mully graph from a CSV file
importLayersCSV(g, file)
importLayersCSV(g, file)
g |
The mully graph to which the layers will be added. If missing, a new mully graph is created |
file |
The path to the CSV file containing the layers' information |
The mully graph with the added layers
Import Nodes to a mully graph from a CSV file
importNodesCSV(g, file, name = "name")
importNodesCSV(g, file, name = "name")
g |
The mully graph to which the nodes will be added. The graph should already have the layers. |
file |
The path to the CSV file containing the nodes' information |
name |
The name of the column containing the names of the nodes |
The mully graph with the added nodes
Is this a mully graph?
is.mully(g)
is.mully(g)
g |
The input graph |
A boolean whether the graph is or not a mully object
Verify if the layer exists in a graph
isLayer(g, name)
isLayer(g, name)
g |
The input graph. |
name |
The name of the layer. |
A boolean value.
g = mully("MyFirstMully",direct = FALSE) g = addLayer(g, c("Gene", "Drug", "Disease")) isLayer(g,"Drug")
g = mully("MyFirstMully",direct = FALSE) g = addLayer(g, c("Gene", "Drug", "Disease")) isLayer(g,"Drug")
Merge or unite two graphs
merge(g1, g2)
merge(g1, g2)
g1 |
The first graph to merge. This is the base of the merge. |
g2 |
The second graph to merge. All of its elements are added to the first graph. |
The merge of the two graphs as a mully object. The merge is based on the first given graph
Create an empty multilayered graph
mully(name = NA, direct = TRUE)
mully(name = NA, direct = TRUE)
name |
The name to be assigned to the graph. |
direct |
A boolean value, if the graph is directed or not. By default TRUE. |
The created multilayered graph, a mully object.
g = mully("MyFirstMully",direct = FALSE)
g = mully("MyFirstMully",direct = FALSE)
Plot the graph in 2D
## S3 method for class 'mully' plot(x, layout, ...)
## S3 method for class 'mully' plot(x, layout, ...)
x |
The input graph |
layout |
The layout. Can either be random or scaled |
... |
Other arguments to be passed to plot.igraph |
No return value. A 2D plot of the given graph is created.
g=mully::demo() plot(g,"Scaled")
g=mully::demo() plot(g,"Scaled")
Plot the graph in 3D using rgl
plot3d( g, layers = TRUE, vertex.label = NA, vertex.label.color = NA, vertex.plac = "circle", edge.color = NA, edge.width = 5, edge.arrow.size = 10, edge.arrow.width = 1 )
plot3d( g, layers = TRUE, vertex.label = NA, vertex.label.color = NA, vertex.plac = "circle", edge.color = NA, edge.width = 5, edge.arrow.size = 10, edge.arrow.width = 1 )
g |
The input graph |
layers |
A boolean whether to add the layers or not |
vertex.label |
The vertices' labels |
vertex.label.color |
The vertices' colors. If not specified, the colors will be chosen randomly |
vertex.plac |
The placement form of the vertices on the layer. Can either be "circle" which will place them on a circle, or "disc" which will place them randomly on a disc. The default is "circle" |
edge.color |
The edges' colors. If not specified, inter-edges are black, and intra-edges have the same color as the nodes on the layer |
edge.width |
The edge width. Default set to 5. |
edge.arrow.size |
The edges' arrow size. Default set to 10 |
edge.arrow.width |
The edges' arrow width. Default set to 1 |
No return value. A 3D plot of the given graph is created.
This function can take the following arguments supported and not ignored by rglplot: vertex.label, vertex.label.color, edge.color, edge.width, edge.arrow.size,edge.arrow.width.
g=mully::demo() labels=getNodeAttributes(g)$name plot3d(g, layers=TRUE, vertex.label=labels,edge.width=6)
g=mully::demo() labels=getNodeAttributes(g)$name plot3d(g, layers=TRUE, vertex.label=labels,edge.width=6)
Print function
## S3 method for class 'mully' print(x, ...)
## S3 method for class 'mully' print(x, ...)
x |
The input graph |
... |
Other arguments to be passed to |
No return value. The given graph is printed
g=mully::demo() print(g)
g=mully::demo() print(g)
Delete an edge
removeEdge(g, nodeStart, nodeDest, attributes = NA, multi = FALSE)
removeEdge(g, nodeStart, nodeDest, attributes = NA, multi = FALSE)
g |
The input graph |
nodeStart |
The first endpoint of the edge |
nodeDest |
The second endpoint of the edge |
attributes |
The attributes of the edge to delete. Required if the nodes are multi-connected |
multi |
A boolean. Specifies whether to delete multiple edges or not, in case they exist. |
The mully graph with the deleted edges
g=mully::demo() removeEdge(g,"dr1","d2",multi=TRUE)
g=mully::demo() removeEdge(g,"dr1","d2",multi=TRUE)
Delete a layer or a set of layers from a graph
removeLayer(g, name, trans = FALSE)
removeLayer(g, name, trans = FALSE)
g |
The input graph. |
name |
The name or the list of the names of the layers to be deleted. |
trans |
A boolean whether to insert transitive edges or not |
The mully graph, with the given layer and its corresponding nodes and edges removed.
g = mully::demo() removeLayer(g,"gene",trans=TRUE)
g = mully::demo() removeLayer(g,"gene",trans=TRUE)
Delete a node or a set of nodes from a graph
removeNode(g, name, trans = FALSE)
removeNode(g, name, trans = FALSE)
g |
The input graph. |
name |
The name or the list of names of the nodes to be deleted. |
trans |
A boolean whether to insert transitive edges or not |
The mully graph, with the nodes deleted.
g=mully::demo() removeNode(g,"dr1",trans=TRUE)
g=mully::demo() removeNode(g,"dr1",trans=TRUE)