Skip to content

Instantly share code, notes, and snippets.

@slarson
Created March 8, 2013 06:42
Show Gist options
  • Save slarson/5114643 to your computer and use it in GitHub Desktop.
Save slarson/5114643 to your computer and use it in GitHub Desktop.
First cut at a script to analyse c. elegans connectome graph
"""
worm2nx.py
Simple script for turning connectome tables into NetworkX graphs.
Note that the tables were extracted manually from the connectivity spreadsheet
of the c. elegans and should accompany this script.
Author: Pedro Tabacof (tabacof at gmail dot com)
Stephen Larson (stephen@openworm.org)
License: Public Domain
"""
# -*- coding: utf-8 -*-
import csv
import urllib2
import networkx as nx
worm = nx.DiGraph()
# Neuron table
csvfile = urllib2.urlopen('https://raw.github.com/openworm/data-viz/master/HivePlots/neurons.csv')
reader = csv.reader(csvfile, delimiter=';', quotechar='|')
for row in reader:
neurontype = ""
# Detects neuron function
if "sensory" in row[1].lower():
neurontype += "sensory"
if "motor" in row[1].lower():
neurontype += "motor"
if "interneuron" in row[1].lower():
neurontype += "interneuron"
if len(neurontype) == 0:
neurontype = "unknown"
if len(row[0]) > 0: # Only saves valid neuron names
worm.add_node(row[0], ntype = neurontype)
# Connectome table
csvfile = urllib2.urlopen('https://raw.github.com/openworm/data-viz/master/HivePlots/connectome.csv')
reader = csv.reader(csvfile, delimiter=';', quotechar='|')
for row in reader:
worm.add_edge(row[0], row[1], weight = row[3])
worm[row[0]][row[1]]['synapse'] = row[2]
worm[row[0]][row[1]]['neurotransmitter'] = row[4]
print "******DEGREES OF TOP FOUR INTERNEURONS*******"
print "Degree of AVAL: " + str(worm.degree('AVAL'))
print "Degree of AVAR: " + str(worm.degree('AVAR'))
print "Degree of AVBL: " + str(worm.degree('AVBL'))
print "Degree of AVBR: " + str(worm.degree('AVBR'))
print "******DEGREES OF NEXT FOUR INTERNEURONS*******"
print "Degree of PVCR: " + str(worm.degree('PVCR'))
print "Degree of PVCL: " + str(worm.degree('PVCL'))
print "Degree of AVDR: " + str(worm.degree('AVDR'))
print "Degree of AVER: " + str(worm.degree('AVER'))
print "******DEGREE OF TOP SENSORY NEURON*******"
print "Degree of ADEL: " + str(worm.degree('ADEL'))
print "******DEGREE OF TOP MOTOR NEURON*******"
print "Degree of RIMR: " + str(worm.degree('RIMR'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment