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

network.Network to igraph obj support #128

Closed luli7 closed 4 years ago

luli7 commented 4 years ago

Hi Everyone,

I am using the new network.Network provided by PyPath. However, I have just realised the to_igraph function within this class has not been implemented.

I have also tried from_igraph function to convert an igraph based main.PyPath obj to network.Network obj, however I obtained a TypeError: "update_attrs() argument after ** must be a mapping, not NoneType".

Besides, when I use exclude in both a main.PyPath obj (load_omnipath()) or a network.Network obj (load_omnipath()), I have obtained different number of nodes and interactions with the same exclude list.

Please help. If I want to use igraph but also like the new functions provided in network.Network (e.g. find_paths()), what I should do?

Thank you in advance! Best regards Lu

deeenes commented 4 years ago

Hi Lu,

The extra interactions in the new Network object were all loops, which are by default disabled in the legacy version. I added an option to the new class to allow loops and the default behaviour is to allow them.

The interactions only in the legacy object were due to a couple of proteins of other organisms remaining in the network. This was a bug in the pypath.legacy.main.PyPath.delete_unknown() method. I fixed it.

Now the networks build by the two classes have exactly the same set of interactions.

Also the Network.from_igraph method works for me fine, I think the bug which caused trouble for you has been already fixed recently.

I add here the script I used for inspecting this issue:

from pypath.resources import network as netres
from pypath.legacy import main as legacy
from pypath.core import network

pw_legacy = legacy.PyPath()
pw_legacy.load_resources(netres.pathway)
i_pw_legacy = set(pw_legacy.graph.es['attrs'])

pw_new = network.Network()
pw_new.load(netres.pathway)
i_pw_new = set(pw_new)

i_only_legacy = i_pw_legacy - i_pw_new
i_only_new = i_pw_new - i_pw_legacy

len(i_only_legacy) # 79 interactions only in the legacy
len(i_only_new) # 327 interactions only in the new

pw_new.remove_loops()
pw_legacy.delete_unknown()
i_pw_new = set(pw_new)
i_pw_legacy = set(pw_legacy.graph.es['attrs'])

i_only_legacy = i_pw_legacy - i_pw_new
i_only_new = i_pw_new - i_pw_legacy

len(i_only_legacy) # 0 interactions only in the legacy
len(i_only_new) # 0 interactions only in the new

# this works for me
pw_from_igraph = network.Network.from_igraph(pw_legacy)

Best wishes,

Denes