Cable Length Calculator

This program reads a neuron hoc file and spits out its total cable length (i.e. the combined length of all neurites, excluding axons).

First, here are the required imports:


In [1]:
# Imports
import sys # Required for system access (below)
import os # Required for os access (below)
sys.path.append(os.path.join(os.path.dirname(os.getcwd()), 'dependencies'))
from neuron_readExportedGeometry import * # Required to interpret hoc files

Next, load up a neuron hoc file as a geo object:


In [2]:
# Convert the given hoc file into a geo object
geo = demoReadsilent('/home/cosmo/marderlab/test/878_043_GM_scaled.hoc')


Number of subgraphs = 3 / size of graphs: [35, 36, 844]
Removed all but largest subgraphs
Soma is filament_999[0].
7 axons are:
['filament_999[431]', 'filament_999[779]', 'filament_999[760]', 'filament_999[680]', 'filament_999[220]', 'filament_999[875]', 'filament_999[20]']
From soma to tips, tortuosity is 1.6 +- 0.9

Now that we have a geo object ready to go, let's make a list of all the neurite paths from soma to tip:


In [3]:
tips, ends = geo.getTips() # Store all the tip segments in a list, "tips"
                           # Also store the associated ends in "ends"
find = PathDistanceFinder(geo, geo.soma) # Set up a PDF object for the
                                         # given geo object, anchored at
                                         # the soma
paths = [find.pathTo(seg) for seg in tips] # List of all paths


Soma is filament_999[0].
7 axons are:
['filament_999[431]', 'filament_999[779]', 'filament_999[760]', 'filament_999[680]', 'filament_999[220]', 'filament_999[875]', 'filament_999[20]']

Finally, it's time to calculate the cable length! Let's create a for loop that keeps a running list of which paths have already been measured while adding everything together:


In [4]:
counted = [] # Initialize a list for keeping track of which segments have
             # already been measured
cablelength = 0 # Initialize a running total of cable length
for path in paths: # Sort through each path
    pruned = [seg for seg in path if seg not in counted] # Limit the paths
                                                         # we work with to
                                                         # those which have
                                                         # not already been
                                                         # measured
    forfind = PathDistanceFinder(geo, pruned[0]) # Initialize a PDF
                                                 # anchored at the earliest
                                                 # unmeasured segment
    cablelength += forfind.distanceTo(pruned[-1]) # Add the distance
                                                  # between the anchor and
                                                  # the tip segment to the
                                                  # running total
    for seg in pruned: # Add all of the measured segments to "counted"
        counted.append(seg)
print(cablelength)


3830.5778984167946