Created
February 23, 2016 18:54
-
-
Save keiono/bff21b7bf8f237995ffe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import json\n", | |
"\n", | |
"JSON_EXT = '.json'\n", | |
"CYTOSCAPE_JS_EXT = '.cyjs'\n", | |
"\n", | |
"def convert2sigma(in_file_name, out_file_name):\n", | |
" print('Source file: ' + in_file_name)\n", | |
"\n", | |
" # Load Original Cyjs file\n", | |
" cyjs_file = open(in_file_name)\n", | |
" source_json = json.load(cyjs_file)\n", | |
" cyjs_file.close()\n", | |
"\n", | |
" # Output files\n", | |
" out = open(out_file_name, \"w\")\n", | |
"\n", | |
" nodeMap = {}\n", | |
"\n", | |
" sourceNodes = source_json[\"elements\"][\"nodes\"]\n", | |
" sourceEdges = source_json[\"elements\"][\"edges\"]\n", | |
"\n", | |
" nodeList = []\n", | |
" edgeList = []\n", | |
"\n", | |
" for node in sourceNodes:\n", | |
" termID = node[\"data\"][\"Manual_Name\"]\n", | |
" x = node[\"position\"][\"x\"]\n", | |
" y = node[\"position\"][\"y\"]\n", | |
" suid = node[\"data\"][\"SUID\"]\n", | |
" if \"Size\" in node[\"data\"]:\n", | |
" size = node[\"data\"][\"Size\"] * 2\n", | |
" else:\n", | |
" size = 2.0\n", | |
" \n", | |
" newNode = {\n", | |
" 'id':termID, \n", | |
" 'label':termID,\n", | |
" 'size':size,\n", | |
" 'x':x, 'y':y, \n", | |
" 'color':\"rgb(58,150,43)\"\n", | |
" }\n", | |
" \n", | |
" nodeMap[str(suid)] = termID\n", | |
" nodeList.append(newNode)\n", | |
"\n", | |
" for edge in sourceEdges:\n", | |
" source = nodeMap[edge['data']['source']]\n", | |
" target = nodeMap[edge['data']['target']]\n", | |
" interaction = edge['data']['interaction']\n", | |
" edgeList.append({'source':source, 'target':target, 'relationship':interaction, 'weight':1.0})\n", | |
"\n", | |
" graph = {}\n", | |
"\n", | |
" graph[\"nodes\"] = nodeList\n", | |
" graph[\"edges\"] = edgeList\n", | |
"\n", | |
" out.write(json.dumps(graph, sort_keys=True, indent=4))\n", | |
" out.close()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Source file: /Users/kono/prog/nexo-docker/nexo/frontend/app/data/atgo.cyjs\n" | |
] | |
} | |
], | |
"source": [ | |
"# Test run\n", | |
"convert2sigma('/Users/kono/prog/nexo-docker/nexo/frontend/app/data/atgo.cyjs', 'atgo.json')" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"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.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment