{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

Schizophrenia Interactome
\n", " Network of protein–protein interactions between schizophrenia genes

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