Created
March 8, 2013 06:42
-
-
Save slarson/5114643 to your computer and use it in GitHub Desktop.
First cut at a script to analyse c. elegans connectome graph
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
""" | |
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 ([email protected]) | |
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