Created
August 6, 2015 20:07
-
-
Save davebshow/2b948c0a1eada2515a38 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": 18, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def assign_ids(ref_file, edge_list):\n", | |
" id_map = {}\n", | |
" infile = open(ref_file, 'r')\n", | |
" for row in infile:\n", | |
" l = row.split(',')\n", | |
" ided = l[0]\n", | |
" name = l[1]\n", | |
" id_map[name] = ided\n", | |
" edgefile = open(edge_list, 'r')\n", | |
" outfile = open('new_edges.txt', 'w')\n", | |
" for row in edgefile:\n", | |
" l = row.split(',')\n", | |
" source = id_map.get(l[1], l[1])\n", | |
" target = id_map.get(l[2], l[2])\n", | |
" outfile.write(\"{},{}\\n\".format(source, target))\n", | |
" infile.close()\n", | |
" edgefile.close()\n", | |
" outfile.close()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"assign_ids('rtbf_nodes.csv', 'rtbf_edges.csv') # Filenames" | |
] | |
} | |
], | |
"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.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment