using graphviz_layout...

1,187 views
Skip to first unread message

nickschurch

unread,
Feb 23, 2010, 8:24:52 AM2/23/10
to networkx-discuss
I'm having some problems getting graphvis layout to work on my data.
What I have is a bunch of connected GO term nodes so ideally I want a
tree-type network plot.

So, I have a networkx.classes.graph.Graph objects with nodes and edges
(nx). I have pydot and pygraphviz installed and available. I try to
get the positions for the nodes with the following commands:

>>> from networkx import graphviz_layout
>>> pos=nx.graphviz_layout(nw,prog="dot")

but this results in:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/networkx-1.1.dev-
py2.6.egg/networkx/drawing/nx_agraph.py", line 229, in graphviz_layout
return pygraphviz_layout(G,prog=prog,root=root,args=args)
File "/usr/local/lib/python2.6/site-packages/networkx-1.1.dev-
py2.6.egg/networkx/drawing/nx_agraph.py", line 260, in
pygraphviz_layout
A=to_agraph(G)
File "/usr/local/lib/python2.6/site-packages/networkx-1.1.dev-
py2.6.egg/networkx/drawing/nx_agraph.py", line 147, in to_agraph
A.add_node(n,**nodedata)
File "/usr/local/lib/python2.6/site-packages/pygraphviz-0.99.1-py2.6-
linux-i686.egg/pygraphviz/agraph.py", line 223, in add_node
node.attr.update(**attr)
File "/usr/local/lib/python2.6/UserDict.py", line 164, in update
self.update(kwargs)
File "/usr/local/lib/python2.6/UserDict.py", line 156, in update
self[k] = v
File "/usr/local/lib/python2.6/site-packages/pygraphviz-0.99.1-py2.6-
linux-i686.egg/pygraphviz/agraph.py", line 1586, in __setitem__
raise "Attribute value must be a string"
TypeError: exceptions must be classes or instances, not str

Am I doing something wrong here or is there something wrong with the
install?

Aric Hagberg

unread,
Feb 23, 2010, 12:32:26 PM2/23/10
to networkx...@googlegroups.com
On Tue, Feb 23, 2010 at 6:24 AM, nickschurch <nicks...@googlemail.com> wrote:
> I'm having some problems getting graphvis layout to work on my data.
> What I have is a bunch of connected GO term nodes so ideally I want a
> tree-type network plot.
>
>>>> from networkx import graphviz_layout
>>>> pos=nx.graphviz_layout(nw,prog="dot")
>
> but this results in:
>
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "/usr/local/lib/python2.6/site-packages/networkx-1.1.de>
> Am I doing something wrong here or is there something wrong with the
> install?
>

It might be a bug - we fixed some related bugs with
string attribute handling (e.g.
https://networkx.lanl.gov/trac/changeset/1485
)

Can you send the version information?
$ python -c "import networkx;print networkx.__version__"
$ python -c "import pygraphviz;print pygraphviz.__version__"


Aric

nickschurch

unread,
Feb 24, 2010, 9:01:32 AM2/24/10
to networkx-discuss
Hi Aric - here is the info:

> python -c "import networkx;print networkx.__version__"

1.1.dev1519


> python -c "import pygraphviz;print pygraphviz.__version__"

0.99.1

Its weird, because I can run the circular tree example, which uses
graphviz for its layout, with no problem.

On Feb 23, 5:32 pm, Aric Hagberg <ahagb...@gmail.com> wrote:


> On Tue, Feb 23, 2010 at 6:24 AM, nickschurch <nickschu...@googlemail.com> wrote:
> > I'm having some problems getting graphvis layout to work on my data.
> > What I have is a bunch of connected GO term nodes so ideally I want a
> > tree-type network plot.
>
> >>>> from networkx import graphviz_layout
> >>>> pos=nx.graphviz_layout(nw,prog="dot")
>
> > but this results in:
>
> > Traceback (most recent call last):
> >  File "<stdin>", line 1, in <module>
> >  File "/usr/local/lib/python2.6/site-packages/networkx-1.1.de>
> > Am I doing something wrong here or is there something wrong with the
> > install?
>
> It might be a bug - we fixed some related bugs with

