```{cat, include = FALSE} \tikzexternalize
```r knitr::opts_chunk$set(echo = TRUE) library(MetClassNetR) library(tidyverse) library(ggrepel) library(plyr)
This script compares several aspects of a set of networks. We start by reading
the networks, using the readNet
function, which gets as input the directory
in which the networks are stored (netDir
parameter). Each network
should be an independent file, and several formats are accepted (e.g., CSV and
GML). Please note that we assume that the networks will have equivalent node
names (i.e., they should all be subsets of a common set of nodes). Importantly,
you can define whether the networks are directed or not using the directed
parameter.
NOTE. You can also generate a predefined set of 4 toy-networks with the
makeToyNet
function, giving as parameter the path of the folder where you
want to store them.
# create toy networks netDir <- tempdir() makeToyNet(netDir) directed <- FALSE # read networks networks <- readNet(netDir, directed = directed, format = "csv")
Now that we have the networks to analyze, we will proceed to calculate some
basic statistics measurements and to make a plot for each of them. In order to
do so, use the calculNetStats
function, giving a parameter the networks you
just read with readNet
. To generate the plots, we will use the
PrintStatsPlots
function, which needs the results of the calculNetStats
function as input parameter.
The statistics that will be calculated and displayed are the following:
# calculate stats and generate plots statistics <- calculNetStats(networks) # print table with stats knitr::kable(statistics$netStats, caption = "General stats") # print plots printStatsPlots(statistics)
We will now calculate the overlap of the nodes and edges of all of our
networks, using the CalculateOverlap
function, which needs the networks to
analyze as input parameter. The CalculateOverlap
function the will also
generate two upset plots, one to show the overlap of nodes, and the other for
the edges. It is to note that the overlap of edges does not take direction into
account and it will thus consider the networks as undirected.
Please note that the upset plots show an intersection of sets, but also a difference, e.g., the upset plot of the overlap of nodes between 2 networks, will show: The common nodes (i.e., intersection) of nodes in both networks The nodes present in the first network, but not in the second one (difference), and * The nodes present in the second network, but not in the first one.
# calculate overlap of nodes and edges calculateOverlap(networks)
If you want to get the list of overlapping nodes, you can use the
getOverlappingNodes
function, giving as input the list of networks and the
list of index of the networks you want to take into account.
NOTE. If no list of index is provided, all the networks are considered for the
calculus of the overlap.
# get list of overlapping nodes getOverlappingNodes(networks)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.