Network Base Class
Bases: object
This baseclass allows one to generate a regulatory network as a graph using a procedural construction algorithm, or from user-input edges. It can then perform analysis on the resulting graph to determine cycles, input and output degree distributions, hierarchical attributes, and other characteristics. The baseclass comes equipt with various visualization methods to plot network degree distributions and visualize state heatmaps.
Attributes:
Name | Type | Description |
---|---|---|
N_edges |
int
|
Total number of edges in the regulatory network. |
N_nodes |
int
|
Total number of nodes in the regulatory network. |
edges_list |
list[tuples]
|
List of the edges as tuples containing node names. |
nodes_list |
list
|
List of the nodes by numerical node index. |
edges_index |
list
|
List of the edges as edge indices. |
nodes_index |
list
|
List of the nodes by node name. |
GG |
DiGraph
|
The regulatory network graph as a networkx.DiGraph object. |
selfloop_edge_inds |
list
|
The edge indices that are self-loops (i.e. node A --> node A). |
in_degree_sequence |
list
|
The in-degree sequence of nodes, arranged according to node index order. |
out_degree_sequence |
list
|
The out-degree sequence of nodes, arranged according to node index order. |
in_dmax |
int
|
The maximum in-degree of the regulatory network. |
out_dmax |
int
|
The maximum out-degree of the regulatory network. |
node_divergence |
list
|
The divergence of each node, as the difference between in- and out- degree. |
in_bins |
list
|
Bins used to count of how many nodes have each binned in-degree (used to plot degree distribution histograms). |
in_degree_counts |
list
|
A count of how many nodes have each in-degree bin (used to plot degree distribution histograms). |
out_bins |
list
|
Bins used to count of how many nodes have each binned out-degree (used to plot degree distribution histograms). |
out_degree_counts |
list
|
A count of how many nodes have each out-degree bin (used to plot degree distribution histograms). |
nodes_by_out_degree |
list
|
Nodes arranged according to the number of outputs (out degree). |
nodes_by_in_degree |
list
|
Nodes arranged according to the number of inputs (in degree). |
graph_cycles |
list(tuple)
|
Cycles of the regulatory network, as defined by network nodes. |
N_cycles |
int
|
Number of simple cycles detected in the regulatory network. |
nodes_in_cycles |
list
|
Nodes of the regulatory network that do participate in cycles. |
nodes_acyclic |
list
|
Nodes of the regulatory network that do not participate in cycles. |
hier_node_level |
list
|
Overall hierarchical node levels of the graph (this is akin to a y-coordinate for each node of the network). |
dem_coeff |
float
|
The democracy coefficient parameter, measuring how much the influencers of a graph are influenced themselves. |
hier_incoherence |
float
|
The hierarchical incoherence parameter, measuring how much feedback there is in the network, with higher levels indicating more feedback, and lower levels indicating more hierarchy. |
input_node_inds |
list[int]
|
These are nodes with zero in degree, which represent the input nodes of the regulatory network. |
output_node_inds |
list[int]
|
These are nodes with zero out degree, which represent output nodes and potential effectors. |
main_nodes |
list[int]
|
The main nodes of the regulatory network, which are nodes that are neither input nor output nodes (these are the internal nodes). |
sensor_node_inds |
list[int]
|
User-defined nodes with NodeType.sensor node types. |
process_node_inds |
list[int]
|
User-defined nodes with NodeType.process node types. |
noninput_node_inds |
list[int]
|
Nodes of the network excluding the input nodes, but still representing internal and output nodes. |
factor_node_inds |
list[int]
|
User-defined nodes with NodeType.factor node types. |
Source code in cellnition/science/network_models/network_abc.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
|
__init__()
Initialize the class to begin building and characterizing a regulatory network graph.
Source code in cellnition/science/network_models/network_abc.py
101 102 103 104 105 |
|
build_network_from_edges(edges)
Use a list of tuples defining directed edges between nodes to build a regulatory network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges
|
list[tuple]
|
List with tuples defining each directed edge in the regulatory network as passing from the first to second node in the tuple. |
required |
Source code in cellnition/science/network_models/network_abc.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
characterize_graph(count_cycles=True, cycle_length_bound=None)
Perform a number of graph-theory style characterizations on the network to determine cycle number, analyze in- and out- degree distribution, and analyze hierarchy. Hierarchical structure analysis was from the work of Moutsinas, G. et al. Scientific Reports 11 (2021).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count_cycles
|
bool
|
Do you wish to perform a cycle count of the network (True)? Some regulatory networks have very high numbers of cycles and in this case the cycle count can consume all the memory and should therefore be disabled. |
True
|
cycle_length_bound
|
int | None
|
Specify an upper bound for the length of a cycle in a network in terms of node number (e.g. 12). For networks with large cycle numbers, specifying an upper bound can prevent the extreme counts that would otherwise be produced. |
None
|
Source code in cellnition/science/network_models/network_abc.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
edges_from_path(path_nodes)
If specifying a path in terms of a set of nodes, this method returns the set of edges corresponding to the path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_nodes
|
list
|
A list of nodes in the network over which the path is specified. |
required |
Returns:
Type | Description |
---|---|
list
|
The list of edges corresponding to the path. |
Source code in cellnition/science/network_models/network_abc.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
|
get_edge_types(p_acti=0.5, set_selfloops_acti=True)
Automatically generate a list of EdgeType for use in model building. The edge type specifies whether the edge is an activating or inhibiting relationship between the nodes. This routine randomly chooses a set of activating and inhibiting edge types for a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p_acti
|
float
|
The probability of an edge type being an activator. Note that this value must be less than 1.0, and that the probability of an edge being an inhibitor becomes 1.0 - p_acti. |
0.5
|
set_selfloops_acti
|
bool
|
Work shows that, in general, self-inhibition does not generate models with multistable states. Therefore, this edge-type assignment routine allows one to automatically set all self-loops to be activation interactions. |
True
|
Returns:
Type | Description |
---|---|
list
|
A list containing an EdgeType enum for every edge in the network. |
Source code in cellnition/science/network_models/network_abc.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
get_paths_matrix()
Compute a matrix showing the number of paths from starting node to end node. Note that this matrix can be extraordinarily large in a complicated graph such as most binomial networks.
Returns:
Type | Description |
---|---|
ndarray
|
The paths matrix, which specifies the number of paths between one node index as row index and another node index as the column index. |
Source code in cellnition/science/network_models/network_abc.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
plot_degree_distributions()
Generate a plot of the in- and out- degree distributions of the network as histograms. Requires self.characterize_graph() to have been run previously.
Returns:
Name | Type | Description |
---|---|---|
fig |
figure
|
|
ax |
axes
|
|
Source code in cellnition/science/network_models/network_abc.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
|
plot_pixel_matrix(solsM, x_labels, y_labels, figsave=None, cmap=None, cbar_label='', figsize=(10, 10), fontsize=16)
Plot a matrix of values as a heatmap.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
solsM
|
ndarray
|
The matrix of values to plot as a heatmap. |
required |
x_labels
|
list | ndarray | None
|
Labels to apply to each column of the solsM matrix, along the horizontal axis. |
required |
y_labels
|
list | ndarray | None
|
Labels to apply to each row of the solsM matrix, along the vertical axis. |
required |
figsave
|
str | None
|
The full directory and filename to write the image file to. If None, no image will be save to disk. Only 'png' images can be exported. |
None
|
cmap
|
str | None
|
The matplotlib colormap to use for the image. |
None
|
cbar_label
|
str
|
The text label to write along the image colorbar. |
''
|
figsize
|
tuple
|
The size of the figure. |
(10,10)
|
Returns:
Name | Type | Description |
---|---|---|
fig |
figure
|
|
ax |
axes
|
|
Source code in cellnition/science/network_models/network_abc.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
|
plot_sols_array(solsM, gene_inds=None, figsave=None, cmap=None, save_format='png', figsize=(10, 10))
Create and save a heatmap image representing a matrix of states for the regulatory network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
solsM
|
ndarray
|
The matrix of regulatory network states, with each state being a coloumn of the matrix and each row representing the expression level of a node in the network. |
required |
gene_inds
|
list | ndarray | None
|
A subset of the total nodes of the network that are to be displayed in the visualized heatmap. |
None
|
figsave
|
str | None
|
The full directory and filename to write the image file to. If None, no image will be save to disk. |
None
|
cmap
|
str | None
|
The matplotlib colormap to use for the image. |
None
|
save_format
|
str
|
The file format to save the image in ('svg' or 'png'). |
'png'
|
figsize
|
tuple
|
The size of the figure. |
(10,10)
|
Returns:
Name | Type | Description |
---|---|---|
fig |
figure
|
|
ax |
axes
|
|
Source code in cellnition/science/network_models/network_abc.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
|
randomly_generate_special_network(N_nodes, b_param=0.15, g_param=0.8, delta_in=0.0, delta_out=0.0, p_edge=0.5, graph_type=GraphType.scale_free)
Procedurally generate a network with a scale-free or binomial (random) degree distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N_nodes
|
int
|
The number of nodes to build the network (only used in randomly built networks, otherwise the number of nodes is calculated from the number of unique nodes supplied in the edges list). |
required |
graph_type
|
GraphType = GraphType.scale_free
|
The type of graph to generate in randomly-constructed networks. |
scale_free
|
b_param
|
float = 0.20
|
For scale-free randomly-constructed networks, this determines the amount of interconnectivity between the in and out degree distributions, and in practical terms, increases the number of cycles in the graph. Note that 1 - beta - gamma must be greater than 0.0. |
0.15
|
g_param
|
float=0.75
|
For scale-free randomly-constructed networks, this determines the emphasis on the network's out degree distribution, and in practical terms, increases the scale-free character of the out-distribution of the graph. Note that 1 - beta - gamma must be greater than 0.0. |
0.8
|
delta_in
|
float=0.0
|
A parameter that increases the complexity of the network core, leading to more nodes being involved in cycles. |
0.0
|
delta_out
|
float = 0.0
|
A parameter that increases the complexity of the network core, leading to more nodes being involved in cycles. |
0.0
|
p_edge
|
float=0.2
|
For randomly constructed binomial-type networks, this parameter determines the probability of forming an edge. As p_edge increases, the number of network edges increases dramatically. |
0.5
|
Source code in cellnition/science/network_models/network_abc.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
save_network(filename)
Write a network, including edge types, to a saved file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The full directory and filename to write the graph file to as a gml format graph. |
required |
Source code in cellnition/science/network_models/network_abc.py
577 578 579 580 581 582 583 584 585 586 587 |
|
save_network_image(save_filename, use_dot_layout=False)
Uses pygraphviz to create a basic plot of the network model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_filename
|
str
|
The full directory and filename to write the graph image file to. If the filename ends with '.png' the image will be a raster image, if it ends with '.svg' it will be a vector graphics file. |
required |
use_dot_layout
|
bool
|
Use the 'dot' layout to build the graph. |
false
|
Source code in cellnition/science/network_models/network_abc.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
|
set_edge_types(edge_types)
Assign a list EdgeType to edges of the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_types
|
list | ndarray
|
A list of edge type enumerations; one for each edge of the network. |
required |
Source code in cellnition/science/network_models/network_abc.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
set_node_types(node_type_dict=None, pure_gene_edges_only=False)
Assign a dictionary of NodeType to nodes of the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_type_dict
|
dict | None
|
A list of node type enumerations for each node of the network. |
None
|
pure_gene_edges_only
|
bool
|
Classify multiple non-process NodeType as "genes" (True) or only NodeType.gene (False). |
False
|
Source code in cellnition/science/network_models/network_abc.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
|