scverse / scverse/scanpy

Exporting a PAGA to gexf format: AttributeError: 'Graph' object has no attribute 'node'

Open
#1,997 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.6k
Forks
779
Avg merge
1d 4h
Merged PRs (30d)
27

Description

Hi, I'm having trouble exporting a PAGA graph as gexf format. I did a manual fix in my own installation of scanpy but it seems like a version issue with networkx2.6.2 (which is the latest of this date).
Minimal working example:

import scanpy as sc
paul15 = sc.datasets.paul15()
sc.pp.recipe_zheng17(paul15)
sc.pp.neighbors(paul15, n_neighbors=4, n_pcs=20)
sc.tl.paga(paul15, groups='paul15_clusters')
sc.pl.paga(paul15, labels=None, color='paul15_clusters')

gexf=sc.pl.paga(paul15, labels=None, color='paul15_clusters', export_to_gexf=True)


  File "anaconda3\lib\site-packages\scanpy\plotting\_tools\paga.py", line 860, in _paga_graph
    nx_g_solid.node[count]['label'] = str(node_labels[count])

AttributeError: 'Graph' object has no attribute 'node'```

Versions

scanpy 1.8.1
networkx 2.6.2
matplotlib 3.4.3

sc.logging.print_versions()
WARNING: If you miss a compact list, please try print_header!

anndata 0.7.6
scanpy 1.8.1
sinfo 0.3.1

PIL 8.0.1
PyQt5 NA
anndata 0.7.6
autoreload NA
backcall 0.2.0
bottleneck 1.3.2
bs4 4.9.3
cairo 1.20.1
cffi 1.14.3
chardet 3.0.4
cloudpickle 1.6.0
colorama 0.4.4
cycler 0.10.0
cython_runtime NA
cytoolz 0.11.0
dask 2.30.0
dateutil 2.8.1
decorator 4.4.2
h5py 2.10.0
html5lib 1.1
igraph 0.9.6
ipykernel 5.3.4
ipython_genutils 0.2.0
jedi 0.17.1
joblib 1.0.1
kiwisolver 1.3.0
leidenalg 0.8.7
llvmlite 0.34.0
lxml 4.6.1
matplotlib 3.4.3
mpl_toolkits NA
natsort 7.1.1
networkx 2.6.2
nt NA
ntsecuritycon NA
numba 0.51.2
numexpr 2.7.1
numpy 1.20.3
packaging 20.4
pandas 1.3.2
parso 0.7.0
pickleshare 0.7.5
pkg_resources NA
prompt_toolkit 3.0.8
psutil 5.7.2
pyarrow 0.16.0
pycparser 2.20
pygments 2.7.2
pynndescent 0.5.2
pyparsing 2.4.7
pythoncom NA
pytz 2020.1
pywintypes NA
scanpy 1.8.1
scipy 1.5.2
sinfo 0.3.1
sip NA
six 1.15.0
sklearn 0.23.2
soupsieve 2.0.1
sphinxcontrib NA
spyder 4.1.5
spyder_kernels 1.9.4
spydercustomize NA
statsmodels 0.12.0
storemagic NA
tables 3.6.1
tblib 1.7.0
texttable 1.6.4
tlz 0.11.0
toolz 0.11.1
tornado 6.0.4
traitlets 5.0.5
typing_extensions NA
umap 0.4.6
wcwidth 0.2.5
webencodings 0.5.1
win32api NA
win32com NA
win32security NA
yaml 5.3.1
zmq 19.0.2
zope NA

IPython 7.19.0
jupyter_client 6.1.7
jupyter_core 4.6.3
jupyterlab 2.2.6
notebook 6.1.4

Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
Windows-10-10.0.19041-SP0
4 logical CPU cores, Intel64 Family 6 Model 78 Stepping 3, GenuineIntel

Session information updated at 2021-09-09 14:23

\

Reading this stackoverflow (https://stackoverflow.com/questions/58518554/attributeerror-graph-object-has-no-attribute-node) I tried downgrading to networkx version 2.3 instead of 2.6.2 and it fixed this issue, but raised a separate incompatibility between networkx and matplotlib.

AttributeError: module 'matplotlib.cbook' has no attribute 'iterable'

which traces back to an issue in networkx rather than scanpy.
The following stackoverflow suggests that the older networkx2.3 requires matplotlib2.2.3 which is quite a large downgrade from my current matplatlib3.4.3 (current as of this date), so downgrading both networkx and matplotlib is not a great solution: https://stackoverflow.com/questions/63198347/attributeerror-module-matplotlib-cbook-has-no-attribute-iterable,

How i fixed it:
After all that I went to line 860-862 of plotting/_tools/paga.py in my own scanpy installation and simply changed all the 'node' to 'nodes':

 for count, n in enumerate(nx_g_solid.nodes()):
            nx_g_solid.node[count]['label'] = str(node_labels[count])
            nx_g_solid.node[count]['color'] = str(colors[count])
            nx_g_solid.node[count]['viz'] = dict(

to

 for count, n in enumerate(nx_g_solid.nodes()):
            nx_g_solid.nodes[count]['label'] = str(node_labels[count])
            nx_g_solid.nodes[count]['color'] = str(colors[count])
            nx_g_solid.nodes[count]['viz'] = dict(

which apparently solved the issue

gexf=sc.pl.paga(paul15, labels=None, color='paul15_clusters', export_to_gexf=True)
WARNING: exporting to write\paga_graph.gexf

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in plotting/_tools/paga.py around lines 860-862 and reproduce the export with the provided PAGA example under networkx 2.6.2. Verify that the graph node attributes are assigned using the supported API and that export_to_gexf=True completes and creates paga_graph.gexf.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.