Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,54 @@
Random Modular Network Generator
================================
This is the source code used for the following paper:
# Random Modular Network Generator

Sah, Pratha*, Lisa O. Singh, Aaron Clauset, and Shweta Bansal. "Exploring community structure in biological networks with random graphs." BMC Bioinformatics 2014, 15:220. doi:10.1186/1471-2105-15-220
This is the source code used for the following paper:

Sah, Pratha\*, Lisa O. Singh, Aaron Clauset, and Shweta Bansal. "Exploring community structure in biological networks with random graphs." BMC Bioinformatics 2014, 15:220\. doi:10.1186/1471-2105-15-220

This Python script generates undirected, simple, connected graphs with a specified degrees and pattern of communities, while maintaining a graph structure that is as random as possible.

email: ps875@georgetown.edu, sb753@georgetown.edu

Please cite the paper above, if you use our code in any form or create a derivative work.

Sample Output Graph
================================
# Dependencies

![alt tag](https://github.com/prathasah/random-modular-network-generator/blob/master/Figure2.jpg)
* Python 3.8 or higher
* Networkx 3.3 or higher
* NumPy 1.24 or higher
* Matplotlib 3.7 or higher

Modular random graphs with network size = 150, 375 edges, 3 modules (or communities) of size, *s* = 50 and degree distribution is power law with modularity values of: a) *Q* = 0.1; b) *Q* = 0.3; and c) *Q* = 0.6.
You can install all dependencies using pip:
```bash
pip install -r requirements.txt
```

From Figure 2, Sah *et al.* (2014)
# Usage

Dependencies
================================
* [Python 2.7](http://python.org/)
* [Networkx 2.2](https://networkx.github.io/)
For a quick demo of the code, open the script "random\_modular\_generator\_variable\_modules.py" and scroll down to the _main_ function. Adjust the model parameters, degree distribution function and module size distribution function and run in terminal using the command:

Link to install Networkx can be found [here](https://networkx.github.io/). The generator also requires sequence_generator.py script which is provided.
```bash
python random_modular_generator_variable_modules.py
```

Usage
================================
# Sample Code

For a quick demo of the code, open the script "random_modular_generator_variable_modules.py" and scroll down to the *main* function. Adjust the model parameters, degree distribution function and module size distribution function and run in terminal using the command:
For users unfamiliar with Python, I have uploaded a sample code file (mock\_code.py) demonstrating how the graph generator can be imported and used in a script. The mock code can be run using the command:

`$ python random_modular_generator_variable_modules.py`
```bash
python mock_code.py
```

# Output

The code saves the adjacency matrix of the generated random modular graph under the filename 'adjacency\_matrix.txt'. The graph is also saved in a graphml format under the filename "random\_modular\_graph.graphml". The graphml file can be uploaded in Gephi (<http://gephi.github.io/>) for graph visualization. Note that Gephi currently does not have a layout plugin to visualize modular graphs. In the near future, I am planning to add a function in random-modular-network-generator.py code to assign each node a particular coordinate that allows easy visualization of modules (I have done this in Figure 2). Shoot us an email if you need this feature sooner than later.

Sample Code
================================
For users unfamiliar to Python, I have uploadeded a sample code file (mock_code.py) demonstrating how the graph generator can be imported and used in a script. The mock code can be run using the command
# Sample Output Graph

`$ python mock_code.py`
![alt tag](https://github.com/prathasah/random-modular-network-generator/blob/master/Figure2.jpg)

Modular random graphs with network size = 150, 375 edges, 3 modules (or communities) of size, *s* = 50 and degree distribution is power law with modularity values of: a) *Q* = 0.1; b) *Q* = 0.3; and c) *Q* = 0.6.

Output
================================
The code saves the the adjacency matrix of the generated random modular graph under the filename 'adjacency_matrix.txt'. The graph is also saved in a graphml format under the filename "random_modular_graph.graphml". The graphml file can be uploaded in Gephi (http://gephi.github.io/) for graph visualization. Note that Gephi currently does not have a layout plugin to visualize modular graphs. In the near future, I am planning to add a function in random-modular-network-generator.py code to assign each node a particular coordinate that allows easy visualization of modules (I have done this in Figure 2). Shoot us an email if you need this feature sooner than later.
From Figure 2, Sah *et al.* (2014)

=========

Expand Down
6 changes: 3 additions & 3 deletions mock_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

# generate the graph!

print "Generating a simple poisson random modular graph with modularity(Q)= " + str(Q)
print "Graph has " + str(N) + " nodes, " +str(m)+ " modules, and a network mean degree of " + str(d)
print "Generating graph....."
print("Generating a simple poisson random modular graph with modularity(Q)= " + str(Q))
print("Graph has " + str(N) + " nodes, " +str(m)+ " modules, and a network mean degree of " + str(d))
print("Generating graph.....")
G = rmg.generate_modular_networks(N, sfunction, modfunction, Q, m, d, verbose=True)
#nx.write_graphml(G, "random_modular_graph_Q"+str(Q)+"_N"+str(N)+"_d"+str(d)+"_m"+str(m)+".graphml")
nx.write_graphml(G, "random_graph_poisson_N"+str(N)+"_d"+str(d)+".graphml")
Loading