BACKGROUND
network analysis and modeling is a rapidly growing area which is moving forward our understanding of biological processes.
networks are mathematical representations of the interactions among the components of a system.
nodes in a biological network usually represent biological units of interest such as genes, proteins, individuals, or species.
edges indicate interaction between nodes such as regulatory interaction, gene flow, social interactions, or infectious contacts  <cit> .
a basic model for biological networks assumes random mixing between nodes of the network.
the network patterns in real biological populations, however, are typically more heterogeneous than assumed by these simple models  <cit> .
for instance, biological networks often exhibit properties such as degree heterogeneity, assortative mixing, non-trivial clustering coefficients, and community structure .
of particular interest is community structure, which reflects the presence of large groups of nodes that are typically highly connected internally but only loosely connected to other groups  <cit> .
this pattern of large and relatively dense subgraphs is called assortative community structure.
in empirical networks, these groups, also called modules or communities, often correspond well with experimentally-known functional clusters within the overall system.
thus, community detection, by examining the patterns of interactions among the parts of a biological system, can help identify functional groups automatically, without prior knowledge of the system’s processes.
although community structure is believed to be a central organizational pattern in biological networks such as metabolic  <cit> , protein  <cit> , genetic  <cit> , food-web  <cit>  and pollination networks  <cit> , a detailed understanding of its relationship with other network topological properties is still limited.
in fact, the task of clearly identifying the true community structure within an empirical network is complicated by a multiplicity of community detection algorithms, multiple and conflicting definitions of communities, inconsistent outcomes from different approaches, and a relatively small number of networks for which ground truth is known.
although node attributes in empirical networks  are sometimes used to evaluate the accuracy of community detection methods  <cit> , these results are generally of ambiguous value as the failure to recover communities that correlates with some node attribute may simply indicate that the true features driving the network’s structure are unobserved, not that the identified communities are incorrect.
a more straightforward method of exploring the structural and functional role of a network property is to generate graphs which are random with respect to other properties except the one of interest.
for example, network properties such as degree distribution, assortativity and clustering coefficient have been studied using the configuration model  <cit> , and models for generating random graphs with tunable structural features  <cit> .
these graphs serve to identify the network measures that assume their empirical values in a particular network due to the particular network property of interest.
in this work, we propose a model for generating simple, connected random networks that have a specified degree distribution and level of community structure.
random graphs with tunable strength of community structure can have several purposes such as:  serving as benchmarks to test the performance of community detection algorithms;  serving as null models for empirical networks to investigate the combined effect of the observed degrees and the latent community structure on the network properties;  serving as proxy networks for modeling network dynamics in the absence of empirical network data; and  allowing for the systematic study of the impact of community structure on the dynamics that may flow on a network.
among these, the use of random graphs with tunable strength of community structure to serve as benchmarks has received the most attention and several such models have been proposed  <cit> .
a few studies have also looked at the role of community structure in the flow of disease through contact networks  <cit> .
however, the use of modular random graphs, which can be defined as random graphs that have a higher strength of community structure than what is expected at random, is still relatively unexplored in other applications.
previous work
in  <dig>  girvan and newman proposed a simple toy model for generating random networks with a specific configuration and strength of community structure  <cit> .
this model assumes a fixed number of modules each of equal size and where each node in each module has the same degree.
in this way, each module is an erdős-rényi random graph.
to produce modular structure, different but fixed probabilities are used to produce edges within or between modules.
although this toy model has been widely used to evaluate the accuracy of community detection algorithms, it has limited relevance to real-world networks, which are generally both larger and much more heterogeneous.
lancichinetti et al.
<cit>  introduced a generalization of the girvan-newman model that better incorporates some of these features, e.g., by including heterogeneity in both degree and community size.
however, this model assumes that degrees are always distributed in a particular way , which is also unrealistic.
yan et al.
<cit>  used a preferential attachment model to grow scale-free networks comprised of communities of nodes whose degrees follow a power-law distribution.
and, models for special graph types such as hierarchical networks  <cit> , bipartite networks  <cit> , and networks with overlapping modules  <cit>  have also been proposed.
these models also make strong assumptions about the degree or community size distributions, which may not be realistic for comparison with real biological networks.
a recently proposed model  <cit>  does generate networks with a broad range of degree distributions, modularity and community sizes, but its parameters have an unclear relationship with desired properties , making it difficult to use in practice.
thus, while these models may be sufficient for comparative evaluation of community detection algorithms, they are of limited value for understanding their performance and output when applied to real-world networks.
an alternative approach comes from probabilistic models, of which there are two popular classes.
exponential random graph models  have a long history of use in social network analysis, and can generate an ensemble of networks that contain certain frequencies of local graph features, including heterogeneous degrees, triangles, and 4-cycles  <cit> .
however, many classes of ergms exhibit pathological behavior when parameterized with triangles or higher-order structures  <cit> , which severely limits their utility.
stochastic block models  are more promising, but require a large number of parameters to be chosen before a graph can be generated.
in this approach, the probability of each link depends only on the community labels of its endpoints.
thus, to generate a network, we must specify the number of communities k, their sizes , and the k <dig>  group-pair probabilities.
the result is a random graph with specified community sizes, where each community is an erdős-rényi random graph with a specified internal density, and each pair of communities is a random bipartite graph with specified density.
the degree distributions of these networks is a mixture of poisson distributions, which can be unrealistic.
a recent generalization of the sbm due to karrer and newman  <cit>  allows the specification of the degree sequence, which circumvents this limitation but introduces another set of parameters to be chosen.
although the stochastic block models can in principle be used to generate synthetic networks, they are more commonly used within an inferrential framework in which community structure is recovered by estimating the various parameters directly from a network.
as a result, the practical use of the sbm as a null model, either for general benchmarking of community detection algorithms or for understanding the structure of biological networks, remains largely unexplored, and we lack clear answers as to how best to sample appropriately from its large parameter space in these contexts.
the sbm also does not provide a simple measure of the level of modularity in a network’s large-scale structure, which makes its structure more difficult to interpret.
the sbm is a promising model for many tasks, and adapting it to the questions we study here remains an interesting avenue for future work.
our approach
here, we develop and implement a simple simulation model for generating modular random graphs using only a small number of intuitive and interpretable parameters.
our model can generate graphs over a broad range of distributions of network degree and community size.
the generated graphs can range from very small  to large  network sizes and can be composed of a variable number of communities.
in methods below, we introduce our algorithm for generating modular random graphs.
in results and discussion, we consider the performance of our algorithm and structural features of our generated graphs to show that properties such as degree assortativity, clustering, and path length remain unchanged for increasing modularity.
we next demonstrate the applicability of the generated modular graphs to test the accuracy of extant community detection algorithms.
the accuracy of community detection algorithms depends on several network properties such as the network mean degree and strength of community structure, which is evident in our analysis.
finally, using a few empirical biological networks, we demonstrate that our model can be used to generate corresponding null modular graphs under two different models of randomization.
we conclude the paper with some thoughts about other applications and present some future directions.
methods
we present a model that generates undirected, simple, connected graphs with prescribed degree sequences and a specified level of community structure, while maintaining a graph structure that is otherwise as random  as possible.
below, we introduce some notation and a metric for measuring community structure, followed by a description of our model and the steps of the algorithm used to generate graphs with this specified structure.
measure of community structure
we begin with a graph g= that is comprised of a set of vertices or nodes v={v <dig> …,v
n
} and a set of edges e={e <dig> …,e
m
}.
g is undirected and simple .
the number of nodes and edges in g is |v|=n and |e|=m, respectively.
the neighborhood of a node v
i
is the set of nodes v
i
is connected to, n={v
j
| ∈e,v
i
≠v
j
,1≤j≤n}.
the degree of a node v
i
, or the size of the neighborhood connected to v
i
, is denoted as d=|n|.
a degree sequence, d, specifies the set of all node degrees as tuples, such that d={} and follows a probability distribution called the degree distribution with mean d¯.
each community or modulec
k
is defined as a subset of g that contains both nodes, v and edges e, where both the endpoints of each edge in e are contained in v. k is the number of modules in g and k ∈.
each node v
i
of g has a within-degree, d
w
=|n∩v|, which is the number of within-edges connecting v
i
to other nodes of the same module c
k
; and a between-degree, d
b
=|n−v|, i.e.
the number of between-edges connecting v
i
to nodes in different modules .
the strength of the community structure defined by a partition, {c
k
}, can be measured as modularity, q, and is defined as
q=∑k=1kekk−ak <dig>
where ekk=|e||e| denotes the proportion of all edges that are within module c
k
, and ak=∑vi∈ckd/2|e| represents the fraction of all edges that touch nodes in community c
k
.
when q= <dig>  the density of within-community edges is equivalent to what is expected when edges are distributed at random, conditioned on the given degree sequence.
values approaching q= <dig>  which is the maximum possible value of q, indicate networks with strong community structure.
typically, values for empirical network modularity fall in the range from about  <dig>  to  <dig>   <cit> .
however, in theory good et al.
<cit>  show that maximum q values depend on the network size and number of modules.
in order to generate a graph with a specified strength of community structure, q, equation  represents our first constraint, which we rewrite below in terms of the expected value of q, :
e=∑k=1kdw¯.skm−d¯.skm <dig>
where dw¯ and d¯ are the average within-degree and average degree, respectively, and s
k
=|v| is the module size for module k. thus, equation  allows us to specify dw¯ in terms of q, d¯, m and s
k
, assuming that the module-specific average degree and average within-degree are equal to d¯ and dw¯, respectively.
when sk=s¯ for all k, e reduces to dw¯d¯−1k.
we note that as the average within-degree  approaches the average degree , the graph, g becomes increasingly modular.
hence, the maximum modularity for g with k modules can be estimated as:
qmax≃sup=1−1k
algorithm
we present a model and an algorithm that generates undirected, unweighted, simple and connected modular random graphs.
the model is specified by a network size , degree distribution , an expected modularity , the number of modules , and the module size distribution ), with mean s¯.
, may be specified instead of a degree distribution, p
d
).
the algorithm proceeds in four steps:
<dig>  assign the n network nodes to k modules based on the size distribution p.
<dig>  assign degrees, d, to each node v
i
based on p
d
and d¯.
we next assign within-degrees, d
w
, to each node v
i
by assuming that the within-degrees follow the same distribution as p
d
with mean dw¯, which is estimated based on equation  above .
<dig>  connect between-edges based on a modified havel-hakimi model and randomize them .
<dig>  connect within-edges based on the havel-hakimi model and randomize them .
the generated graph then has a degree distribution that follows p
d
with mean d¯, k modules with sizes distributed as p, and a modularity q≈e.
we set an arbitrary tolerance of ε= <dig> , such that the achieved modularity is q=e± ε. the graph is also as random as possible given the constraints of the degree and community structure, contains no self loops , multi-edges , isolate nodes , or disconnected components.
below, we elaborate on each of the steps of this algorithm.
assigning nodes to modules
we sample module sizes, s
k
, for each of the k modules from the specified module size distribution, p so that ∑sk=n.
the n nodes are then arbitrarily  assigned to each module to satisfy the sampled module size sequence.
assigning degrees
based on the degree distribution specified, a degree sequence is sampled from the distribution to generate a degree, d, for each node v
i
.
to ensure that the degree sequence attains the expected mean of the distribution  and is realizable, we verify the handshake theorem  and the erdős-gallai criterion   <cit> , and that no node is assigned a degree of zero.
unless a within-degree sequence is specified, we assume that the within-degree distribution follows the class of the degree distribution specified, p
d
, with mean dw¯ based on equation  .
this assumption is considered reasonable as it holds true for several of the empirical networks we analyze .
however, our model can be extended for arbitrary within-degree distributions  , although the space of feasible within-degree distributions given a degree distribution is restricted.
next, we sample a within-degree sequence, d
w
, from this within-degree distribution.
using rejection sampling, we ensure that the within-degree sequence attains the expected overall mean, dw¯ within a tolerance εdw=εd¯ , and satisfies the following conditions:
● condition 1: d≥d
w
for all v
i
.
to ensure this, we sort the degree sequence and within-degree sequence, independently.
if d<d
w
for any v
i
in the ordered lists, the condition is not satisfied.
in figure s <dig> of additional file  <dig>  we discuss the rejection rates for the rejection sampling of both the degree and within-degree sequence.
● condition 2: a realizable within-degree sequence for each module, c
k
, as defined by the handshake theorem and the erdos-gallai criterion.
in addition, to ensure that each module approximately achieves the overall mean within-degree, dw¯, we specify the following constraint: max≤min.
if the sampled module sizes do not satisfy this criteria, the module sizes are re-sampled or an error is generated.
the between-degree sequence is generated by specifying d
b
=d−d
w
for each node v
i
.
to test if the between-degree sequence is realizable, we impose a criterion developed by chungphaisan  <cit>   for realizable degree sequences in multigraphs.
to do so, we imagine a coarse graph, h, where the modules of g are the nodes of h ={c <dig> c <dig> …c
k
}), and the between-edges that connect modules of g are the edges of h. we note that h is a multigraph, because g allows multiple between-edges of g to connect each pair of modules.
in this case, the degree sequence of h is d=)|d=∑vj∈ckdb,k=1…k.
the chungphaisan criterion then specifies that the multigraph degree sequence {d} on h is realizable if the following conditions are satisfied:
● condition 1: the handshake theorem is satisfied for {d}: ∑k=1kd=∑k=1k∑vj∈ckdb is even
● condition 2:∑k=1jd−bj≤∑k=j+1kmin for .
here, b is defined as the maximum number of edges allowed between a pair of nodes in h; in our case, b=max[ {d
b
}], the maximum between-degree of any node v
i
∈g.
we also generate graphs with q= <dig> by assuming the network is composed of a single module with no between-edges.
thus, d
w
=d and d
b
= <dig> for all v
i
∈g.
connecting edges
based on the within-degree sequence and between-degree sequence specified above, edges are connected in two steps .
nodes that belong to different modules are connected based on their between-degree to form between-edges  and nodes that belong to the same module are connected according to their within-degree to form within-edges .
we connect between-edges using a modified version of the havel-hakimi algorithm.
the havel-hakimi algorithm  <cit>  constructs graphs by sorting nodes according to their degree and successively connecting nodes of highest degree with each other.
after each step of connecting the highest degree node, the degree list is resorted and the process continues until all the edges on the graph are connected.
here, we modify this to construct between-edges by sorting nodes by highest between-degree, in order of highest total between-degree for the module to which they belong, and successively connecting the node at the top of the list randomly with other nodes.
connections are only made between nodes if they are not previously connected, belong to different modules, and do not both have within-degree of zero .
after each step the between-degree list is resorted, and the process continues until all between-edges are connected.
after all between-edges have been connected, the connections are randomized using a well-known method of rewiring through double-edge swaps  <cit> .
specifically, two randomly chosen between-edges  and  are removed, and replaced by two new edges  and , as long as u and x, and v and y belong to different modules, respectively.
the swaps are constrained to avoid the formation of self loops and multi-edges.
this process is repeated a large number of times to randomize edges.
we then connect within-edges using the standard havel-hakimi algorithm, applied to each module independently.
specifically, within-edges of a module are connected by sorting nodes of the module according to their within-degree and successively connecting nodes of highest within-degree with each other.
connections are only made between nodes if they are not previously connected, and do not both have a between-degree of zero .
after each step the within-degree list is resorted and the process continues until all the within-edges of the module are connected.
the connections are then randomized by rewiring through double-edge swaps  <cit> .
we do not specify that each module be connected .
however, if this is required, taylor’s algorithm can be used to rewire pairs of edges until the module is connected  <cit> .
specifically, the algorithm selects two random edges  and  that belong to two different disconnected components of the module.
as long as  and  are not existing edges, the  and  edges are removed and  and  are added.
taylor’s theorem proves that following such operation any disconnected module can be converted to a connected module with the same degree sequence.
RESULTS
using our simulation algorithm, we were able to generate modular random graphs of variable network size, number of communities, degree distribution, and community size distribution.
in figure  <dig>  we show sample networks of varying levels of modularity, q= <dig> , <dig> , <dig> .
we note that a network with three modules can approach a maximum modularity value of 2/ <dig> , and thus q =  <dig>  is a relatively high modularity for this particular network type.
in the sections that follow, we consider the algorithm performance, as well as structural properties of the generated graphs.
we then highlight two applications of our model: 1) to generate benchmark graphs for validation of community detection algorithms and 2) to generate null graphs for the analysis of empirical networks.
community detection algorithms assist in identifying community structure in empirical networks.
our model is able to generate modular networks de novo to test these algorithms.
once community structure has been identified in an empirical network with a community detection algorithm, the number of communities and the modularity level   can be used as input to our model to generate graphs that can act as random controls to test hypotheses about the empirical system.
performance & properties of generated graphs
performance
our model generates graphs that closely match the expected modularity and degree distribution.
the deviation of the observed modularity is less than  <dig>  from the expected value, given the specified partition.
the modular random graphs with poisson degree distribution generated by our model are similar to the ones described by girvan and newman  <cit>  with linking  and cross-linking probability  equal to dw¯s¯−1and d¯−dw¯s¯ respectively.
however, our model overcomes several limitations of the model proposed by girvan and newman  <cit>  and others  <cit>  by considering heterogeneity in total degree, within-module degree distribution, and module sizes.
unlike many of the existing models  <cit> , our model can generate modular random graphs with arbitrary degree distributions, including those obtained from empirical networks.
though we discuss modular random graphs with positive q values, our model can also generate disassortative modular random graphs .
in this case, nodes tend to connect to nodes in other modules and thus the density of edge connections within a module is less than what is expected at random.
additionally, we also compare our model to graphs generated based on a degree-corrected stochastic block model .
the details of the parameterization of the sbm and the results are shown in figure s <dig> in additional file 1).
structural properties
there are several other topological properties  that can influence network function and dynamics.
the most significant of these properties are degree assortativity , clustering coefficient  and average path length .
we have developed this model to generate graphs with specified degree distribution and modularity, while minimizing structural byproducts.
thus, it is important to confirm that we have reached this goal with the generative model above.
to evaluate the status of other structural properties due to the generative model, we specify graphs of n= <dig> following poisson , geometric
k−1), and power-law k−αζ degree distributions with d¯= <dig>  we chose these particular types of degree distributions as they have widely studied in the context of biological networks  <cit> .
each network has k= <dig> modules and a module size distribution p= <dig>  we generate modular random graphs with these specifications and modularity values that range from q= <dig> to q= <dig> , in steps of  <dig> .
for each level of modularity, we generated  <dig> such modular random graphs and calculated the degree assortativity , clustering coefficient , and average path length  for each network, which is illustrated in figure  <dig>  in networks with random community structure , that is random graphs with specified degree distributions , the value of r,c, and l are what are expected at random.
in figure  <dig>  we show that for increasing values of modularity, degree assortativity, clustering coefficient, and average path length remain relatively constant for all three network types .
at the highest levels of modularity, edge connections are constrained, particularly for the heavy-tailed geometric and power-law degree distributions, leading to an increase in clustering coefficient.
correlations between high clustering coefficient and high modularity have also been observed before  <cit> .
the average path length for all network types also increases at the highest levels of modularity, likely reflecting the lack of many paths between modules, requiring additional steps to reach nodes in different modules.
thus, our model is able to increase levels of modularity in random graphs without altering other topological properties significantly.
biological networks show remarkable variation in network size, connectivity and community size distribution, with some of them having particularly small network size, high degree, and small module sizes .
we therefore tested the performance of our generated networks under deviations in the network specifications of size, mean degree and module size distribution .
we find that the structural properties of our generated modular random graphs remain constant, except for two constraining conditions: a) high average degree  and b) low average module size .
at these parameter extremes, the modular random graphs become degree disassortative and have increased clustering coefficient.
a similar observation of network degree disassortativity has been made in hierarchically modular networks  <cit> .
in these two scenarios, the highest value of within-degree ) that a node can attain is constrained by the community size, which reduces the number of possible high within-degree nodes.
as a consequence high within-degree nodes must connect to low within-degree nodes more than expected, resulting in a degree disassortative network.
in these two cases, modules also become more dense and thus create more triangles resulting in a gradual increase in clustering.
path length, on the other hand, is not affected by these conditions and shows a consistent dependence on network size and mean degree, which is well known  <cit> .
application: benchmark graphs for community-detection algorithms
detecting communities in empirical networks has been an area of intensive research in the past decade  <cit>  since girvan and newman’s seminal paper on community detection  <cit> .
extant techniques such as modularity maximization, hierarchical clustering, the clique-based method, the spin glass method etc.
aim at achieving high levels of accuracy in detecting the correct partition , but have their own set of strengths and weaknesses.
choosing the best algorithm can be a difficult task especially as algorithms often use distinct definitions of communities and perform well within that description.
thus, it is exceedingly important to test community-detection algorithms against a suitable benchmark.
we propose our modular random graphs as benchmark graphs for the validation of existing and new algorithms of community detection.
to illustrate this use, we test the performance of six popular community detection algorithms: the louvain method  <cit> , fast modularity method  <cit> , the spin-glass based method  <cit> , the infomap method  <cit> , label propagation  <cit>  and the random-walk based method  <cit>  using our modular random graphs as benchmarks.
specifically, we generate a modular random graph for each level of modularity and used these community detection algorithms to detect their community structure.
we also test the performance of the algorithms on random graphs of specified degree distribution, with no modularity .
figure  <dig> summarizes the performance of these algorithms, as measured by the estimated q, for modular random graphs with three different degree distributions .
we also investigated the robustness of these algorithms on replicate modular random graphs at each modularity level, with the results presented in .the louvain, fast modularity algorithm, random-walk and infomap algorithm overestimate the modularity for networks with weak community structure, and underestimate the modularity for networks of moderate community structure across all three network types .
spinglass and label-propagation consistently underestimate the modularity of both weak and moderate community structure.
all the algorithms are fairly accurate at the highest strengths of community structure across the various network types.
the accuracy at a particular level of modularity and degree-distribution, however, varies for different algorithms.
for instance, the performance of spin-glass algorithm is better for poisson modular random graphs at modularity values of  <dig> - <dig> , whereas the louvain and label-propagation algorithm out-perform on geometric random modular graphs at these modularity values.
in addition to comparing the estimated values of modularity to the known values in the modular random graphs, we can compare the similarity in the partitions detected by the algorithms to the true partitions.
for this comparison, we use the jaccard similarity , which measures the similarity between two partitions based on the proportion of the union of the partitions that is made up by the intersection of the partitions  <cit> ; as well as the variation of information , which measures the distance between two partitions based on the amount of information lost when going from one partition to another  <cit> .
these results are presented in the .
as reflected in the results above, we find that partitioning is inaccurate when the true community structure is weak but improves as the q
t
r
u
e
value increases.
these observations have also been noted before by lacichinetti and fortunato  <cit> .
application: null analysis of empirical networks
it is crucial to have random controls in the study of biological systems.
our algorithm can be used to generate null models and applied to the detection of structure in empirical biological networks.
these null networks can be used to test hypotheses regarding the role of modularity and other topological features of the empirical networks.
to do so, one would first determine the number of communities and modularity level  of the sampled network using an appropriate community detection algorithm .
our algorithm can then be used to generate an ensemble of networks that match the empirical degree structure and community structure, and then compare the structural, functional, or dynamical properties of the empirical network to those of the generated modular random graphs.
because our model generates graphs without any structural byproducts , this is an appropriate model for generation of null models.
we note that our algorithm does not necessarily require knowledge of the complete empirical network, but rather only estimates of the degree structure and community structure.
the literature on algorithms for inference of network structure from a sample is growing, and currently includes work on inference of missing nodes, edges and even community structure  <cit> .
we demonstrate this application using four classes of biological networks, namely: a) a food-web, representing the trophic interactions at little rock lake in wisconsin with a network size of  <dig> and average degree =  <dig>   <cit> ; b) a protein-protein interaction network in saccharomyces cerevisiae  of size =  <dig> and average degree =  <dig>   <cit> ; c) a metabolic interaction network of caenorhabditis elegans of size =  <dig> and average degree  <dig>   <cit> ; and d) a network of social interactions in a community of dolphins living off doubtful sound, new zealand of size =  <dig> and average degree =  <dig>   <cit> .
visualizations of the dolphin social interaction network and the food-web trophic interaction network and its modular random counterpart are shown in figure  <dig>
for each of these four empirical networks, we generate modular random graphs  with three parameters estimated from the empirical networks:  the degree sequence, p
k
the modularity, q and  the average community size, s¯.
we note that as our goal is to construct null models, we assume that communities are of equal size, i.e.
p= <dig>  and that the within-degree distribution matches the degree distribution fitted from the specified degree sequence .
and the within-degree sequences estimated from the empirical networks, and we do this in table s <dig> of additional file 1).
specifically, we generate  <dig> such random graphs and measure structural properties of the generated graphs including clustering coefficient , average path length , degree assortativity .
we also generate random graphs based on the configuration model that have the same degree distribution and average network degree as the empirical network but are random with respect to other network properties for each of the four empirical networks .
our modular random graph model identifies which network measures assume their empirical values in a particular network because of  the observed degrees and  the latent community structure.
the configuration model, on the other hand, only specifies  and not   <cit> .
comparison to these configuration model networks thus helps us highlight the utility of our model to identify which empirical patterns in a network are deserving of further investigation.
figure  <dig> shows the value of each of these properties for the empirical networks as well as the ensemble mean of modular random and random graphs with matched degree distribution.
from figure  <dig> it is evident that none of the empirical biological networks have network structure identical to their null counterparts.
this suggests that the structure of each of these biological systems is governed by more than what is specified by the degree distribution and community structure.
however, the observed network properties of empirical networks are closer to the ensemble means of the modular random graphs, which indicates that modularity is an essential structural component of real biological networks and that it plays an important role in influencing other structural properties of the network.
for instance, compartmentalization induced by modularity promotes species persistence and system robustness by containing localized perturbation  <cit> , which might favor their selection during the course of evolution.
our results show that the empirical networks tested have a much higher modularity than the simple random graphs  and therefore provide evidence for this selection.
out of the three network properties that we tested apart from modularity, we found clustering coefficient of the generated random graphs to be significantly different from each of the empirical counterparts.
this may point to a functional role for “triangles” in these biological networks, significantly above or below what is prescribed by the degree and community structure.
little rock lake food web interactions
among the four empirical networks that we tested, the properties of the ensemble mean of null models such as assortativity and path length closely match most of the observed properties of little rock food web.
the observed clustering coefficient of food web is strikingly lower than either of the random graphs which confirm the observations of low clustering in food web made by earlier studies .
the observed path length of this food web is short  and only slightly longer than the path lengths of random graphs, which has also been noted before  <cit> .
we note that for this food web, the structural properties of the random graphs with matched degree distribution are quite similar to those of modular random graph counterparts, suggesting that the degree distribution, particularly the high density of edges in the network governs most of the other topological characteristics of this network.
modularity, on the other hand, seems to play a minor role in dictating the structural properties of this network.
yeast protein-protein interaction network
the empirical yeast protein network is more disassortative than the ensemble mean of null modular graphs .
disassortative interactions in protein-protein interaction networks are known to reduce interferences between functional modules and thus increase the overall robustness of the network to deleterious perturbations  <cit> , while also allowing for functions to be performed concurrently  <cit> .
the results therefore suggest that disassortative interactions may be selected for in the evolution of biological networks.
from figure  <dig> it is also evident that the yeast protein network has a higher value of clustering coefficient than the expected value predicted by the modular random graphs.
a high value of clustering coefficient indicates that there are several alternate interaction paths between two proteins, making the system more robust to perturbation  <cit> .
c.elegans metabolic interaction network
the c.elegans metabolic network demonstrates a shorter path length but higher clustering coefficient than both modular and random graphs with matched degree distribution .
a high clustering coefficient and short path length suggests that the graph has small-world properties, which has been observed in other metabolic networks as well  <cit> .
a highly disassortative degree structure is also well known in metabolic networks, although the mechanism leading to this property is unclear .
as the predicted value of disassortativity of the modular random graphs is closer to the observed value, our results suggest that the strong community structure of the metabolic networks could be one of the factors contributing to high degree disassortativity.
.
social interaction network of dolphins network at doubtful sound, new zealand
the empirical social interaction network of dolphins that we investigated demonstrated a negative assortativity  similar to other real biological networks .
interestingly, the assortativity value of both null modular and random graphs with matched degree distribution counterparts of the dolphin network is lower than the observed value, which suggests that the network is more assortative than expected.
degree assortativity has also been observed in other animal  <cit>  and human  <cit>  social interaction networks.
this result is quite intuitive for a social network and is also referred to as homophily: more gregarious individuals tend to interact with other gregarious individuals while introverted individuals prefer to associate with other introverts  <cit> .
the empirical dolphin network also demonstrated a lower value of clustering coefficient than the expected values of either null model.
low clustering coupled with high degree assortativity indicates that dolphin populations may be more susceptible to the propagation of infection or information, as transmission may occur rapidly through the entire network with such properties  <cit> .
CONCLUSIONS
in summary, the model that we propose in this study generates modular random graphs over a broad range of degree distribution and modularity values, as well as module size distributions.
we highlight that our model is specifically designed to generate networks which have modularity evenly divided across its modules, modulo the impact of module size.
this means that we are mitigating the resolution limit effect and indeed generating networks with the maximum modularity partition.
we also confirm that structural properties of our generated modular graphs such as assortativity, clustering and path length remain unperturbed for a broad range of parameter values.
this important feature allows these graphs to act as benchmark and control graphs to explicitly test hypotheses regarding the function and evolution of modularity in biological systems.
of the approaches available, our method provides flexibility and has been explored the most fully for these applications.
compartmentalization of biological networks has been an area of great interest to biologists.
what we refer to as community structure in this work is any segregation of a biological system into smaller subunits inter-connected by only a few connections.
it has been suggested that modularity in a system promotes system robustness and enhances species persistence by containing localized perturbations  <cit> .
metabolic networks of organisms living in a variable environment have indeed been found to be more modular  <cit> .
maintaining and selecting for modularity in biological networks, however, comes at a great cost of reducing system complexity  <cit> , longer developmental time and cost of complete module replacement in case of failure  <cit> .
it is therefore unclear why modularity would be strongly selected for as a structural feature of biological systems.
there is also a lack of evidence to prove that the functional localization of sub-goals overlaps with the structural segregation of the network into community structure.
our work provides a tool for the systematic study of network structure  and of the impact of connectivity and compartmentalization on system function and dynamics .
the detection of community structure plays a crucial role in our topological understanding of complex networks.
currently the performance of community detection methods is usually evaluated based on ground-truth from real networks.
however, determining reference communities in real networks is often a difficult task.
also, ground truth data on empirical network partitions do not necessarily identify system features based on network topology and thus may create a bias when analyzing community structure.
a more convenient technique of evaluating community detection method is to use artificial random graphs, but has been limited as most of the models fail to incorporate degree heterogeneity of real networks.
by providing a systematic method to generate benchmark graphs, our model can aid in the development of more robust community detection algorithms, and therefore improve our topological understanding of empirical networks.
a step beyond identifying the topological presence of network communities is the understanding of its evolution as well as the functional and dynamical role of community structure.
we believe this process can be facilitated by using an appropriate class of control or null graphs.
as a model for generating null networks, our method joins a suite of random graph models, each contributing to a hierarchy of null models.
the simplest model for generating random graphs  is the erdős-rényi random graph model, which produces graphs that are completely defined by their average degree and are random in all other respects.
a slightly more complex and general model is one that generates graphs with a specified degree distribution  but are random in all other respects  <cit> .
these models can be extended to sequentially include additional independent structural constraints, such as degree distribution and clustering coefficient  <cit> , or degree structure and community structure, as we have demonstrated here.
a further extension to this work will be designing models that generate random graphs with multiple structural constraints.
for example, our model can be combined with the one proposed by  <cit>  to generate random graphs with specified degree distribution as well as tunable strength of modularity and clustering coefficient.
availability and requirements
project name: modular random graph generatorproject home page:http://github.com/bansallaboperating system: platform independentprogramming language: python  <dig> other requirements: networkx python packagelicense: bsd-styleany restrictions to use by non-academics: none
competing interests
the authors declare that they have no competing interests.
authors’ contributions
ps and sb contributed to algorithm design and implementation.
ps, los, ac and sb contributed to manuscript writing.
all authors read and approved the final manuscript.
supplementary material
additional file 1
supplementary analysis.
additional analysis of algorithm with figures.
click here for file
acknowledgements
this work was supported by nsf award deb- <dig>

 network analysis and modeling is a rapidly growing area which is moving forward our understanding of biological processes. networks are mathematical representations of the interactions among the components of a system. nodes in a biological network usually represent biological units of interest such as genes, proteins, individuals, or species. edges indicate interaction between nodes such as regulatory interaction, gene flow, social interactions, or infectious contacts. a basic model for biological networks assumes random mixing between nodes of the network. the network patterns in real biological populations, however, are typically more heterogeneous than assumed by these simple models. for instance, biological networks often exhibit properties such as degree heterogeneity, assortative mixing, non-trivial clustering coefficients, and community structure. of particular interest is community structure, which reflects the presence of large groups of nodes that are typically highly connected internally but only loosely connected to other groups. this pattern of large and relatively dense subgraphs is called assortative community structure. in empirical networks, these groups, also called modules or communities, often correspond well with experimentally-known functional clusters within the overall system. thus, community detection, by examining the patterns of interactions among the parts of a biological system, can help identify functional groups automatically, without prior knowledge of the system’s processes. although community structure is believed to be a central organizational pattern in biological networks such as metabolic, protein, genetic, food-web and pollination networks, a detailed understanding of its relationship with other network topological properties is still limited. in fact, the task of clearly identifying the true community structure within an empirical network is complicated by a multiplicity of community detection algorithms, multiple and conflicting definitions of communities, inconsistent outcomes from different approaches, and a relatively small number of networks for which ground truth is known. although node attributes in empirical networks are sometimes used to evaluate the accuracy of community detection methods, these results are generally of ambiguous value as the failure to recover communities that correlates with some node attribute may simply indicate that the true features driving the network’s structure are unobserved, not that the identified communities are incorrect. a more straightforward method of exploring the structural and functional role of a network property is to generate graphs which are random with respect to other properties except the one of interest. for example, network properties such as degree distribution, assortativity and clustering coefficient have been studied using the configuration model, and models for generating random graphs with tunable structural features. these graphs serve to identify the network measures that assume their empirical values in a particular network due to the particular network property of interest. in this work, we propose a model for generating simple, connected random networks that have a specified degree distribution and level of community structure. random graphs with tunable strength of community structure can have several purposes such as: serving as benchmarks to test the performance of community detection algorithms; serving as null models for empirical networks to investigate the combined effect of the observed degrees and the latent community structure on the network properties; serving as proxy networks for modeling network dynamics in the absence of empirical network data; and allowing for the systematic study of the impact of community structure on the dynamics that may flow on a network. among these, the use of random graphs with tunable strength of community structure to serve as benchmarks has received the most attention and several such models have been proposed. a few studies have also looked at the role of community structure in the flow of disease through contact networks. however, the use of modular random graphs, which can be defined as random graphs that have a higher strength of community structure than what is expected at random, is still relatively unexplored in other applications. previous work in girvan and newman proposed a simple toy model for generating random networks with a specific configuration and strength of community structure. this model assumes a fixed number of modules each of equal size and where each node in each module has the same degree. in this way, each module is an erdős-rényi random graph. to produce modular structure, different but fixed probabilities are used to produce edges within or between modules. although this toy model has been widely used to evaluate the accuracy of community detection algorithms, it has limited relevance to real-world networks, which are generally both larger and much more heterogeneous. lancichinetti et al. introduced a generalization of the girvan-newman model that better incorporates some of these features, e.g., by including heterogeneity in both degree and community size. however, this model assumes that degrees are always distributed in a particular way, which is also unrealistic. yan et al. used a preferential attachment model to grow scale-free networks comprised of communities of nodes whose degrees follow a power-law distribution. and, models for special graph types such as hierarchical networks, bipartite networks, and networks with overlapping modules have also been proposed. these models also make strong assumptions about the degree or community size distributions, which may not be realistic for comparison with real biological networks. a recently proposed model does generate networks with a broad range of degree distributions, modularity and community sizes, but its parameters have an unclear relationship with desired properties, making it difficult to use in practice. thus, while these models may be sufficient for comparative evaluation of community detection algorithms, they are of limited value for understanding their performance and output when applied to real-world networks. an alternative approach comes from probabilistic models, of which there are two popular classes. exponential random graph models have a long history of use in social network analysis, and can generate an ensemble of networks that contain certain frequencies of local graph features, including heterogeneous degrees, triangles, and 4-cycles. however, many classes of ergms exhibit pathological behavior when parameterized with triangles or higher-order structures, which severely limits their utility. stochastic block models are more promising, but require a large number of parameters to be chosen before a graph can be generated. in this approach, the probability of each link depends only on the community labels of its endpoints. thus, to generate a network, we must specify the number of communities k, their sizes, and the k group-pair probabilities. the result is a random graph with specified community sizes, where each community is an erdős-rényi random graph with a specified internal density, and each pair of communities is a random bipartite graph with specified density. the degree distributions of these networks is a mixture of poisson distributions, which can be unrealistic. a recent generalization of the sbm due to karrer and newman allows the specification of the degree sequence, which circumvents this limitation but introduces another set of parameters to be chosen. although the stochastic block models can in principle be used to generate synthetic networks, they are more commonly used within an inferrential framework in which community structure is recovered by estimating the various parameters directly from a network. as a result, the practical use of the sbm as a null model, either for general benchmarking of community detection algorithms or for understanding the structure of biological networks, remains largely unexplored, and we lack clear answers as to how best to sample appropriately from its large parameter space in these contexts. the sbm also does not provide a simple measure of the level of modularity in a network’s large-scale structure, which makes its structure more difficult to interpret. the sbm is a promising model for many tasks, and adapting it to the questions we study here remains an interesting avenue for future work. our approach here, we develop and implement a simple simulation model for generating modular random graphs using only a small number of intuitive and interpretable parameters. our model can generate graphs over a broad range of distributions of network degree and community size. the generated graphs can range from very small to large network sizes and can be composed of a variable number of communities. in methods below, we introduce our algorithm for generating modular random graphs. in results and discussion, we consider the performance of our algorithm and structural features of our generated graphs to show that properties such as degree assortativity, clustering, and path length remain unchanged for increasing modularity. we next demonstrate the applicability of the generated modular graphs to test the accuracy of extant community detection algorithms. the accuracy of community detection algorithms depends on several network properties such as the network mean degree and strength of community structure, which is evident in our analysis. finally, using a few empirical biological networks, we demonstrate that our model can be used to generate corresponding null modular graphs under two different models of randomization. we conclude the paper with some thoughts about other applications and present some future directions. methods we present a model that generates undirected, simple, connected graphs with prescribed degree sequences and a specified level of community structure, while maintaining a graph structure that is otherwise as random as possible. below, we introduce some notation and a metric for measuring community structure, followed by a description of our model and the steps of the algorithm used to generate graphs with this specified structure. measure of community structure we begin with a graph g= that is comprised of a set of vertices or nodes v={v …,v n } and a set of edges e={e …,e m }. g is undirected and simple. the number of nodes and edges in g is |v|=n and |e|=m, respectively. the neighborhood of a node v i is the set of nodes v i is connected to, n={v j | ∈e,v i ≠v j,1≤j≤n}. the degree of a node v i, or the size of the neighborhood connected to v i, is denoted as d=|n|. a degree sequence, d, specifies the set of all node degrees as tuples, such that d={} and follows a probability distribution called the degree distribution with mean d¯. each community or modulec k is defined as a subset of g that contains both nodes, v and edges e, where both the endpoints of each edge in e are contained in v. k is the number of modules in g and k ∈. each node v i of g has a within-degree, d w =|n∩v|, which is the number of within-edges connecting v i to other nodes of the same module c k; and a between-degree, d b =|n−v|, i.e. the number of between-edges connecting v i to nodes in different modules. the strength of the community structure defined by a partition, {c k }, can be measured as modularity, q, and is defined as q=∑k=1kekk−ak where ekk=|e||e| denotes the proportion of all edges that are within module c k, and ak=∑vi∈ckd/2|e| represents the fraction of all edges that touch nodes in community c k. when q= the density of within-community edges is equivalent to what is expected when edges are distributed at random, conditioned on the given degree sequence. values approaching q= which is the maximum possible value of q, indicate networks with strong community structure. typically, values for empirical network modularity fall in the range from about to. however, in theory good et al. show that maximum q values depend on the network size and number of modules. in order to generate a graph with a specified strength of community structure, q, equation represents our first constraint, which we rewrite below in terms of the expected value of q,: e=∑k=1kdw¯.skm−d¯.skm where dw¯ and d¯ are the average within-degree and average degree, respectively, and s k =|v| is the module size for module k. thus, equation allows us to specify dw¯ in terms of q, d¯, m and s k, assuming that the module-specific average degree and average within-degree are equal to d¯ and dw¯, respectively. when sk=s¯ for all k, e reduces to dw¯d¯−1k. we note that as the average within-degree approaches the average degree, the graph, g becomes increasingly modular. hence, the maximum modularity for g with k modules can be estimated as: qmax≃sup=1−1k algorithm we present a model and an algorithm that generates undirected, unweighted, simple and connected modular random graphs. the model is specified by a network size, degree distribution, an expected modularity, the number of modules, and the module size distribution ), with mean s¯., may be specified instead of a degree distribution, p d ). the algorithm proceeds in four steps: assign the n network nodes to k modules based on the size distribution p. assign degrees, d, to each node v i based on p d and d¯. we next assign within-degrees, d w, to each node v i by assuming that the within-degrees follow the same distribution as p d with mean dw¯, which is estimated based on equation above. connect between-edges based on a modified havel-hakimi model and randomize them. connect within-edges based on the havel-hakimi model and randomize them. the generated graph then has a degree distribution that follows p d with mean d¯, k modules with sizes distributed as p, and a modularity q≈e. we set an arbitrary tolerance of ε=, such that the achieved modularity is q=e± ε. the graph is also as random as possible given the constraints of the degree and community structure, contains no self loops, multi-edges, isolate nodes, or disconnected components. below, we elaborate on each of the steps of this algorithm. assigning nodes to modules we sample module sizes, s k, for each of the k modules from the specified module size distribution, p so that ∑sk=n. the n nodes are then arbitrarily assigned to each module to satisfy the sampled module size sequence. assigning degrees based on the degree distribution specified, a degree sequence is sampled from the distribution to generate a degree, d, for each node v i. to ensure that the degree sequence attains the expected mean of the distribution and is realizable, we verify the handshake theorem and the erdős-gallai criterion, and that no node is assigned a degree of zero. unless a within-degree sequence is specified, we assume that the within-degree distribution follows the class of the degree distribution specified, p d, with mean dw¯ based on equation. this assumption is considered reasonable as it holds true for several of the empirical networks we analyze. however, our model can be extended for arbitrary within-degree distributions, although the space of feasible within-degree distributions given a degree distribution is restricted. next, we sample a within-degree sequence, d w, from this within-degree distribution. using rejection sampling, we ensure that the within-degree sequence attains the expected overall mean, dw¯ within a tolerance εdw=εd¯, and satisfies the following conditions: ● condition 1: d≥d w for all v i. to ensure this, we sort the degree sequence and within-degree sequence, independently. if d<d w for any v i in the ordered lists, the condition is not satisfied. in figure s of additional file we discuss the rejection rates for the rejection sampling of both the degree and within-degree sequence. ● condition 2: a realizable within-degree sequence for each module, c k, as defined by the handshake theorem and the erdos-gallai criterion. in addition, to ensure that each module approximately achieves the overall mean within-degree, dw¯, we specify the following constraint: max≤min. if the sampled module sizes do not satisfy this criteria, the module sizes are re-sampled or an error is generated. the between-degree sequence is generated by specifying d b =d−d w for each node v i. to test if the between-degree sequence is realizable, we impose a criterion developed by chungphaisan for realizable degree sequences in multigraphs. to do so, we imagine a coarse graph, h, where the modules of g are the nodes of h ={c c …c k }), and the between-edges that connect modules of g are the edges of h. we note that h is a multigraph, because g allows multiple between-edges of g to connect each pair of modules. in this case, the degree sequence of h is d=)|d=∑vj∈ckdb,k=1…k. the chungphaisan criterion then specifies that the multigraph degree sequence {d} on h is realizable if the following conditions are satisfied: ● condition 1: the handshake theorem is satisfied for {d}: ∑k=1kd=∑k=1k∑vj∈ckdb is even ● condition 2:∑k=1jd−bj≤∑k=j+1kmin for. here, b is defined as the maximum number of edges allowed between a pair of nodes in h; in our case, b=max[ {d b }], the maximum between-degree of any node v i ∈g. we also generate graphs with q= by assuming the network is composed of a single module with no between-edges. thus, d w =d and d b = for all v i ∈g. connecting edges based on the within-degree sequence and between-degree sequence specified above, edges are connected in two steps. nodes that belong to different modules are connected based on their between-degree to form between-edges and nodes that belong to the same module are connected according to their within-degree to form within-edges. we connect between-edges using a modified version of the havel-hakimi algorithm. the havel-hakimi algorithm constructs graphs by sorting nodes according to their degree and successively connecting nodes of highest degree with each other. after each step of connecting the highest degree node, the degree list is resorted and the process continues until all the edges on the graph are connected. here, we modify this to construct between-edges by sorting nodes by highest between-degree, in order of highest total between-degree for the module to which they belong, and successively connecting the node at the top of the list randomly with other nodes. connections are only made between nodes if they are not previously connected, belong to different modules, and do not both have within-degree of zero. after each step the between-degree list is resorted, and the process continues until all between-edges are connected. after all between-edges have been connected, the connections are randomized using a well-known method of rewiring through double-edge swaps. specifically, two randomly chosen between-edges and are removed, and replaced by two new edges and, as long as u and x, and v and y belong to different modules, respectively. the swaps are constrained to avoid the formation of self loops and multi-edges. this process is repeated a large number of times to randomize edges. we then connect within-edges using the standard havel-hakimi algorithm, applied to each module independently. specifically, within-edges of a module are connected by sorting nodes of the module according to their within-degree and successively connecting nodes of highest within-degree with each other. connections are only made between nodes if they are not previously connected, and do not both have a between-degree of zero. after each step the within-degree list is resorted and the process continues until all the within-edges of the module are connected. the connections are then randomized by rewiring through double-edge swaps. we do not specify that each module be connected. however, if this is required, taylor’s algorithm can be used to rewire pairs of edges until the module is connected. specifically, the algorithm selects two random edges and that belong to two different disconnected components of the module. as long as and are not existing edges, the and edges are removed and and are added. taylor’s theorem proves that following such operation any disconnected module can be converted to a connected module with the same degree sequence.  using our simulation algorithm, we were able to generate modular random graphs of variable network size, number of communities, degree distribution, and community size distribution. in figure we show sample networks of varying levels of modularity, q=,,. we note that a network with three modules can approach a maximum modularity value of 2/, and thus q = is a relatively high modularity for this particular network type. in the sections that follow, we consider the algorithm performance, as well as structural properties of the generated graphs. we then highlight two applications of our model: 1) to generate benchmark graphs for validation of community detection algorithms and 2) to generate null graphs for the analysis of empirical networks. community detection algorithms assist in identifying community structure in empirical networks. our model is able to generate modular networks de novo to test these algorithms. once community structure has been identified in an empirical network with a community detection algorithm, the number of communities and the modularity level can be used as input to our model to generate graphs that can act as random controls to test hypotheses about the empirical system. performance & properties of generated graphs performance our model generates graphs that closely match the expected modularity and degree distribution. the deviation of the observed modularity is less than from the expected value, given the specified partition. the modular random graphs with poisson degree distribution generated by our model are similar to the ones described by girvan and newman with linking and cross-linking probability equal to dw¯s¯−1and d¯−dw¯s¯ respectively. however, our model overcomes several limitations of the model proposed by girvan and newman and others by considering heterogeneity in total degree, within-module degree distribution, and module sizes. unlike many of the existing models, our model can generate modular random graphs with arbitrary degree distributions, including those obtained from empirical networks. though we discuss modular random graphs with positive q values, our model can also generate disassortative modular random graphs. in this case, nodes tend to connect to nodes in other modules and thus the density of edge connections within a module is less than what is expected at random. additionally, we also compare our model to graphs generated based on a degree-corrected stochastic block model. the details of the parameterization of the sbm and the results are shown in figure s in additional file 1). structural properties there are several other topological properties that can influence network function and dynamics. the most significant of these properties are degree assortativity, clustering coefficient and average path length. we have developed this model to generate graphs with specified degree distribution and modularity, while minimizing structural byproducts. thus, it is important to confirm that we have reached this goal with the generative model above. to evaluate the status of other structural properties due to the generative model, we specify graphs of n= following poisson, geometric k−1), and power-law k−αζ degree distributions with d¯= we chose these particular types of degree distributions as they have widely studied in the context of biological networks. each network has k= modules and a module size distribution p= we generate modular random graphs with these specifications and modularity values that range from q= to q=, in steps of. for each level of modularity, we generated such modular random graphs and calculated the degree assortativity, clustering coefficient, and average path length for each network, which is illustrated in figure in networks with random community structure, that is random graphs with specified degree distributions, the value of r,c, and l are what are expected at random. in figure we show that for increasing values of modularity, degree assortativity, clustering coefficient, and average path length remain relatively constant for all three network types. at the highest levels of modularity, edge connections are constrained, particularly for the heavy-tailed geometric and power-law degree distributions, leading to an increase in clustering coefficient. correlations between high clustering coefficient and high modularity have also been observed before. the average path length for all network types also increases at the highest levels of modularity, likely reflecting the lack of many paths between modules, requiring additional steps to reach nodes in different modules. thus, our model is able to increase levels of modularity in random graphs without altering other topological properties significantly. biological networks show remarkable variation in network size, connectivity and community size distribution, with some of them having particularly small network size, high degree, and small module sizes. we therefore tested the performance of our generated networks under deviations in the network specifications of size, mean degree and module size distribution. we find that the structural properties of our generated modular random graphs remain constant, except for two constraining conditions: a) high average degree and b) low average module size. at these parameter extremes, the modular random graphs become degree disassortative and have increased clustering coefficient. a similar observation of network degree disassortativity has been made in hierarchically modular networks. in these two scenarios, the highest value of within-degree ) that a node can attain is constrained by the community size, which reduces the number of possible high within-degree nodes. as a consequence high within-degree nodes must connect to low within-degree nodes more than expected, resulting in a degree disassortative network. in these two cases, modules also become more dense and thus create more triangles resulting in a gradual increase in clustering. path length, on the other hand, is not affected by these conditions and shows a consistent dependence on network size and mean degree, which is well known. application: benchmark graphs for community-detection algorithms detecting communities in empirical networks has been an area of intensive research in the past decade since girvan and newman’s seminal paper on community detection. extant techniques such as modularity maximization, hierarchical clustering, the clique-based method, the spin glass method etc. aim at achieving high levels of accuracy in detecting the correct partition, but have their own set of strengths and weaknesses. choosing the best algorithm can be a difficult task especially as algorithms often use distinct definitions of communities and perform well within that description. thus, it is exceedingly important to test community-detection algorithms against a suitable benchmark. we propose our modular random graphs as benchmark graphs for the validation of existing and new algorithms of community detection. to illustrate this use, we test the performance of six popular community detection algorithms: the louvain method, fast modularity method, the spin-glass based method, the infomap method, label propagation and the random-walk based method using our modular random graphs as benchmarks. specifically, we generate a modular random graph for each level of modularity and used these community detection algorithms to detect their community structure. we also test the performance of the algorithms on random graphs of specified degree distribution, with no modularity. figure summarizes the performance of these algorithms, as measured by the estimated q, for modular random graphs with three different degree distributions. we also investigated the robustness of these algorithms on replicate modular random graphs at each modularity level, with the results presented in.the louvain, fast modularity algorithm, random-walk and infomap algorithm overestimate the modularity for networks with weak community structure, and underestimate the modularity for networks of moderate community structure across all three network types. spinglass and label-propagation consistently underestimate the modularity of both weak and moderate community structure. all the algorithms are fairly accurate at the highest strengths of community structure across the various network types. the accuracy at a particular level of modularity and degree-distribution, however, varies for different algorithms. for instance, the performance of spin-glass algorithm is better for poisson modular random graphs at modularity values of -, whereas the louvain and label-propagation algorithm out-perform on geometric random modular graphs at these modularity values. in addition to comparing the estimated values of modularity to the known values in the modular random graphs, we can compare the similarity in the partitions detected by the algorithms to the true partitions. for this comparison, we use the jaccard similarity, which measures the similarity between two partitions based on the proportion of the union of the partitions that is made up by the intersection of the partitions; as well as the variation of information, which measures the distance between two partitions based on the amount of information lost when going from one partition to another. these results are presented in the. as reflected in the results above, we find that partitioning is inaccurate when the true community structure is weak but improves as the q t r u e value increases. these observations have also been noted before by lacichinetti and fortunato. application: null analysis of empirical networks it is crucial to have random controls in the study of biological systems. our algorithm can be used to generate null models and applied to the detection of structure in empirical biological networks. these null networks can be used to test hypotheses regarding the role of modularity and other topological features of the empirical networks. to do so, one would first determine the number of communities and modularity level of the sampled network using an appropriate community detection algorithm. our algorithm can then be used to generate an ensemble of networks that match the empirical degree structure and community structure, and then compare the structural, functional, or dynamical properties of the empirical network to those of the generated modular random graphs. because our model generates graphs without any structural byproducts, this is an appropriate model for generation of null models. we note that our algorithm does not necessarily require knowledge of the complete empirical network, but rather only estimates of the degree structure and community structure. the literature on algorithms for inference of network structure from a sample is growing, and currently includes work on inference of missing nodes, edges and even community structure. we demonstrate this application using four classes of biological networks, namely: a) a food-web, representing the trophic interactions at little rock lake in wisconsin with a network size of and average degree =; b) a protein-protein interaction network in saccharomyces cerevisiae of size = and average degree =; c) a metabolic interaction network of caenorhabditis elegans of size = and average degree; and d) a network of social interactions in a community of dolphins living off doubtful sound, new zealand of size = and average degree =. visualizations of the dolphin social interaction network and the food-web trophic interaction network and its modular random counterpart are shown in figure for each of these four empirical networks, we generate modular random graphs with three parameters estimated from the empirical networks: the degree sequence, p k the modularity, q and the average community size, s¯. we note that as our goal is to construct null models, we assume that communities are of equal size, i.e. p= and that the within-degree distribution matches the degree distribution fitted from the specified degree sequence. and the within-degree sequences estimated from the empirical networks, and we do this in table s of additional file 1). specifically, we generate such random graphs and measure structural properties of the generated graphs including clustering coefficient, average path length, degree assortativity. we also generate random graphs based on the configuration model that have the same degree distribution and average network degree as the empirical network but are random with respect to other network properties for each of the four empirical networks. our modular random graph model identifies which network measures assume their empirical values in a particular network because of the observed degrees and the latent community structure. the configuration model, on the other hand, only specifies and not. comparison to these configuration model networks thus helps us highlight the utility of our model to identify which empirical patterns in a network are deserving of further investigation. figure shows the value of each of these properties for the empirical networks as well as the ensemble mean of modular random and random graphs with matched degree distribution. from figure it is evident that none of the empirical biological networks have network structure identical to their null counterparts. this suggests that the structure of each of these biological systems is governed by more than what is specified by the degree distribution and community structure. however, the observed network properties of empirical networks are closer to the ensemble means of the modular random graphs, which indicates that modularity is an essential structural component of real biological networks and that it plays an important role in influencing other structural properties of the network. for instance, compartmentalization induced by modularity promotes species persistence and system robustness by containing localized perturbation, which might favor their selection during the course of evolution. our results show that the empirical networks tested have a much higher modularity than the simple random graphs and therefore provide evidence for this selection. out of the three network properties that we tested apart from modularity, we found clustering coefficient of the generated random graphs to be significantly different from each of the empirical counterparts. this may point to a functional role for “triangles” in these biological networks, significantly above or below what is prescribed by the degree and community structure. little rock lake food web interactions among the four empirical networks that we tested, the properties of the ensemble mean of null models such as assortativity and path length closely match most of the observed properties of little rock food web. the observed clustering coefficient of food web is strikingly lower than either of the random graphs which confirm the observations of low clustering in food web made by earlier studies. the observed path length of this food web is short and only slightly longer than the path lengths of random graphs, which has also been noted before. we note that for this food web, the structural properties of the random graphs with matched degree distribution are quite similar to those of modular random graph counterparts, suggesting that the degree distribution, particularly the high density of edges in the network governs most of the other topological characteristics of this network. modularity, on the other hand, seems to play a minor role in dictating the structural properties of this network. yeast protein-protein interaction network the empirical yeast protein network is more disassortative than the ensemble mean of null modular graphs. disassortative interactions in protein-protein interaction networks are known to reduce interferences between functional modules and thus increase the overall robustness of the network to deleterious perturbations, while also allowing for functions to be performed concurrently. the results therefore suggest that disassortative interactions may be selected for in the evolution of biological networks. from figure it is also evident that the yeast protein network has a higher value of clustering coefficient than the expected value predicted by the modular random graphs. a high value of clustering coefficient indicates that there are several alternate interaction paths between two proteins, making the system more robust to perturbation. c.elegans metabolic interaction network the c.elegans metabolic network demonstrates a shorter path length but higher clustering coefficient than both modular and random graphs with matched degree distribution. a high clustering coefficient and short path length suggests that the graph has small-world properties, which has been observed in other metabolic networks as well. a highly disassortative degree structure is also well known in metabolic networks, although the mechanism leading to this property is unclear. as the predicted value of disassortativity of the modular random graphs is closer to the observed value, our results suggest that the strong community structure of the metabolic networks could be one of the factors contributing to high degree disassortativity.. social interaction network of dolphins network at doubtful sound, new zealand the empirical social interaction network of dolphins that we investigated demonstrated a negative assortativity similar to other real biological networks. interestingly, the assortativity value of both null modular and random graphs with matched degree distribution counterparts of the dolphin network is lower than the observed value, which suggests that the network is more assortative than expected. degree assortativity has also been observed in other animal and human social interaction networks. this result is quite intuitive for a social network and is also referred to as homophily: more gregarious individuals tend to interact with other gregarious individuals while introverted individuals prefer to associate with other introverts. the empirical dolphin network also demonstrated a lower value of clustering coefficient than the expected values of either null model. low clustering coupled with high degree assortativity indicates that dolphin populations may be more susceptible to the propagation of infection or information, as transmission may occur rapidly through the entire network with such properties.  in summary, the model that we propose in this study generates modular random graphs over a broad range of degree distribution and modularity values, as well as module size distributions. we highlight that our model is specifically designed to generate networks which have modularity evenly divided across its modules, modulo the impact of module size. this means that we are mitigating the resolution limit effect and indeed generating networks with the maximum modularity partition. we also confirm that structural properties of our generated modular graphs such as assortativity, clustering and path length remain unperturbed for a broad range of parameter values. this important feature allows these graphs to act as benchmark and control graphs to explicitly test hypotheses regarding the function and evolution of modularity in biological systems. of the approaches available, our method provides flexibility and has been explored the most fully for these applications. compartmentalization of biological networks has been an area of great interest to biologists. what we refer to as community structure in this work is any segregation of a biological system into smaller subunits inter-connected by only a few connections. it has been suggested that modularity in a system promotes system robustness and enhances species persistence by containing localized perturbations. metabolic networks of organisms living in a variable environment have indeed been found to be more modular. maintaining and selecting for modularity in biological networks, however, comes at a great cost of reducing system complexity, longer developmental time and cost of complete module replacement in case of failure. it is therefore unclear why modularity would be strongly selected for as a structural feature of biological systems. there is also a lack of evidence to prove that the functional localization of sub-goals overlaps with the structural segregation of the network into community structure. our work provides a tool for the systematic study of network structure and of the impact of connectivity and compartmentalization on system function and dynamics. the detection of community structure plays a crucial role in our topological understanding of complex networks. currently the performance of community detection methods is usually evaluated based on ground-truth from real networks. however, determining reference communities in real networks is often a difficult task. also, ground truth data on empirical network partitions do not necessarily identify system features based on network topology and thus may create a bias when analyzing community structure. a more convenient technique of evaluating community detection method is to use artificial random graphs, but has been limited as most of the models fail to incorporate degree heterogeneity of real networks. by providing a systematic method to generate benchmark graphs, our model can aid in the development of more robust community detection algorithms, and therefore improve our topological understanding of empirical networks. a step beyond identifying the topological presence of network communities is the understanding of its evolution as well as the functional and dynamical role of community structure. we believe this process can be facilitated by using an appropriate class of control or null graphs. as a model for generating null networks, our method joins a suite of random graph models, each contributing to a hierarchy of null models. the simplest model for generating random graphs is the erdős-rényi random graph model, which produces graphs that are completely defined by their average degree and are random in all other respects. a slightly more complex and general model is one that generates graphs with a specified degree distribution but are random in all other respects. these models can be extended to sequentially include additional independent structural constraints, such as degree distribution and clustering coefficient, or degree structure and community structure, as we have demonstrated here. a further extension to this work will be designing models that generate random graphs with multiple structural constraints. for example, our model can be combined with the one proposed by to generate random graphs with specified degree distribution as well as tunable strength of modularity and clustering coefficient. availability and requirements project name: modular random graph generatorproject home page:http://github.com/bansallaboperating system: platform independentprogramming language: python other requirements: networkx python packagelicense: bsd-styleany restrictions to use by non-academics: none competing interests the authors declare that they have no competing interests. authors’ contributions ps and sb contributed to algorithm design and implementation. ps, los, ac and sb contributed to manuscript writing. all authors read and approved the final manuscript. supplementary material additional file 1 supplementary analysis. additional analysis of algorithm with figures. click here for file acknowledgements this work was supported by nsf award deb- 