> string attribute handling (e.g.https://networkx.lanl.gov/trac/changeset/1485

nickschurch

unread,
Feb 24, 2010, 9:08:33 AM2/24/10
to networkx-discuss
Interesting, I just tried the circulat tree layout (twopi) on my data
and it falls over with exactly the same error.

Aric Hagberg

unread,
Feb 24, 2010, 9:10:35 AM2/24/10
to networkx...@googlegroups.com
On Wed, Feb 24, 2010 at 7:01 AM, nickschurch <nicks...@googlemail.com> wrote:
> Hi Aric - here is the info:
>
>> python -c "import networkx;print networkx.__version__"
> 1.1.dev1519
>> python -c "import pygraphviz;print pygraphviz.__version__"
> 0.99.1
>
> Its weird, because I can run the circular tree example, which uses
> graphviz for its layout, with no problem.

Try updating to the dev version of PyGraphviz.
http://networkx.lanl.gov/download/pygraphviz/

If that doesn't fix it could you send a small example that
shows the problem?

Aric

nickschurch

unread,
Feb 24, 2010, 10:14:07 AM2/24/10
to networkx-discuss
OK, I've upgraded my pygraphviz and I'm now getting something a bit
different....

--------------------------
>>> import networkx as nx


>>> from networkx import graphviz_layout
>>> pos=nx.graphviz_layout(nw,prog="dot")

Warning: graph has 4859 nodes...layout may take a long time.
/usr/local/lib/python2.6/site-packages/pygraphviz-1.0.dev-py2.6-linux-
i686.egg/pygraphviz/agraph.py:1168: RuntimeWarning: Error:
gvwrite_no_z problem 18484

warnings.warn("".join(errors),RuntimeWarning)
Warning: syntax error in line 124 near ''
Segmentation fault
------------------------------

I guess I can put up a file or two as an example of the error...

On Feb 24, 2:10 pm, Aric Hagberg <ahagb...@gmail.com> wrote:


> On Wed, Feb 24, 2010 at 7:01 AM, nickschurch <nickschu...@googlemail.com> wrote:
> > Hi Aric - here is the info:
>
> >> python -c "import networkx;print networkx.__version__"
> > 1.1.dev1519
> >> python -c "import pygraphviz;print pygraphviz.__version__"
> > 0.99.1
>
> > Its weird, because I can run the circular tree example, which uses
> > graphviz for its layout, with no problem.
>

> Try updating to the dev version of PyGraphviz.http://networkx.lanl.gov/download/pygraphviz/

Aric Hagberg

unread,
Feb 24, 2010, 11:18:29 AM2/24/10
to networkx...@googlegroups.com
On Wed, Feb 24, 2010 at 8:14 AM, nickschurch <nicks...@googlemail.com> wrote:
> OK, I've upgraded my pygraphviz and I'm now getting something a bit
> different....
>
> --------------------------
>>>> import networkx as nx
>>>> from networkx import graphviz_layout
>>>> pos=nx.graphviz_layout(nw,prog="dot")
> Warning: graph has 4859 nodes...layout may take a long time.
> /usr/local/lib/python2.6/site-packages/pygraphviz-1.0.dev-py2.6-linux-
> i686.egg/pygraphviz/agraph.py:1168: RuntimeWarning: Error:
> gvwrite_no_z problem 18484
>
>  warnings.warn("".join(errors),RuntimeWarning)
> Warning:  syntax error in line 124 near ''
> Segmentation fault
> ------------------------------

Do the tests run OK?
>>> import pygraphviz
>>> pygraphviz.test()

Aric

nickschurch

unread,
Feb 24, 2010, 11:57:31 AM2/24/10
to networkx-discuss
I think its actually to do with the metadata storred in the graph
object. The network I'm looking at is a bunch of enriched GO terms.
I've added the id of each gene that maps to a given GO term as an
attribute of the node...#

i.e. for each node, i do: nw.add_node(node,genes=geneids)

When I try

>>> pos=nx.graphviz_layout(nw,prog="dot")

I get a segfault, but when I define a new object and addthe nodes and
edges contained within nw, its no problem!

>>> GD=nx.DiGraph()
>>> GD.add_nodes_from(nw.nodes())
>>> GD.add_edges_from(nw.edges())
>>> pos=nx.graphviz_layout(DG,prog="dot")


Warning: graph has 4859 nodes...layout may take a long time.

>>> nx.draw(DG, pos)

So the only thing I can think is that the additional info on the nodes
is causing the problem....

nickschurch

unread,
Feb 24, 2010, 11:58:22 AM2/24/10
to networkx-discuss
tests run OK.

On Feb 24, 4:18 pm, Aric Hagberg <ahagb...@gmail.com> wrote:

Christopher Ellison

unread,
Feb 24, 2010, 1:39:35 PM2/24/10
to networkx...@googlegroups.com
nickschurch wrote the following on 02/24/2010 08:57 AM:
>
> So the only thing I can think is that the additional info on the nodes
> is causing the problem....
>

I'm glad you were able to track down the source of your problem.
However, had you posted a minimal example which produced the error, I
think diagnosis would have been much simpler (and quicker).

Strictly for informational purposes, what was an example of a
problematic geneid (that maps to a given GO term)?

Chris

nickschurch

unread,
Feb 25, 2010, 5:15:05 AM2/25/10
to networkx-discuss
> I'm glad you were able to track down the source of your problem.
> However, had you posted a minimal example which produced the error, I
> think diagnosis would have been much simpler (and quicker).

I understand, and it was in the process of putting together a minimal
example that I found the problem! I still don't know why it causes the
problem though, since the manual suggests you can attach any arbitrary
information as a node attribute. I didn't post the full code initially
because is part of a large code (which actually makes it kind of hard
to distil into a minimal example I found) and the data that it
operates on is not my own, and I thus I have to treat as confidential.

> Strictly for informational purposes, what was an example of a
> problematic geneid (that maps to a given GO term)?

The geneids are Entrez ID in a list - so an example of the gene ids
for a given GO term would be:

geneids=['100134991','443540','744399']

Could it be a problem that the attribute is not a single entity but a
list?

Nick

Christopher Ellison

unread,
Feb 25, 2010, 10:38:12 PM2/25/10
to networkx...@googlegroups.com
nickschurch wrote the following on 02/25/2010 02:15 AM:
> The geneids are Entrez ID in a list - so an example of the gene ids
> for a given GO term would be:
>
> geneids=['100134991','443540','744399']
>
> Could it be a problem that the attribute is not a single entity but a
> list?
>

In principle, NetworkX can definitely handle that kind of node data. If
you are able to get a minimal example, post it online. You should be
able to reduce it and reduce it...and even change the data so as to keep
confidentiality.

In [1]: import networkx as nx

In [2]: g = nx.Graph()

In [3]: g.add_node('A', genes=['100134991','443540','744399'])

In [4]: g.node
Out[4]: {'A': {'genes': ['100134991', '443540', '744399']}}

Chris

nickschurch

unread,
Feb 26, 2010, 8:42:02 AM2/26/10
to networkx-discuss
hmmm, in my exuberance I've deleted the code that added the gene
annotation data. the simeple example you put on your email works fine
for me (and for you, clearly) so I thinks its something more tricky
than that. I'll see if I can reproduce it again...

On Feb 26, 3:38 am, Christopher Ellison <celli...@cse.ucdavis.edu>
wrote:

nickschurch

unread,
Mar 3, 2010, 5:49:12 AM3/3/10
to networkx-discuss
OK, I've uploaded a cPickel file to the files section
(savenet_temp.pkl.gz) that will provide a simple example of the
problem. The file contains two network x graph objects with identical
nodes and edges, but in one case the nodes have metadata, in the other
they don't. The metadata is a list exactly as described previously.

Download file a gunzip it. Then, in python:

>>> # load data
>>> import cPickle
>>> file=open("savenet_temp.pkl","r")
>>> datastore=cPickle.load(file)
>>> file.close()
>>>
>>> # import networkx stuff


>>> import networkx as nx
>>> from networkx import graphviz_layout
>>>

>>> # calculate positions for graph without metadata <- this should work no problem!
>>> pos=nx.graphviz_layout(datastore["without_metadata"],prog="dot")
>>> pos
[output] (something like....)

{'GO:0032774': (906.0, 162.0), 'GO:0019222': (529.0, 450.0), 'GO:
0016310': (1506.0, 90.0), 'GO:0031323': (384.0, 378.0), 'GO:0044249':
(853.0, 378.0), 'GO:0045449': (605.0, 90.0), 'GO:0007165': (240.0,
378.0), 'GO:0034645': (1038.0, 306.0), 'GO:0009799': (80.0, 378.0),
'GO:0043170': (1067.0, 450.0), 'GO:0007275': (178.0, 522.0), 'GO:
0006139': (856.0, 306.0), 'GO:0044260': (1139.0, 378.0), 'GO:0007368':
(64.0, 234.0), 'GO:0050789': (529.0, 522.0), 'GO:0019219': (673.0,
234.0), 'GO:0010467': (1282.0, 378.0), 'GO:0009855': (64.0, 306.0),
'GO:0065007': (529.0, 594.0), 'GO:0031326': (387.0, 306.0), 'GO:
0034960': (1323.0, 306.0), 'GO:0034961': (1129.0, 234.0), 'GO:
0043284': (1180.0, 306.0), 'GO:0032502': (168.0, 594.0), 'GO:0006468':
(1578.0, 18.0), 'GO:0032501': (310.0, 594.0), 'GO:0044267': (1600.0,
234.0), 'GO:0060255': (673.0, 378.0), 'GO:0043687': (1651.0, 90.0),
'GO:0009987': (384.0, 522.0), 'GO:0009889': (529.0, 378.0), 'GO:
0006464': (1651.0, 162.0), 'GO:0050794': (384.0, 450.0), 'GO:0007389':
(88.0, 450.0), 'GO:0009058': (710.0, 450.0), 'GO:0009059': (996.0,
378.0), 'GO:0008150': (419.0, 666.0), 'GO:0008152': (781.0, 522.0),
'GO:0007154': (241.0, 450.0), 'GO:0043283': (1713.0, 378.0), 'GO:
0016070': (856.0, 234.0), 'GO:0044238': (1571.0, 378.0), 'GO:0007242':
(206.0, 306.0), 'GO:0019538': (1651.0, 306.0), 'GO:0051252': (764.0,
162.0), 'GO:0043412': (1742.0, 234.0), 'GO:0044237': (853.0, 450.0),
'GO:0010468': (673.0, 306.0), 'GO:0006355': (764.0, 18.0), 'GO:
0006796': (1506.0, 306.0), 'GO:0010556': (530.0, 306.0), 'GO:0006350':
(1049.0, 162.0), 'GO:0006351': (906.0, 90.0), 'GO:0006793': (1427.0,
378.0)}

>>> # calculate positions for graph with metadata <- this should segfault.
>>> pos=nx.graphviz_layout(datastore["with_metadata"],prog="dot")
[output]

Warning: syntax error in line 233 near ''
Segmentation fault

Christopher Ellison

unread,
Mar 3, 2010, 1:43:22 PM3/3/10
to networkx...@googlegroups.com
nickschurch wrote the following on 03/03/2010 02:49 AM:
> OK, I've uploaded a cPickel file to the files section
> (savenet_temp.pkl.gz) that will provide a simple example of the
> problem. The file contains two network x graph objects with identical
> nodes and edges, but in one case the nodes have metadata, in the other
> they don't. The metadata is a list exactly as described previously.
>
>>>> # calculate positions for graph with metadata <- this should segfault.
>>>> pos=nx.graphviz_layout(datastore["with_metadata"],prog="dot")
> [output]
>
> Warning: syntax error in line 233 near ''
> Segmentation fault
>

Hi Nick,

Thanks for uploading the example. I was able to run your example on
both graphs without issue. So perhaps there is some difference in the
versions of the software we are running. It would be nice to get a
second confirmation from another user on the list too.

Here is what I have:

$ python -c "import networkx as nx; print nx.__version__"
1.1.dev1519

$ python -c "import pygraphviz as p; print p.__version__"
1.0.dev1519

$ dot -V
dot - Graphviz version 2.20.2 (Wed Sep 16 11:12:11 UTC 2009)


Chris

nickschurch

unread,
Mar 4, 2010, 5:14:12 AM3/4/10
to networkx-discuss
I think there are some differences: I have:

$ python -c "import networkx as nx; print nx.__version__"
1.1.dev1519

$ python -c "import pygraphviz as p; print p.__version__"
1.0.dev

$ dot -V
dot - graphviz version 2.22.0 (20090304.0156)

I'm not quite sure why my version of pygraphviz doesn't show a number
after the dev declaration - the package I updated from was
pygraphviz-1.0.dev1521 which is a small increment up from yours
(although I note there is a 1529 on the website now) - could this be
making the difference?. My dot install seems marginally newer too, but
given that its functionality has been aroudn for a while I don't
imagine this is the problem.

Nick


On Mar 3, 6:43 pm, Christopher Ellison <celli...@cse.ucdavis.edu>
wrote:

franck kalala

unread,
Mar 5, 2010, 7:07:53 AM3/5/10
to networkx...@googlegroups.com
Hey All,

I have an edgelist see attached file. This edgelist has a third column which the diagonal of the adjacency matrix.
Is possible to read this edgefile with a routine in NetworkX.

Cheers



nickschurch

unread,
Mar 8, 2010, 4:40:03 AM3/8/10
to networkx-discuss
*bump*

Just thought I'd bump this back up the list to see if we can find a
solution....

Aric Hagberg

unread,
Mar 8, 2010, 10:49:07 AM3/8/10
to networkx...@googlegroups.com
On Mon, Mar 8, 2010 at 2:40 AM, nickschurch <nicks...@googlemail.com> wrote:
> *bump*
>
> Just thought I'd bump this back up the list to see if we can find a
> solution....

I tried to load your files but apparently you are using numpy
objects in your data and I don't have the same version of numpy
as you do (or some other related problem).

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.


>>> import cPickle
>>> file=open("savenet_temp.pkl","r")
>>> datastore=cPickle.load(file)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>

ValueError: can't handle version -1 of numpy.dtype pickle

Aric

nickschurch

unread,
Mar 9, 2010, 6:58:06 AM3/9/10
to networkx-discuss
That is very strange - there are no numpy objects in the pickl'd file.
The file just contains a dictionary of two networkX DiGraph objects.
The graphs only have a nodes and edges added and both nodes and edges
have the type 'list' - the additional metedata in the nodes is stored
with each node as a tuple, with the metadata (the second entry in each
tuple) as a dictionary. The actual data stored in the dictionary is a
list. So there should be no numpy bits anywhere! Could it be a problem
with cPickle?

On 8 Mar, 15:49, Aric Hagberg <ahagb...@gmail.com> wrote:

nickschurch

unread,
Mar 9, 2010, 7:00:10 AM3/9/10
to networkx-discuss
Ahhh, hang on, the values in the list have the type 'numpy.string_'
cos they are pulled from a numpy array. I guess thats the problem. Are
you loading numpy first, and if you do does it work?

Aric Hagberg

unread,
Mar 9, 2010, 7:17:54 AM3/9/10
to networkx...@googlegroups.com
On Tue, Mar 9, 2010 at 5:00 AM, nickschurch <nicks...@googlemail.com> wrote:
> Ahhh, hang on, the values in the list have the type 'numpy.string_'
> cos they are pulled from a numpy array. I guess thats the problem. Are
> you loading numpy first, and if you do does it work?

It doesn't matter if you load numpy first. I have numpy-1.3.0.

If it is possible to make a very small (text) example to show the problem
that would help.

Aric

chen fred

unread,
Mar 10, 2010, 6:51:04 AM3/10/10
to networkx...@googlegroups.com
Hi,

I am new comer. Please let me know best online tutorial of Python
that easy to follow for beginners like me.

Cheers,

Fred


Hotmail: Free, trusted and rich email service. Get it now.

chen fred

unread,
Mar 10, 2010, 6:51:24 AM3/10/10
to networkx...@googlegroups.com

Dheeraj M R

unread,
Mar 10, 2010, 8:08:11 AM3/10/10
to networkx-discuss
On Wed, Mar 10, 2010 at 5:21 PM, chen fred <chan...@live.com> wrote:
> Hi,
>
> I am new comer. Please let me know best online tutorial of Python
> that easy to follow for beginners like me.

http://software-carpentry.org/

>
> Cheers,
>
> Fred
>
> ________________________________
> Hotmail: Free, trusted and rich email service. Get it now.
>

> --
> You received this message because you are subscribed to the Google Groups
> "networkx-discuss" group.
> To post to this group, send email to networkx...@googlegroups.com.
> To unsubscribe from this group, send email to
> networkx-discu...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/networkx-discuss?hl=en.
>

--
What I want is muscles of iron and nerves of steel, inside which
dwells a mind of the same material as that of which the thunderbolt is
made

franck kalala

unread,
Mar 10, 2010, 8:19:14 AM3/10/10
to networkx...@googlegroups.com
http://www.python.org/doc/2.5.2/tut/tut.html


De : chen fred <chan...@live.com>
À : networkx...@googlegroups.com
Envoyé le : Mer 10 Mars 2010, 11 h 51 min 24 s
Objet : [networkx-discuss] Ask: Online Tutorial
--

Andrew Conway

unread,
Mar 10, 2010, 9:16:22 AM3/10/10
to networkx...@googlegroups.com
Fred,

There are several good online tutorials, in addition to the official one Franck suggested.

Dive Into Python (http://diveintopython.org/) and Python Rocks (http://personalpages.tds.net/~kent37/stories/00020.html) are both very thorough tutorials on the language.

That said, I often find the best way to learn is through example, and if you are learning Python to use NetworkX I highly recommend looking over the examples contained in the package source, the most up-to-date of which can be found here: https://networkx.lanl.gov/trac/browser/networkx/trunk/examples

Good luck!


- Drew

-- 

You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.


___________________________________
Drew Conway
Ph.D. Student
Department of Politics, New York University
@drewconway

Reply all
Reply to author
Forward
0 new messages