graphsim: An R package for simulating gene expression data from graph structures of biological pathways

Transcriptomic analysis is used to capture the molecular state of a cell or sample in many biological and medical applications. In addition to identifying alterations in activity at the level of individual genes, understanding changes in the gene networks that regulate fundamental biological mechanisms is also an important objective of molecular analysis. As a result, databases that describe biological pathways are increasingly uesad to assist with the interpretation of results from large-scale genomics studies. Incorporating information from biological pathways and gene regulatory networks into a genomic data analysis is a popular strategy, and there are many methods that provide this functionality for gene expression data. When developing or comparing such methods, it is important to gain an accurate assessment of their performance. Simulation-based validation studies are frequently used for this. This necessitates the use of simulated data that correctly accounts for pathway relationships and correlations. Here we present a versatile statistical framework to simulate correlated gene expression data from biological pathways, by sampling from a multivariate normal distribution derived from a graph structure. This procedure has been released as the graphsim R package on CRAN and GitHub (https://github.com/TomKellyGenetics/graphsim) and is compatible with any graph structure that can be described using the igraph package. This package allows the simulation of biological pathways from a graph structure based on a statistical model of gene expression.


Introduction: inference and modelling of biological networks
Network analysis of molecular biological pathways has the potential to lead to new insights into biology and medical genetics (Barabási & Oltvai, 2004;Hu, Thomas, & Brunak, 2016).Since gene expression profiles capture a consistent signature of the regulatory state of a cell (Ozsolak & Milos, 2011;Perou et al., 2000;Svensson, Vento-Tormo, & Teichmann, 2018), they can be used to analyse complex molecular states with genome-scale data.However, biological pathways are often analysed in a reductionist paradigm as amorphous sets of genes involved in particular functions, despite the fact that the relationships defined by pathway structure could further inform gene expression analyses.In many cases, the pathway relationships are well-defined, experimentally-validated, and are available in public databases (Croft et al., 2014).As a result, network analysis techniques can play an important role in furthering our understanding of biological pathways and aiding in the interpretation of genomics studies.
Gene networks provide insights into how cells are regulated, by mapping regulatory interactions between target genes and transcription factors, enhancers, and sites of epigenetic marks or chromatin structures (Barabási & Oltvai, 2004;Yamaguchi, Yoshida, Imoto, Higuchi, & Miyano, 2007).Inference using these regulatory interactions genomic analysis has the potential to radically expand the range of candidate biological pathways to be further explored, or to improve the accuracy of bioinformatics and functional genomic analysis.A number of methods have been developed to utilise timecourse gene expression data (Arner et al., 2015;Yamaguchi et al., 2007) using gene regulatory modules in state-space models and recursive vector autoregressive models (Hirose et al., 2008;Shimamura et al., 2009).Various approaches to gene regulation and networks at the genome-wide scale have led to novel biological insights (Arner et al., 2015;Komatsu et al., 2013), however, inference of regulatory networks has thus far primarily relied on experimental validation or resampling-based approaches to estimate the likelihood of specific network modules being predicted (Hawe, Theis, & Heinig, 2019;Markowetz & Spang, 2007).
Simulating datasets that account for pathway structure are of particular interest for benchmarking regulatory network inference techniques and methods being developed for genomics data containing complex biological interactions (Saelens, Cannoodt, Todorov, & Saeys, 2019;Schaffter, Marbach, & Floreano, 2011).Dynamical models using differential equations have been employed, such as by GeneNetWeaver (Schaffter et al., 2011), to generate simulated datasets specifically for benchmarking gene regulatory network inference techniques.There is also renewed interest in modelling biological pathways and simulating data for benchmarking due to the emergence of single-cell genomics technologies and the growing number of bioinformatics techniques developed to use this data (Saelens et al., 2019;Zappia, Phipson, & Oshlack, 2017).Packages such as 'splatter' (Zappia et al., 2017), which uses the gammapoisson distribution, have been developed to model single-cell data.SERGIO (Dibaeinia & Sinha, 2019) and dyngen (Cannoodt, Saelens, Deconinck, & Saeys, 2020) build on this by adding gene regulatory networks and multimodality respectively.These methods have been designed based on known deterministic relationships or synthetic reaction states, to which stochasticity is then added.However, it is computationally-intensive to model these reactions at scale or run many iterations for benchmarking.In some cases, it is only necessary to model the statistical variability and "noise" of RNA-Seq data in order to evaluate methods in the presence of multivariate correlation structures.
There is a need, therefore, for a systematic framework for statistical modelling and simulation of gene expression data derived from hypothetical, inferred or known gene networks.Here we present a package to achieve this, where samples from a multivariate normal distribution are used to generate normally-distributed log-expression data, with correlations between genes derived from the structure of the underlying pathway or gene regulatory network.This methodology enables simulation of expression profiles that approximate the log-transformed and normalised data from microarray studies, as well as bulk or single-cell RNA-Seq experiments.This procedure has been released as the graphsim package to enable the generation of simulated gene expression datasets containing pathway relationships from a known underlying network.These simulated datasets can be used to evaluate various bioinformatics methodologies, including statistical and network inference procedures.

Methodology and software
Here we present a procedure to simulate gene expression data with correlation structure derived from a known graph structure.This procedure assumes that transcriptomic data have been generated and follow a log-normal distribution (i.e., log(X ij ) ∼ M V N (µ, Σ), where µ and Σ are the mean vector and variance-covariance matrix respectively, for gene expression data derived from a biological pathway) after appropriate normalisation (Law, Chen, Shi, & Smyth, 2014;Li, Piao, Shon, & Ryu, 2015).Log-normality of gene expression matches the assumptions of the popular limma package (Matthew E R. et al., 2015), which is often used for the analysis of intensity-based data from gene expression microarray studies and count-based data from RNA-Seq experiments.This approach has also been applied for modelling UMIbased count data from single-cell RNA-Seq experiments in the DESCEND R package (Wang et al., 2018).
In order to simulate transcriptomic data, a pathway is first constructed as a graph structure, using the igraph R package (Csardi & Nepusz, 2006), with the status of the edge relationships defined (i.e, whether they activate or inhibit downstream pathway members).This procedure uses a graph structure such as that presented in Figure 1a.The graph can be defined by an adjacency matrix, A (with elements A ij ), where 1 if genes i and j are adjacent 0 otherwise A matrix, R, with elements R ij , is calculated based on distance (i.e., number of edges contained in the shortest path) between nodes, such that closer nodes are given more weight than more distant nodes, to define inter-node relationships.A geometrically-decreasing (relative) distance weighting is used to achieve this: 1 if genes i and j are adjacent ) dij if a path can be found between genes i and j 0 if no path exists between genes i and j where d ij is the length of the shortest path (i.e., minimum number of edges traversed) between genes (nodes) i and j in graph G.Each more distant node is thus related by 1 2 compared to the next nearest, as shown in Figure 2b.An arithmetically-decreasing (absolute) distance weighting is also supported in the graphsim R package which implements this procedure: if genes i and j are adjacent if a path can be found between genes i and j 0 if no path exists between genes i and j Assuming a unit variance for each gene, these values can be used to derive a Σ matrix: where ρ is the correlation between adjacent nodes.Thus covariances between adjacent nodes are assigned by a correlation parameter (ρ) and the remaining off-diagonal values in the matrix are based on scaling these correlations by the geometrically weighted relationship matrix (or the nearest positive definite matrix for Σ with negative correlations).
Computing the nearest positive definite matrix is necessary to ensure that the variancecovariance matrix can be inverted when used as a parameter in multivariate normal simulations, particularly when negative correlations are included for inhibitions (as shown below).Matrices that cannot be inverted occur rarely with biologically plausible graph structures but this approach allows for the computation of a plausible correlation matrix when the given graph structure is incomplete or contains loops.When required, the nearest positive definite matrix is computed using the nearPD function of the Matrix R package (Bates & Maechler, 2016) to perform Higham's algorithm (Higham, 2002) on variance-covariance matrices.The graphsim package gives a warning when this occurs.

