Created
December 27, 2016 21:17
-
-
Save edraizen/640d7c2535a8642187a752a994dd6a65 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": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import networkx as nx\n", | |
"import matplotlib.pyplot as plt\n", | |
"%matplotlib inline" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"TMs = {\n", | |
" \"TM1\": range(34,64),\n", | |
" \"TM2\": range(71,100),\n", | |
" \"TM3\": range(106,140),\n", | |
" \"TM4\": range(150,172),\n", | |
" \"TM5\": range(200,230),\n", | |
" \"TM6\": range(241,276),\n", | |
" \"TM7\": range(286,309)\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"TM_ecs = {tm:{} for tm in TMs.keys()}\n", | |
"with open(\"gross_aln_gremlin_ecs.tsv\") as f:\n", | |
" for line in f.readlines()[1:]:\n", | |
" fields = line.rstrip().split()\n", | |
" i = int(fields[0])\n", | |
" j = int(fields[1])\n", | |
" score = float(fields[5])\n", | |
" if score>=1:\n", | |
" for tm1, tm1_ranges in TMs.iteritems():\n", | |
" if i in tm1_ranges:\n", | |
" break\n", | |
"\n", | |
" for tm2, tm2_ranges in TMs.iteritems():\n", | |
" if j in tm2_ranges:\n", | |
" break\n", | |
" try:\n", | |
" TM_ecs[tm1][tm2]+=1\n", | |
" except:\n", | |
" TM_ecs[tm1][tm2]=1\n", | |
"\n", | |
" try:\n", | |
" TM_ecs[tm2][tm1]+=1\n", | |
" except:\n", | |
" TM_ecs[tm2][tm1]=1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"tm_graph = nx.Graph()\n", | |
"for tm1, tm1_partners in TM_ecs.iteritems():\n", | |
" for tm2, tm1_tm2 in tm1_partners.iteritems():\n", | |
" if not tm_graph.has_edge(tm1, tm2):\n", | |
" tm_graph.add_edge(tm1, tm2, count=tm1_tm2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"pos = nx.spring_layout(tm_graph)\n", | |
"weights = [tm_graph[u][v]['count'] for u,v in tm_graph.edges()]\n", | |
"labels = nx.get_edge_attributes(tm_graph,'count')\n", | |
"nx.draw(tm_graph,pos=pos, with_labels=True, width=weights, node_size=1800, node_color=\"#D3D3D3\", edge_color=\"#688e3a\")\n", | |
"nx.draw_networkx_edge_labels(tm_graph,pos,edge_labels=labels)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"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.12" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment