jcrozum / pystablemotifs

Python library for attractor identification and control in Boolean networks
MIT License
28 stars 7 forks source link

Generate figures #86

Closed priyambial123 closed 2 years ago

priyambial123 commented 2 years ago

Hello

I need some help with generated figures showing attractors. Name of the nodes are not complete in the right side of the figure and the node names are overlapping. Is there a way to adjust the figure settings

Used the below code to generate figures:

import pystablemotifs as sm
import pyboolnet
import pystablemotifs.export as ex
import networkx as nx
import matplotlib.pyplot as plt

relative_path_to_model = r'''D:\Users\Labor\attractors\prenatal_clusters\attractors\cluster2_1_simulations\simulation4.txt'''
primes = sm.format.import_primes(relative_path_to_model)

print("RULES")
sm.format.pretty_print_prime_rules(primes)
print()

ar = sm.AttractorRepertoire.from_primes(primes)
ar.summary()

GR=sm.export.networkx_succession_diagram(ar,include_attractors_in_diagram=True)
sm.export.plot_nx_succession_diagram(GR,nx_node_label_kwargs={'font_size':10})
ar.succession_diagram.get_motifs()

Please find the attached figures Figure_1_sim1 Figure_1_sim2

Thanks

jcrozum commented 2 years ago

The function you used allows you to pass arguments to the networkx drawing algorithm via the nx_node_kwargs argument. Please refer to the networkx documentation for details.

Alternatively, you can export the networks to a yEd-readable graphml format, and tweak the layout and so on in yEd, which is a GUI application. This is described in more detail in one of the tutorial notebooks.

jcrozum commented 2 years ago

See also the documentation for plot_nx_succession_diagram for further description of what arguments can be passed to networkx when plotting.

priyambial123 commented 2 years ago

Thank you. I tried several times and it is hard to see all the attractor states with their node names in the figure. I could bring all the node names in one frame by decreasing the node font size. But, no more the font is visible. Is there a way to capture all the nodes and their names clearly in one figure. When I save it in graphml format and open in yED, the lay out changes and node names given their large size is hard to see in the yED window.

I could also find in one of the tutorials to plot state transition graph. Does STG shows the states transitioned to reach the final attractor state?. Can this STG figure be broken down to steps to understand the state transitions?

This is the change in code I used to create figure, all the node names can be captured

GR=sm.export.networkx_succession_diagram(ar,include_attractors_in_diagram=True)
sm.export.plot_nx_succession_diagram(GR,fig_dimensions=(None, None),nx_node_kwargs= {'node_size':10*GR.number_of_nodes()},nx_edge_kwargs={'arrowstyle':'-|>','width':1,'arrowsize':1}, nx_node_label_kwargs={'font_size':3})

Figure created from above code
![succ_fig_1](https://user-images.githubusercontent.com/11889537/180620419-42ef6805-e015-4c35-a4d5-9bc24bf3e699.png)

Code to create STG

G=pyboolnet.state_transition_graphs.primes2stg(primes,'asynchronous')##in-depth states
H=nx.DiGraph()
for u,v in G.edges():
    H.add_edge(u,v)
for n in H.nodes():
    H.nodes[n]["label"]=n
nx.write_graphml(H,"Fig3STG.graphml")
print("done.")

Thanks

priyambial123 commented 2 years ago

I can change the figure size or the font size, but I am not sure how to push the node names to the left side so that the node names don't get cut out as shown in the attached figure Figure_1_cluster1

jcrozum commented 2 years ago

The plotting utilities included in pystablemotifs are "quick and dirty". If you want fine-grained control over plotting, you should use the pystablemotifs.export.networkx_succession_diagram to generate a networkx digraph. This can then be plotted by exporting to a program like yEd or by using the built-in plotting tools for networkx.

To use yEd for plotting these graphs, you will need to have yEd generate a new layout, and you may need to use its property mapper utility (Edit -> Properties Mapper...) to get the node labels to display.

Because this issue thread is not the appropriate forum for discussing how to use these external tools, I am closing this issue. For further assistance, I recommend looking at the networkx documentation or asking around on a forum such as stackoverflow.