our model allows for the systematic study of the presence of community structure and its impact on network function and dynamics. community structure is ubiquitous in biological networks. additionally, we demonstrate two important applications of our model: to generate networks that can be used to benchmark existing and new algorithms for detecting communities in biological networks; and to generate null models to serve as random controls when investigating the impact of complex network features beyond the byproduct of degree and modularity in empirical biological networks. here, we develop a generative model to produce undirected, simple, connected graphs with a specified degrees and pattern of communities, while maintaining a graph structure that is as random as possible. even when community structure is identified in an empirical system, disentangling the effect of community structure from other network properties such as clustering coefficient and assortativity can be a challenge. this process is a crucial step in unraveling the functional consequences of the structural properties of biological systems and uncovering the mechanisms that drive these systems. choosing an appropriate community detection algorithm to identify the community structure in an empirical network can be difficult, however, as the many algorithms available are based on a variety of cost functions and are difficult to validate. there has been an increased interest in unraveling the community structure of biological systems as it may provide important insights into a system’s functional components and the impact of local structures on dynamics at a global scale.
 community structure is ubiquitous in biological networks. there has been an increased interest in unraveling the community structure of biological systems as it may provide important insights into a system’s functional components and the impact of local structures on dynamics at a global scale. choosing an appropriate community detection algorithm to identify the community structure in an empirical network can be difficult, however, as the many algorithms available are based on a variety of cost functions and are difficult to validate. even when community structure is identified in an empirical system, disentangling the effect of community structure from other network properties such as clustering coefficient and assortativity can be a challenge.  here, we develop a generative model to produce undirected, simple, connected graphs with a specified degrees and pattern of communities, while maintaining a graph structure that is as random as possible. additionally, we demonstrate two important applications of our model: to generate networks that can be used to benchmark existing and new algorithms for detecting communities in biological networks; and to generate null models to serve as random controls when investigating the impact of complex network features beyond the byproduct of degree and modularity in empirical biological networks.  our model allows for the systematic study of the presence of community structure and its impact on network function and dynamics. this process is a crucial step in unraveling the functional consequences of the structural properties of biological systems and uncovering the mechanisms that drive these systems. biological networkscommunity structurerandom graphsmodularitybenchmark graphs 