pypath icon indicating copy to clipboard operation
pypath copied to clipboard

Conversion from network to dataframe

Open elifcevrim opened this issue 2 years ago • 1 comments

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

elifcevrim avatar Dec 14 '21 15:12 elifcevrim

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

deeenes avatar Dec 14 '21 19:12 deeenes

Closing as solved/response time out

Nic-Nic avatar Feb 15 '24 13:02 Nic-Nic