Becksteinlab / kda

Python package used for the analysis of biochemical kinetic diagrams.
GNU General Public License v3.0
3 stars 1 forks source link

kda.diagrams.generate_directional_partial_diagrams(return_edges=False) and kda.plotting.draw_diagrams() incompatibility #38

Closed nawtrey closed 2 years ago

nawtrey commented 2 years ago

At the moment the primary use case for generating the directional partial diagrams in NetworkX diagram for (instead of an array of edges) is to plot them using kda.plotting.draw_diagrams(), but kda.plotting.draw_diagrams() only draws many diagrams when a list of diagrams is input. This is an issue when running the following code:

dir_pars = kda.diagrams.generate_directional_partial_diagrams(G, return_edges=False)
kda.plotting.draw_diagrams(dir_pars)

because it raises the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-822cdbca70d2> in <module>
      1 # plotting.draw_diagrams(dir_pars, pos=pos, panel=True, panel_scale=1.5, cbt=True, rows=4, cols=8, font_size=font_size, path=PATH, label=dir_pars_label)
----> 2 plotting.draw_diagrams(dir_pars, pos=pos, panel=True, panel_scale=1.5, cbt=True, rows=4, cols=8, font_size=font_size)

c:\users\nikol\onedrive\phy495\kda\kda\plotting.py in draw_diagrams(diagrams, pos, panel, panel_scale, font_size, cbt, rows, cols, path, label)
    144         fig = plt.figure(figsize=(4, 4), tight_layout=True)
    145         ax = fig.add_subplot(111)
--> 146         node_list = list(G.nodes)
    147         node_size = 500
    148         nx.draw_networkx_nodes(

AttributeError: 'numpy.ndarray' object has no attribute 'nodes'

This is confusing because you expect to be able to feed the diagrams directly into the plotting function. There are basically 2 solutions for this:

  1. change kda.diagrams.generate_directional_partial_diagrams(return_edges=False) to return a list of diagrams instead of an array. This should be done in a consistent way in comparison to kda.diagrams.generate_partial_diagrams() so they can both be used effectively.
  2. change the way that kda.plotting.draw_diagrams() detects multiple diagrams (let it check for an array, for example).