Skip to content

Instantly share code, notes, and snippets.

@slarson
Last active December 19, 2015 07:29
Show Gist options
  • Save slarson/5919352 to your computer and use it in GitHub Desktop.
Save slarson/5919352 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": "Synapse Position Algorithm"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "Goal \n----\n\nTo annotate NeuroML morphologies with synapse positions from Cook's data\n\nChallenge\n----------\n\nThe most obvious approach involves skilled manual labor that no one realistically is going to do and is too hard to train others to do.\n\nTheory\n------- \n\nAutomated solution with less precision may be preferable to manual process with greater precision\n\nCook's data\n-----------\nNeuron $<->$ muscle mapping"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "NeuroML\n-------\n3D morphology representation of neurons discretized into segments"
},
{
"cell_type": "code",
"collapsed": false,
"input": "Image(url='https://docs.google.com/drawings/d/16W7jPxFTdmZaEr9I5L-Lem-loA6iVfSQlZl-dHW4yxg/pub?w=806&amp;h=255')",
"language": "python",
"metadata": {},
"outputs": [
{
"html": "<img src=\"https://docs.google.com/drawings/d/16W7jPxFTdmZaEr9I5L-Lem-loA6iVfSQlZl-dHW4yxg/pub?w=806&amp;h=255\"/>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": "<IPython.core.display.Image at 0x254b4d0>"
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": "neuroml code\n------------\n\nIn NeuroML, everything is a segment, idealized as a cylinder. Each muscle cell is approximated as a cylinder. The extended shape of a neuron is discretized by breaking it apart into cylinders. \n\nIn the figure above, each cylinder labeled 'm' is a separate muscle cell. Lines that are drawn running down the body of the worm are the NeuroML representations of the neurons. They are also broken up into cylinders. In this drawing, we are only showing 3 neurons and we are only showing a subset of their segments. That subset is defined by the red disks. The red discs are the planes created by the end caps, $s(m)$ and $e(m)$ of the cylinder representing muscle cell m. We define the set of segments that fall in between $s(m)$ and $e(m)$ as the seg_list.\n\n\n muscle_seg_map = [] # init a muscle segment multi-map that uses the muscle name as its key and a list of segment multi-maps as its value\n for each mus m: # loop over all muscle cells\n start_disc = s(m) # define the disc / plane at the beginning of that muscle cell\n end_disc = e(m) # define the disc / plane at the end of that muscle cell\n seg_list = seg_list(start_disc, end_disc) # create a list of segments (from neurons) that are bounded by the start and end discs.\n for each seg s in seg_list: \n sm = seg_map(n(s), s) # define a segment multi map that uses the neuron name as its key and a list of segments as its value\n muscle_seg_map.put(m, sm) # add the segment multi-map to the muscle segment map.\n\nAt the end of this process, there will be a data structure that has a set of segment ids from the neurons that are known to be nearby for each muscle cell. These are then candidate segments which we will use to assign synapses based on the biological data we pull out in the next step..."
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Cook's connectome code\n----------------------\n\nThe synapse positions in the database are stored within image coordinates in cross sections through the body of the worm.\n\nFor initial testing, we will deal with the back $3/4$ of the worm and leave the head (first 7 muscle cells) alone.\n\nCook's database can tell us for any muscle cell m, what neurons synapse on it. \n \n for each mus m: # iterate over all muscle cells\n syn_list = [] # initialize a list of the synapses for muscle cell m \n list neu = neurons w/ synapses from m # define the list of neurons that have synapses with m\n for each n in neu: \n syn_count = syn_count(n, m) # get the number of synapse between muscle m and neuron n\n distribute_syn (syn_count, n, m) # distribute the number of synapses across the neuron segment list "
},
{
"cell_type": "code",
"collapsed": false,
"input": "Image(url='https://docs.google.com/drawings/d/13pCbJpCNKxhfGd2eEjtPRxgTjur-eI7Cfl3zWYn1BJU/pub?w=478&amp;h=211')",
"language": "python",
"metadata": {},
"outputs": [
{
"html": "<img src=\"https://docs.google.com/drawings/d/13pCbJpCNKxhfGd2eEjtPRxgTjur-eI7Cfl3zWYn1BJU/pub?w=478&amp;h=211\"/>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": "<IPython.core.display.Image at 0x254b650>"
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Assuming you know which neuron and which muscle you want to add synapses, then all you need to do is find the segments for the NeuroML of that neuron to assign those synapses to. An algorithm could assign synapses randomly among the segments nearest the muscle. That function would look something like:\n\ndistribute code\n---------------\n\n distribute ( syn_count, neuron, muscle) # distribute a number of synapses between a neuron and a muscle segment representation\n seg_list = muscle_seg_map(m,n) # pull the seg list for a given neuron that is near this muscle (from NeuroML code above)\n ... to write ... # assign syn_count number of synapses between neuron and muscle for the segments in seg_list\n "
},
{
"cell_type": "code",
"collapsed": false,
"input": "from IPython.display import Image\nImage(url='https://docs.google.com/drawings/d/1rfX9cDaFThd2X9HcyWXb-ECPjB6L6UTR5uTAErBUqEU/pub?w=435&amp;h=292')",
"language": "python",
"metadata": {},
"outputs": [
{
"html": "<img src=\"https://docs.google.com/drawings/d/1rfX9cDaFThd2X9HcyWXb-ECPjB6L6UTR5uTAErBUqEU/pub?w=435&amp;h=292\"/>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": "<IPython.core.display.Image at 0x254b090>"
}
],
"prompt_number": 4
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment