Closed CPerscheid closed 4 years ago
Hi Cindy,
Yes unfortunately the tutorial is still out of date (that's why #104 is still open). After submitting the manuscript, these days I am working also on updating the tutorial, hopefully just in a few days it will be completely up to date.
The example above works with little modifications:
from pypath.internals import input_formats
from pypath.core import network
input2 = input_formats.NetworkInput(
name = 'egf2',
input = 'network2.sif',
separator = ' ',
id_col_a = 0,
id_col_b = 2,
id_type_a = 'genesymbol',
id_type_b = 'genesymbol',
sign = (1, '+', '-'),
ncbi_tax_id = 9606,
)
n = network.Network()
n.load(input2)
n
# <Network: 9 nodes, 9 interactions>
n.interactions
# ...
# (<Entity: AKT1>, <Entity: PIK3CA>): <Interaction: AKT1 <=(+)======== PIK3CA [Evidences: egf2 (0 references)]>,
# (<Entity: AKT1>, <Entity: GSK3B>): <Interaction: AKT1 =======(-)==> GSK3B [Evidences: egf2 (0 references)]>,
# (<Entity: PIK3CA>, <Entity: RAC1>): <Interaction: PIK3CA =======(+)==> RAC1 [Evidences: egf2 (0 references)]>,
# ...
Best wishes,
Denes
Hi Denes,
thanks for the answer. I meanwhile found it out myself, however I am wondering if there is any possibility to provide a data structure and not a file? What kind of file formats are currently supported (can I also somehow provide the BioPAXReader class to NetworkInput)?
Best
Cindy
Sure, you can use instead of the file name anything iterable or callable that yields records (i.e. lists or tuples containing fields). Most of the built-in input definitions use a function:
def reader():
with open('network2.sif', 'r') as fp:
for line in fp:
yield line.split()
input2 = input_formats.NetworkInput(
name = 'egf2',
input = reader,
separator = ' ',
id_col_a = 0,
id_col_b = 2,
id_type_a = 'genesymbol',
id_type_b = 'genesymbol',
sign = (1, '+', '-'),
ncbi_tax_id = 9606,
)
n = network.Network()
n.load(input2)
The BioPaxReader
in pypath.utils.pyreact
is something we haven't used for 4 years, when people ask for it I usually need to update it to work properly with other parts of the module. If you want to use it please update to version 0.11.34
. It works by processing the BioPAX and converting the process description representation by applying the PathwayCommons conversion rules. Even if it works well I would recommend to apply it only for process description databases. We plan to replace this module in the future, I am not very confident this kind of conversion is useful. Nevertheless I show below an example how to create a network from Reactome:
from pypath.share import settings
from pypath.utils import pyreact
from pypath.internals import input_formats
from pypath.core import network
settings.setup(progressbars = True)
def reactome_interactions():
r = pyreact.PyReact()
r.load_reactome()
r.expand()
return r.interactions
reactome_input = input_formats.NetworkInput(
name = 'Reactome',
input = reactome_interactions,
id_col_a = 0,
id_col_b = 1,
id_type_a = 'uniprot',
id_type_b = 'uniprot',
ncbi_tax_id = 9606,
references = 5,
is_directed = (3, True),
must_have_references = False,
)
n = network.Network()
n.load(reactome_input)
Thanks a lot for the examples!
I needed some time to get it working for reader methods within a class with parameters, so here just for the sake of completeness a working example for data structures and usage within a class (may it be of help for others):
import pypath.core.network as network
import pypath.core.entity as entity
import pypath.internals.input_formats as input_formats
class Example():
def reader(self, pathway=None):
lines = pathway.split("\n")
for line in lines:
yield line.split()
def createPathway(self):
params = {"self": self, "pathway": "EGFR\txx\tRAC1\nEGF\txx\tAKT1\n"}
input2 = input_formats.NetworkInput(
name='egf2',
input=Example.reader,
input_args= params,
separator=' ',
id_col_a=0,
id_col_b=2,
id_type_a='genesymbol',
id_type_b='genesymbol',
sign=(1, '+', '-'),
ncbi_tax_id=9606,
)
n = network.Network()
n.load(input2)
neighbors = n.partners(entity.Entity("EGFR"))
print("Number of neighbors: " + str(len(neighbors)))
if __name__ == '__main__':
# parse input params
ex = Example()
ex.createPathway()
Hi there,
I just wanted to try out PyPath according to the descriptions here: https://pypath.omnipathdb.org/notebooks/pypath_guide.html#quick-start-3
It seems that this tutorial is outdated with the current pypath version (0.11.32, as you already noted in the release readme).
I wanted to follow the example and use the Readsettings class to create a network from two input files. Is it still possible in general to load networks from own files (probably with the NetworkInput class)? Is it also possible to plot the network? Obviously you removed igraph from pypath, but how can I plot a network now? I cannot find any to_graph (or similarly named) method in the Network class. I have also found the pypath.visual.plot module, but cannot see a class that would be able to visualize a network...
Could you please update the reference and documentation accordingly? It is really hard to move from code piece to code piece to adapt that tutorial code...
Best,
Cindy