This network is generated from data provided as suplimentary files, by the authors of the paper Schizophrenia interactome with 504 novel protein–protein interactions.
import numpy as np
import igraph as ig
We define the schizofrenia network as an igraph.Graph():
G=ig.Graph.Read_GML('Data/schizophrenia.gml')
Extract the list of tuples representing graph edges:
E=[e.tuple for e in G.es]
E[:4]
len(E)
Separate the known edges from novel edges:
known_edge=[k for k in range(len(G.es)) if G.es[k]['interaction']=='Known']
novel_edge=[k for k in range(len(G.es)) if G.es[k]['interaction']=='Novel']
len(known_edge)+len(novel_edge)
Extract the list of vertices of type 'tri', respectively 'sq':
L=len(G.vs)
T=[k for k in range(L) if G.vs[k]['type']=='tri']
S=[k for k in range(L) if G.vs[k]['type']=='sq']
TS=set(T) | set(S)
known=[k for k in range(L) if G.vs[k]['interactor']=='Known']
novel=[k for k in range(L) if G.vs[k]['interactor']=='Novel']
interactor=list(G.vs['interactor'])
red_edge=[]
bluegray_edge=[]
for k,e in enumerate(E):
if k in novel_edge:
red_edge.append(e)
else:
bluegray_edge.append(e)
Get the vertices position assigned by the Fruchterman-Reingold layout algorithm:
layt=G.layout('fr')
N=len(layt)# N is equal to len(G.vs)
N
U=set(T) | set(S) | set(known) | set(novel)|{47}
C=set(range(L))-U #C is the list of 'Candidate" type vertices
print (C)
C=sorted(list(C))
#print ([G.vs[k] for k in C])
Define the lists of x, y-coordinates of different typys of nodes (verts):
XnG=[layt[k][0] for k in T]
YnG=[layt[k][1] for k in T]
XnH=[layt[k][0] for k in S]
YnH=[layt[k][1] for k in S]
XnK=[layt[k][0] for k in known]
YnK=[layt[k][1] for k in known]
XnN=[layt[k][0] for k in novel]
YnN=[layt[k][1] for k in novel]
XnC=[layt[k][0] for k in C]
YnC=[layt[k][1] for k in C]
Xn=[layt[47][0]]
Yn=[layt[47][1]]
Define the lists of x, y-coordinates of edge ends:
Xer=[]
Yer=[]
for e in red_edge:
Xer.extend([layt[e[0]][0],layt[e[1]][0], None])
Yer.extend([layt[e[0]][1],layt[e[1]][1], None])
Xeb=[]
Yeb=[]
for e in bluegray_edge:
Xeb.extend([layt[e[0]][0],layt[e[1]][0], None])
Yeb.extend([layt[e[0]][1],layt[e[1]][1], None])
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
init_notebook_mode(connected=True)
verts=list(G.vs['name'])
verts[:5]
VG=[verts[k] for k in range(L) if k in T ]
VH=[verts[k] for k in range(L) if k in S ]
VK=[verts[k] for k in range(L) if k in known ]
VN=[verts[k] for k in range(L) if k in novel ]
VC=[verts[k] for k in range(L) if k in C ]
Define Plotly traces/data for each class of vertices and edges:
trace1=dict(type='scatter',
x=Xer,
y=Yer,
mode='lines',
line=dict(color='#d890a7', width=0.5),
hoverinfo='none',
name='Novel'
)
trace2=dict(type='scatter',
x=Xeb,
y=Yeb,
mode='lines',
line=dict(color='#a3bad2', width=0.5),
hoverinfo='none',
name='Known'
)
trace4=dict(type='scatter',
x=XnH,
y=YnH,
mode='markers',
name='Historic',
marker=dict(symbol='square',
size=7,
color='blue'
),
text=VH,
hoverinfo='text'
)
trace3=dict(type='scatter',
x=XnG,
y=YnG,
mode='markers',
name='GWAS',
marker=dict(symbol='triangle-up',
size=8,
color='blue'
),
text=VG,
hoverinfo='text'
)
trace5=dict(type='scatter',
x=XnK,
y=YnK,
mode='markers',
name='Known',
marker=dict(size=4,
color='#a3bad2',
line=dict(color='rgb(100,100,100)', width=0.5)
),
text=VK,
hoverinfo='text'
)
trace6=dict(type='scatter',
x=XnN,
y=YnN,
mode='markers',
name='Novel',
marker=dict(size=4,
color='rgb(255,0,0)'
),
text=VN,
hoverinfo='text'
)
trace7=dict(type='scatter',
x=XnC,
y=YnC,
mode='markers',
name='Candidate',
marker=dict(symbol='star',
size=4,
color='rgb(245,245,245)',
line=dict(color='rgb(100,100,100)', width=0.5)
),
text=VC,
hoverinfo='text'
)
trace8=dict(type='scatter',
x=Xn,
y=Yn,
mode='markers',
name='Schizo-assoc-gene',
marker=dict(size=4,
color='blue',
),
text=[verts[47]],
hoverinfo='text'
)
Set the Plotly layout for the schizophrenia network:
axis=dict(showbackground=False,
showline=False,
zeroline=False,
showgrid=False,
showticklabels=False,
title=''
)
plot_title=title="Schizophrenia Interactome"+\
"<br>Network of protein–protein interactions between schizophrenia genes"
layout = dict(title=plot_title,
font=dict(family='Balto', color='rgb(1,1,1)'),
width=930,
height=870,
showlegend=True,
legend=dict(x=1.02, y=0.9,
bgcolor='rgb(255,255,255)',
bordercolor='rgb(1,1,1)'),
xaxis=dict(axis),
yaxis=dict(axis),
margin=dict(t=120),
paper_bgcolor='rgb(230,230,230)',
hovermode='closest',
annotations=[dict(showarrow=False,
text="Data source: <a href='http://www.nature.com/articles/npjschz201612'> [1]</a>",
xref='paper',
yref='paper',
x=0.1,
y=0,
font=dict(family='Balto',size=14 )
)
]
)
data=[trace2, trace1, trace3, trace4, trace5, trace6, trace8, trace7]
fig=dict(data=data, layout=layout)
iplot(fig)#plot offline
Send plot to Plotly cloud:
import plotly.plotly as py
py.sign_in('empet', 'my_api_key')
py.iplot(fig, filename='schizophrenia-network')
from IPython.display import HTML
HTML('<iframe src=https://plot.ly/~empet/14299 width=1000 height=800></iframe>')
from IPython.core.display import HTML
def css_styling():
styles = open("./custom.css", "r").read()
return HTML(styles)
css_styling()