Illustrations Generating a Graph Structure
The graph structure in Figure 1a was used to simulate correlated gene expression data by sampling from a multivariate normal distribution using the mvtnorm R package (Genz & Bretz, 2009;Genz et al., 2016).The graph structure visualisation in Figure 1 was specifically developed for (directed) igraph objects in and is available in the graphsim package.The plot_directed function enables customisation of plot parameters for each node or edge, and mixed (directed) edge types for indicating activation or inhibition.These inhibition links (which occur frequently in biological pathways) are demonstrated in Figure 1b.A graph structure can be generated and plotted using the following commands in R:

Generating a Simulated Expression Dataset
The correlation parameter of ρ = 0.8 is used to demonstrate the inter-correlated datasets using a geometrically-generated relationship matrix (as used for the example in Figure 2c).This Σ matrix was then used to sample from a multivariate normal distribution such that each gene had a mean of 0, standard deviation 1, and covariance within the range [0, 1] so that the off-diagonal elements of Σ represent correlations.This procedure generated a simulated (continuous normally-distributed) log-expression profile for each node (Figure 2e) with a corresponding correlation structure (Figure 2d).The simulated correlation structure closely resembled the expected correlation structure in Figure 2c) even for the relatively modest sample size (N = 100) illustrated in Figure 2. Once a gene expression dataset comprising multiple pathways has been generated (as in Figure 2e), it can then be used to test procedures designed for analysis of empirical gene expression data (such as those generated by microarrays or RNA-Seq) that have been normalised on a log-scale.The Σ matrix has been used to generate a simulated expression dataset of 100 samples (coloured blue to red from low to high) via sampling from the multivariate normal distribution.Here genes with closer relationships in the pathway structure show a higher correlation between simulated values.

Summary and discussion
Biological pathways are fundamental importance to understanding molecular biology.In order to translate findings from genomics studies into real-world applications such as improved healthcare, the roles of genes must be studied in the context of molecular pathways.Here we present a statistical framework to simulate gene expression from biological pathways, and provide the graphsim package in R to generate these simulated datasets.This approach is versatile and can be fine-tuned for modelling existing biological pathways or for testing whether constructed pathways can be detected by other means.In particular, methods to infer biological pathways and gene regulatory networks from gene expression data can be tested on simulated datasets using this framework.The package also enables simulation of complex gene expression datasets to test how these pathways impact on statistical analysis of gene expression data using existing methods or novel statistical methods being developed for gene expression data analysis.This approach is intended to be applied to bulk gene expression data but could in principle be adapted to modelling single-cell or different modalities such as genome-wide epigenetic data.

Computational details
Complete examples of code needed to produce the figures in this paper are available in the Rmarkdown version in the package GitHub repository (https://github.com/TomKellyGenetics/graphsim).Further details are available in the vignettes as well.
The results in this paper were obtained using R 4.0.2 with the igraph 1.2.5 Matrix 1.2-17, matrixcalc 1.0-3, and mvtnorm 1.1-1 packages.R itself and all dependent packages used are available from the Comprehensive Archive Network (CRAN) at https://CRAN.R-project.org.The graphsim 1.0.0 package can be installed from CRAN and the issues can be reported to the development version on GitHub.This package is included in the igraph.extensionslibrary on GitHub (https://github.com/TomKellyGenetics/igraph.extensions) which installs various tools for igraph analysis.This software is cross-platform and compatible with installations on Windows, Mac, and Linux operating systems.Updates to the package (graphsim 1.0.0) will be released on CRAN.

Figure 1 :
Figure 1: Simulated graph structures.A constructed graph structure used as an example to demonstrate the simulation procedure in Figures 2 and 3. Activating links are denoted by black arrows and inhibiting links by red edges.

Figure 2 :
Figure2: Simulating expression from a graph structure.An example of a graph structure (a) that has been used to derive a relationship matrix (b), Σ matrix (c) and correlation structure (d) from the relative distances between the nodes.Non-negative values are coloured white to red from 0 to 1 (e).The Σ matrix has been used to generate a simulated expression dataset of 100 samples (coloured blue to red from low to high) via sampling from the multivariate normal distribution.Here genes with closer relationships in the pathway structure show a higher correlation between simulated values.

Figure 3 :
Figure3: Simulating expression from graph structure with inhibitions.An example of a graph structure (a), that has been used to derive a relationship matrix (b), Σ matrix (c), and correlation structure (d), from the relative distances between the nodes.These values are coloured blue to red from −1 to 1 (e).This has been used to generate a simulated expression dataset of 100 samples (coloured blue to red from low to high) via sampling from the multivariate normal distribution.Here the inhibitory relationships between genes are reflected in negatively correlated simulated values.
Simulated expression data (log scale)

Figure 4 :
Figure4: Simulating expression from a biological pathway graph structure.The graph structure (a) of a known biological pathway, "TGF-β receptor signaling activates SMADs" (R-HSA-2173789), was used to derive a relationship matrix (b), Σ matrix (c) and correlation structure (d) from the relative distances between the nodes.These values are coloured blue to red from −1 to 1 (e).This has been used to generate a simulated expression dataset of 100 samples (coloured blue to red from low to high) via sampling from the multivariate normal distribution.Here modules of genes with correlated expression can be clearly discerned.