{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "if (window['cytoscape'] === undefined) {\n", " var paths = {\n", " cytoscape: 'http://cytoscape.github.io/cytoscape.js/api/cytoscape.js-latest/cytoscape.min'\n", " };\n", "\n", " require.config({\n", " paths: paths\n", " });\n", "\n", " require(['cytoscape'], function (cytoscape) {\n", " console.log('Loading Cytoscape.js Module...');\n", " window['cytoscape'] = cytoscape;\n", "\n", " var event = document.createEvent(\"HTMLEvents\");\n", " event.initEvent(\"load_cytoscape\", true, false);\n", " window.dispatchEvent(event);\n", " });\n", "}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "ename": "ImportError", "evalue": "No module named rpy2.robjects.packages", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0migraph\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mig\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mrpy2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrobjects\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpackages\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mrpackages\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mImportError\u001b[0m: No module named rpy2.robjects.packages" ] } ], "source": [ "from py2cytoscape.data.cynetwork import CyNetwork\n", "from py2cytoscape.data.cyrest_client import CyRestClient\n", "from py2cytoscape.data.style import StyleUtil\n", "import py2cytoscape.util.cytoscapejs as cyjs\n", "import py2cytoscape.cytoscapejs as renderer\n", "\n", "import networkx as nx\n", "import pandas as pd\n", "import json\n", "\n", "import igraph as ig\n", "\n", "import rpy2.robjects.packages as rpackages" ] }, { "cell_type": "code", "execution_count": 117, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 117, "metadata": {}, "output_type": "execute_result" } ], "source": [ "NUM_NODES = 100\n", "\n", "g1 = ig.Graph.Barabasi(NUM_NODES, 2)\n", "g2 = ig.Graph.GRG(NUM_NODES, 0.2)\n", "\n", "cy = CyRestClient()\n", "cy.network.create_from_igraph(g1)\n", "cy.network.create_from_igraph(g2)" ] }, { "cell_type": "code", "execution_count": 148, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[igraph.Vertex(,27,{'y': 0.4122450976155393, 'x': 0.26689583205779077, 'label': -1, 'community': 0, 'f1': None}), igraph.Vertex(,37,{'y': 0.4413342902926116, 'x': 0.4042221456555569, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(,42,{'y': 0.3919489906377719, 'x': 0.4447844056662684, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(,43,{'y': 0.4770437889078536, 'x': 0.4455614569474644, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(,44,{'y': 0.7063847186804972, 'x': 0.4719754150531076, 'label': -1, 'community': 0, 'f1': None}), igraph.Vertex(,46,{'y': 0.4894698809295054, 'x': 0.48049028523140314, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(,48,{'y': 0.4316934429074447, 'x': 0.48068638848412193, 'label': -1, 'community': 1, 'f1': None}), igraph.Vertex(,54,{'y': 0.5463835210708057, 'x': 0.5826852935480062, 'label': -1, 'community': 0, 'f1': None}), igraph.Vertex(,55,{'y': 0.4600141507637713, 'x': 0.5841189250955006, 'label': -1, 'community': 1, 'f1': None})]\n", "27\n", "37\n", "42\n", "43\n", "44\n", "46\n", "48\n", "54\n", "55\n", "39\n", "47\n", "50\n", "59\n", "64\n", "67\n", "69\n" ] } ], "source": [ "g2.vs['label'] = [-1]*NUM_NODES\n", "fix = [False]*NUM_NODES\n", "\n", "\n", "node0 = g2.vs[40]\n", "node1 = g2.vs[57]\n", "\n", "\n", "ne1= node0.neighbors()\n", "ne2= node1.neighbors()\n", "\n", "print(ne1)\n", "\n", "\n", "g2.vs[40]['label'] = 1 \n", "g2.vs[57]['label'] = 1 \n", "\n", "for n in ne1:\n", " print(n.index)\n", " g2.vs[n.index]['label'] = 1\n", " \n", "for n in ne2:\n", " print(n.index)\n", " g2.vs[n.index]['label'] = 1\n", "\n", "fix[40] = True\n", "fix[57] = True" ] }, { "cell_type": "code", "execution_count": 149, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 149, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res = g2.community_label_propagation(initial='label')\n", "\n", "g2.vs['community'] = res.membership\n", "\n", "cy.network.create_from_igraph(g2)" ] }, { "cell_type": "code", "execution_count": 167, "metadata": { "collapsed": true }, "outputs": [], "source": [ "yhq = pd.read_csv('/Applications/Cytoscape_v3.2.1/sampleData/yeastHighQuality.sif', sep=' ', names=['s', 'itr', 't'])\n", "yhq = yhq.drop('itr', 1)\n", "yhq.head()\n", "\n", "yhq.to_csv('yhq.el', sep=' ')" ] }, { "cell_type": "code", "execution_count": 168, "metadata": { "collapsed": false }, "outputs": [ { "ename": "InternalError", "evalue": "Error at foreign.c:101: parsing edgelist file failed, Parse error", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mInternalError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRead_Edgelist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'yhq.el'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mInternalError\u001b[0m: Error at foreign.c:101: parsing edgelist file failed, Parse error" ] } ], "source": [ "ig.Graph.Read_Edgelist('yhq.el')" ] }, { "cell_type": "raw", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }