Determining distance from soma along apical dendrite

Managing anatomically complex model cells with the CellBuilder. Importing morphometric data with NEURON's Import3D tool or Robert Cannon's CVAPP. Where to find detailed morphometric data.
Post Reply
pascal
Posts: 116
Joined: Thu Apr 26, 2012 11:51 am

Determining distance from soma along apical dendrite

Post by pascal »

I am working with a pyramidal cell in a recently published study by Ponzi et. al. (https://modeldb.science/267686?tab=2&fi ... es/pyr.hoc). It is my first time working with morphometric data (defined in this file: https://modeldb.science/267686?tab=2&fi ... A0_idJ.asc), and I have some very basic questions.

1) pyr.hoc (linked above) defines five different categories of sections with the lines

Code: Select all

public soma, dend, apic, axon, myelin
create soma[1], dend[1], apic[1], axon[1], myelin[1]
As was pointed out in a previous post (viewtopic.php?p=20390&hilit=soma#p20390), this sets up each part of the neuron to be imported as a "chain of chunks."

My question is, how does pyr.hoc know how to assign each chunk of data in oh140807_A0_idJ.asc to the appropriate section category (soma, dend, apic, axon, or myelin)? Looking at oh140807_A0_idJ.asc, there are parts labeled "Dendrite" (but not "dend") and "Apical" (but not "apic"), and there is a "CellBody" (but no "soma"). Do the functions Import3d_Neurolucida3 and/or Import3d_GUI called in pyr.hoc somehow know to map the "dend" sections in pyr.hoc to the "Dendrite" data in oh140807_A0_idJ.asc?

2) For the simulation I want to run, I need to find at least one branch of the apical dendrite that is 250 um from the soma (I need to attach an IClamp there). What is the best way to do that?

Thank you in advance for the help.
ted
Site Admin
Posts: 6361
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Determining distance from soma along apical dendrite

Post by ted »

how does pyr.hoc know how to assign each chunk of data in oh140807_A0_idJ.asc to the appropriate section category
The Neurolucida file contains not only the morphometric data that specify cell topology and geometry, but also metadata (specified by the person or algorithm that did the actual measuring) that Import3d recognizes and uses to determine which measurements correspond to the soma, axon, or various dendrites. If you want more information about the SWC file format look online or see Neurolucida's own documentation. If you want to learn how Import3d works, reading the files in share/nrn/lib/hoc/import3d would be a good way to start.
I need to find at least one branch of the apical dendrite that is 250 um from the soma
Why not find 'em all?

But first, you must decide: from where in the soma? Middle of the soma? 0 end? 1 end? somewhere else? This will serve as the reference point for all distance calculations. You decide.

Then here's your solution, in pseudocode. For convenience I call the reference point R.

Code: Select all

first, if R is not the 0, 0.5, or 1 location in the soma, make sure that soma.nseg is such that R corresponds to the middle of a soma segment
then set R as the reference point for distance calculations
for every dendrite in the set of apical dendrites
  dist0 = distance between R and this section's 0 end
  if dist0 <= 250 um
    dist1 = distance between R and this section's 1 end
    if dist1 >= 250 um
      print "got one" and the name of the section
Implementational details will depend on whether you are using hoc or Python, but one thing will be certain: you'll be using NEURON's distance function, starting with the second line in the pseudocode. Read about distance() in NEURON's hoc or Python documentation, accordingly.
pascal
Posts: 116
Joined: Thu Apr 26, 2012 11:51 am

Re: Determining distance from soma along apical dendrite

Post by pascal »

Thanks, Ted, that is really helpful. Here's the Python code I wrote to implement your pseudocode:

Code: Select all

from neuron import h

h.load_file('pyr.hoc') 
cell = h.CA1_PC_cAC_sig()

target_dist = 250 #um
for sec in cell.apical: #'apical' is a SectionList defined in pyr.hoc
    # use distance function to determine distance from center of soma (see https://nrn.readthedocs.io/en/8.0.1/hoc/modelspec/programmatic/topology/geometry.html?highlight=distance#distance )
    if h.distance(cell.soma[0](0.5), sec(0)) <= target_dist and h.distance(cell.soma[0](0.5), sec(1)) > target_dist:
        print(sec,'0 end: ', h.distance(cell.soma[0](0.5), sec(0)),'1 end:', h.distance(cell.soma[0](0.5), sec(1)))
        
For this model, there are 14 apical dendrite sections that fit the bill. It would be nice if I could easily visualize where the 14 sections are located...I started by using the GUI's Import3D tool (https://nrn.readthedocs.io/en/latest/gu ... ort3d.html), but I couldn't figure out a way for it display the names of each section. When I exported to the CellBuilder and went to the Topology tab, it was blank:

Image
Image

Unfortunately it appears the screenshot is not linking correctly for some reason. In any case, does the Import3D GUI allow for visualizing the section names? And if not, is there another way to generate such a visualization?
ted
Site Admin
Posts: 6361
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Determining distance from soma along apical dendrite

Post by ted »

Import3d won't do this. NEURON's InterViews based GUI has a "Section Parameters viewer" tool (AKA "shape name" tool) that is specifically designed for interactive browsing of a model cell's sections and segments.

NEURON Main Menu toolbar / Tools / Distributed Mechanisms / Viewers / Shape Name

brings it up. Left panel is a canvas that shows an xy projection (implemented with the Shape class) of the model cell, right panel contains a scrollable list of section names.

It is a good idea to make the "shape's" canvas larger by grabbing the right lower corner of the tool and dragging it down and to the right. You can also use the shape's menu box to move the canvas around and zoom in on regions of interest. Then be sure to restore the normal operation of the shape by clicking on Section in its primary menu.

Click on any branch in the shape and It will turn red, and the name of the section will be highlighted in the scrollable list. Click on any section name in the list, and the corresponding branch in the "shape" will turn red. At the top of the tool's right panel note the "Type" button and the numerical field next to the x button. Double click on a section name, and up pops a panel that reveals the PARAMETERs, ASSIGNED variables, and/or STATE variables (depending on the selection of "Type") at the location specified by x.

Let me know if it would be helpful to have a brief Zoom session to see how to use this tool.

Deeply orthodox pythonistas might gag at the thought of using such a primitive implement, but they haven't yet created anything like it in Python.

If you have free time on your hands, you could use the Shape class from Python to implement a graph that could
highlight each section of interest in red
place a dot at the center of each segment that is closest to your desired distance from the soma
report the name and range of any segment that you click on
present a scrollable list of sections that meet your distance criteria and, in the Shape, highlight the section that corresponds to the section name you clicked on.
and then you could rotate and zoom that Shape to your heart's content.
pascal
Posts: 116
Joined: Thu Apr 26, 2012 11:51 am

Re: Determining distance from soma along apical dendrite

Post by pascal »

Thanks, Ted, this sounds like exactly the tool I need. However, I am still running into a very basic problem (exposing my ignorance related to using the NEURON GUI). I assume that to use this Shape Name tool, I need to have created an instance of the model cell in question. I tried to do this by opening nrngui and loading pyr.hoc (https://modeldb.science/267686?tab=2&fi ... es/pyr.hoc), which defines the template cell named CA1_PC_cAC_sig. Loading this file appeared to be successful (it loaded all the relevant mechanisms and did not throw an error). I then tried to create an instance of the cell within the nrngui command window by typing

Code: Select all

cell = new CA1_PC_cAC_sig()
However this gives the following error:
C:\nrn\bin\nrniv.exe: syntax error
near line 464
cell = new CA1_PC_cAC_sig()


I'm pretty sure I'm using proper hoc syntax. I also tried it with Python syntax ( cell = h.CA1_PC_cAC_sig() ), and that gave a syntax error as well within the nrngui command window. I'm sure I'm missing something very basic, but I can't figure out what it is.
ted
Site Admin
Posts: 6361
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Determining distance from soma along apical dendrite

Post by ted »

You're almost there. I bet you forgot to declare that cell is an objref. Easy to do, especially if you're comfortable with Python which has dynamic typing.

Just to make sure, I ran a couple of tests myself. Over the past couple of days I have been switching from CentoOS 7 to Rocky Linux 9, and as of this afternoon had completed enough installation and configuration that I could install NEURON and start doing code development.

From modeldb.science I downloaded 267686.zip, expanded it in an empty directory, then cd'd into that directory and executed
nrnivmodl mechanisms
which succeeded, creating an x86_67 subdirectory.

Then I created file test.hoc which contained these statements

Code: Select all

load_file("nrngui.hoc") // gets the run time system and the GUI library
load_file("pyr.hoc")
objref foo
foo = new CA1_PC_cAC_sig()
and then executed
nrngui test.hoc
which succeeded and printed this message to the terminal
Target stub axon length:60 um, equivalent length: 57.954581
before presenting the oc> prompt. At that point executing
topology()
confirmed the existence of a branched model cell.

Then I exited NEURON, and created file test.py which contained these statements

Code: Select all

from neuron import h, gui
h.load_file("pyr.hoc")
foo = h.CA1_PC_cAC_sig("foo")
and then executed
python -i test.py
which also succeeded and printed this message to the terminal
Target stub axon length:60 um, equivalent length: 57.954581
before presenting the >>> prompt. At that point executing
h.topology()
confirmed the existence of a branched model cell.

Of course you don't have to include the GUI's library if you don't want to (but executing
nrngui test.hoc
will load it anyway because that's what nrngui does).
pascal
Posts: 116
Joined: Thu Apr 26, 2012 11:51 am

Re: Determining distance from soma along apical dendrite

Post by pascal »

Excellent, everything is working perfectly now. Thanks so much, Ted!
ted
Site Admin
Posts: 6361
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Determining distance from soma along apical dendrite

Post by ted »

You're welcome. Many of the old GUI tools are quite powerful, and particularly useful for interactive exploration of model properties and simulation results in a way that complements Python's powerful introspection features.
Post Reply