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')
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
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)