saezlab / pypath

Python module for prior knowledge integration. Builds databases of signaling pathways, enzyme-substrate interactions, complexes, annotations and intercellular communication roles.
http://omnipathdb.org/
GNU General Public License v3.0
134 stars 47 forks source link

Cannot see the graph of combined *pathway* resources. #153

Closed numpde closed 4 years ago

numpde commented 4 years ago

Describe the bug This is a follow-up to #152. Cannot see the graph of combined pathway resources.

To Reproduce

from os import devnull
from pypath.legacy.main import PyPath
from pypath.resources import data_formats

devnull = open(devnull, mode='w')

# print(list(data_formats.pathway.keys()))
# ['trip', 'spike', 'signalink3', 'guide2pharma', 'ca1', 'arn', 'nrf2', 'macrophage', 'death', 'pdz', 'signor', 'adhesome', 'icellnet', 'hpmr', 'cellphonedb', 'ramilowski2015', 'lrdb', 'baccin2019']

set1 = {"lrdb", "macrophage", "signalink3", "signor"}
set2 = set(data_formats.pathway.keys()) - set1

datasets = sorted(data_formats.pathway.items())

print("= Set 1 works =")
pa = PyPath()
for (k, v) in datasets:
    if k in set1:
        print(F"Loading {k}")
        pa.load_resources({k: v})
        print(pa.graph, file=devnull)

print("= Set 2 works =")
pa = PyPath()
for (k, v) in datasets:
    if k in set2:
        print(F"Loading {k}")
        pa.load_resources({k: v})
        print(pa.graph, file=devnull)

print("= Combination loads =")
pa = PyPath()
for (k, v) in datasets:
    print(F"Loading {k}")
    pa.load_resources({k: v})

print("= The graph fails =")
print(pa.graph)

Expected behavior See the graph.

Traceback

...
= The graph fails =
Traceback (most recent call last):
  File "/home/ra/repos/cbb/20200902-Pypath/z_issues/152.py", line 38, in <module>
    print(pa.graph)
  File "/home/ra/repos/cbb/venv/lib/python3.8/site-packages/igraph/__init__.py", line 3377, in __str__
    return self.summary(**params)
  File "/home/ra/repos/cbb/venv/lib/python3.8/site-packages/igraph/__init__.py", line 3397, in summary
    return str(GraphSummary(self, verbosity, width, *args, **kwds))
  File "/home/ra/repos/cbb/venv/lib/python3.8/site-packages/igraph/summary.py", line 361, in __str__
    output.extend(getattr(self, method_name)())
  File "/home/ra/repos/cbb/venv/lib/python3.8/site-packages/igraph/summary.py", line 155, in _construct_edgelist_adjlist
    maxlen = max(len(name) for name in names)
  File "/home/ra/repos/cbb/venv/lib/python3.8/site-packages/igraph/summary.py", line 155, in <genexpr>
    maxlen = max(len(name) for name in names)
TypeError: object of type 'Complex' has no len()

Process finished with exit code 1

Log file pypath-ymkzh.log

Desktop (please complete the following information):

Additional context Similar problem with data_formats.ligand_receptor where lrdb and italk cause the issue.

deeenes commented 4 years ago

I think this should be addressed in igraph first of all: https://github.com/igraph/python-igraph/pull/329 But adding a __len__ method to pypath.intera.Complex fixed it also within our side.