Make MMP network and send to cytoscape #chemoinfo

Recently I use cytoscape in my laboratory. You know Cytoscape is nice tool for network visualization.
I often make data with python and import data from cytoscape. The work flow is not so bad but I am thinking that it will be nice if python can communicate with cytoscape.
Fortunately cytocape has REST plugin called cyREST and also python has py2cytoscape to do it!
It sounds nice. I tried to use these libraries.
At first I installed cyREST to my cytoscape (v3.5.1). appmanager => cyREST >
And also I installed chemviz for drawing chemical structure in cytoscape.
Then install py2cytoscape via pip. ;-)
You can access localhost:1234/v1 from web blowser when cytoscape launched if cyREST is successfully installed.

Ready.
I drew simple MMP network. Code is below.
First, I made MMP from SMILES file by using RDKit MMP script.

$ cat testdata.smi
Oc1ccccc1 phenol
Oc1ccccc1O catechol
Oc1ccccc1N 2-aminophenol
Oc1ccccc1Cl 2-chlorophenol
Nc1ccccc1N o-phenylenediamine
Nc1cc(O)ccc1N amidol
Oc1cc(O)ccc1O hydroxyquinol
Nc1ccccc1 phenylamine
C1CCCC1N cyclopentanol
$ python rfrag.py < testdata.smi> testdata.frag
$ python indexing.py < testdata.frag > testmmp.txt -r 0.2
$ cat testmmp.txt
Oc1ccccc1,Nc1ccccc1,phenol,phenylamine,O[*:1]>>N[*:1],c1ccc(cc1)[*:1]
Nc1cc(O)ccc1N,Nc1ccccc1N,amidol,o-phenylenediamine,O[*:1]>>[*:1][H],Nc1ccc(cc1N)[*:1]
Oc1ccccc1N,Nc1ccccc1N,2-aminophenol,o-phenylenediamine,O[*:1]>>N[*:1],Nc1ccccc1[*:1]
Oc1ccccc1N,Nc1ccccc1,2-aminophenol,phenylamine,O[*:1]>>[*:1][H],Nc1ccccc1[*:1]
Nc1ccccc1N,Nc1ccccc1,o-phenylenediamine,phenylamine,N[*:1]>>[*:1][H],Nc1ccccc1[*:1]
Oc1ccccc1O,Oc1ccccc1N,catechol,2-aminophenol,O[*:1]>>N[*:1],Oc1ccccc1[*:1]
Oc1ccccc1O,Oc1ccccc1Cl,catechol,2-chlorophenol,O[*:1]>>Cl[*:1],Oc1ccccc1[*:1]
Oc1ccccc1O,Oc1ccccc1,catechol,phenol,O[*:1]>>[*:1][H],Oc1ccccc1[*:1]
Oc1ccccc1N,Oc1ccccc1Cl,2-aminophenol,2-chlorophenol,N[*:1]>>Cl[*:1],Oc1ccccc1[*:1]
Oc1ccccc1N,Oc1ccccc1,2-aminophenol,phenol,N[*:1]>>[*:1][H],Oc1ccccc1[*:1]
Oc1ccccc1Cl,Oc1ccccc1,2-chlorophenol,phenol,Cl[*:1]>>[*:1][H],Oc1ccccc1[*:1]
Oc1cc(O)ccc1O,Oc1ccccc1O,hydroxyquinol,catechol,O[*:1]>>[*:1][H],Oc1ccc(cc1O)[*:1]

Now I got MMP data I used the data to make edge of my network and testdata.smi is used to make node data.

Next code is example for communication between python and cytoscape.
At first, import CyRestClient and make connection. Default URL is localhost and port is 1234. But if user would like to use another IP and Port, user can modify from cytoscape.
Edit => Preferences => add => rest.url xxxxx, rest.port xxxx

I used python-igraph for making graph but py2cytoscape handle data generated by networkx, geohi and something.

import igraph
from py2cytoscape.data.cyrest_client import CyRestClient
import py2cytoscape

cy = CyRestClient()
cy.session.delete()
G = igraph.Graph()

with open('testdata.smi', 'r') as vertexis:
    for v in vertexis:
        G.add_vertex(v.split(' ')[0], molname=v.split(' ')[1])

with open("testmmp.txt", "r") as edges:
    for edge in edges:
        G.add_edge(edge.split(",")[0], edge.split(",")[1], transform=edge.split(",")[4])

After making network, go to next step.
network_create_from_igraph method receives data from igraph and send to cytoscape.
Then I set network layout ‘force-directed’.
Finally I set some view style and update the graph settings.

g_cy = cy.network.create_from_igraph(G)
cy.layout.apply(name='force-directed', network=g_cy)

mystyle = cy.style.create('mystyle')

defaults = {
    'NODE_HIGHT': 100,
    'NODE_WIDTH': 100,
    'NODE_FILL_COLOR': "#87CEFA",
    'NODE_BORDER_WIDTH': 5,
    'NODE_BORDER_PAINT': '#FFFFFF',
    'NODE_LABEL_FONT_SIZE': 14,
    'NODE_LABEL_COLOR': '#555555',
    'EDGE_TRANSPARENCY': 100,
    'EDGE_WIDTH': 20,
    'EDGE_STROKE_UNSELECTED_PAINT': '#FFFFFF',
    'NETWORK_BACKGROUND_PAINT': '#3B426F'
}

mystyle.update_defaults(defaults)
cy.style.apply(mystyle, network=g_cy)

View screenshots.
Before run the code, there is no network in cytoscape.

After run the code I could see MMP network without chemical structure.

Finally I set chemviz setting and run paint structure from menu, I could see structure on each node.

And also each node and edge has their own attribute that is set by igraph.
It interesting and useful because all work is done by using only python!

This example is one way python => cytoscape. But the library can send data in both directions.
There are nice documents written in Japanese such like a following URL.
https://qiita.com/keiono/items/ed796643107bd03aff64
Enjoy!

Advertisement

Published by iwatobipen

I'm medicinal chemist in mid size of pharmaceutical company. I love chemoinfo, cording, organic synthesis, my family.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: