pypath
pypath copied to clipboard
Conversion from network to dataframe
Describe the bug We were trying to convert a network object into dataframe. We are following github pypath_tutorial.ipynb tutorial. In section 19, we couldn't import main, data_formats, network modules. In the description of this section, pypath is independent from igraph. But in the folllowing code lines include igraph module. What is the alternative way of getting dataframe?
from pypath import main
from pypath import data_formats
from pypath import network
pa = main.PyPath()
pa.init_network(data_formats.pathway_all)
net = network.Network.from_igraph(pa)
net.records[:10]
Traceback
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_12520/2800188623.py in <module>
----> 1 from pypath import main
2 from pypath import data_formats
3 from pypath import network
ImportError: cannot import name 'main' from 'pypath' (C:\Users\elifc\anaconda3\envs\pypath\lib\site-packages\pypath\__init__.py)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_12520/1635450336.py in <module>
----> 1 from pypath import network
ImportError: cannot import name 'network' from 'pypath' (C:\Users\elifc\anaconda3\envs\pypath\lib\site-packages\pypath\__init__.py)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_12520/2290017702.py in <module>
----> 1 from pypath import data_formats
ImportError: cannot import name 'data_formats' from 'pypath' (C:\Users\elifc\anaconda3\envs\pypath\lib\site-packages\pypath\__init__.py)
Desktop (please complete the following information):
- OS: Windows
- Python version: 3.8
- Version or commit hash v0.13.13
Hi Elif,
Apologies for your troubles, this is due to the tutorial being out of date.
The preferred method to load a network and access it as a data frame:
from pypath.core import network
from pypath.resources import network as netres
n = network.Network()
# here we load the "pathway" dataset
# multiple resources and datasets can be added by subsequent calls to `load`
n.load(netres.pathway)
n.make_df()
n.df
Best,
Denes
Closing as solved/response time out