Help with Procedure!

Anything that doesn't fit elsewhere.
Martenzi
Posts: 34
Joined: Thu Feb 28, 2013 4:17 am

Help with Procedure!

Post by Martenzi » Tue Jun 04, 2013 3:19 am

I want to create a procedure that looks like these:

proc "fire" ($1 dend(3)0.3, $2 dend(5)0.1, $3 apic(1)0, §4 apic(9)0.9 etc)

and when executed it adds a alphasynapse at one or multiple locations and fire them according to the users settings and finally plot the amplitude vs location in a window and writes the numbers minus baseline to a file.

Would this be a complicated HOC file?

Before I begin I wanna reassure that I´m not taking water over my head. Ted, you wrote two procedures called "putsyn.hoc" and "profile.hoc". I want to modify these into taking one or more specific arguments so that the user can specify multiple places and automate the process of plotting amplitude vs location. I would like to implement an argument to specify recording site as well but I want to check with you first. I´m not fully sure if I am using § correctly.

I am very grateful for some guidance.

Martenzi
Posts: 34
Joined: Thu Feb 28, 2013 4:17 am

Re: Help with Procedure!

Post by Martenzi » Tue Jun 04, 2013 9:17 am

Code: Select all

/* putsyn.hoc for somatic epsp as a function of synaptic location
   last modified 7/15/99 NTC
*/

synloc=0	// accessible to the Gather Values tool

proc putsyn() {
	if ($1 < 0 || $1 > 1) {
		printf("%c",7)	// ring bell
		print "ERROR--location must be in the range [0, 1]" 
		synloc = -1
	} else {
		// say what we want	
		dend AlphaSynapse[0].loc($1)
		// find out what we got
		synloc = AlphaSynapse[0].get_loc()
   /* Note: get_loc() pushes the section of the target point 
	process onto the section stack, so that it becomes the 
	currently accessed section.  We must restore the currently 
	accessed section to what it was before get_loc(). */
		pop_section()
		run()
	}
}

This is the procedure code for the "putsyn.hoc" which is written by you Ted from the hands on tutorial provided by my supervisor.

Code: Select all

/* profile.hoc for somatic epsp as a function of synaptic location
   last modified 7/13/2000 NTC
*/

// objects must first be declared _outside_ procedures
objref location, amplitude
location = new Vector()		// stores locations along the dendrite
amplitude = new Vector()	// stores peak amplitude at each location

objref vm
vm = new Vector()	// to hold the time course of somatic Vm 
			//   evoked by a synaptic input
vm.record(&soma.v(0.5))	// "attach" vm to soma.v(0.5)

objref g
g = new Graph()		// for plot of amplitude vs. location

proc profile() {
	// next three statements discard prior results, if any
	location = new Vector()
	amplitude = new Vector()
	g = new Graph()
	dend for (x) {	// loop over each node in dend
		putsyn(x)
		// at this point, vm should contain a record of soma.v(0.5)
		maximum = vm.max()	// find maximum element in vm
		maximum -= v_init	// epsp amplitude relative to baseline
		amplitude.append(maximum)	// append this to amplitude vector
		location.append(x*dend.L)	// append x to location vector
						//   use units of um, not range
	}
	/* plot amplitude vs. location */
	amplitude.plot(g, location)	// plot amplitude vs. location
}

This is from the "profile.hoc" procedure file.

I figured I can modify these to take multiple statements for specific locations. Is this a good idea or am I completely of with the implementation?

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Help with Procedure!

Post by ted » Tue Jun 04, 2013 9:47 pm

Martenzi wrote:I want to create a procedure that looks like these:

proc "fire" ($1 dend(3)0.3, $2 dend(5)0.1, $3 apic(1)0, §4 apic(9)0.9 etc)

and when executed it adds a alphasynapse at one or multiple locations and fire them according to the users settings and finally plot the amplitude vs location in a window and writes the numbers minus baseline to a file.

Would this be a complicated HOC file?
It is a mistake to start writing code before one has a clear idea of what is to be accomplished. Forget about hoc for now. Start by making a clear statement, in human language, of exactly what you want to do.

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Help with Procedure!

Post by ted » Tue Jun 04, 2013 9:55 pm

If I had it to do over, I would delete the
run()
statement in proc putsyn(), and insert it into proc profile() right after the putsyn() call.

But that's not particularly relevant to your question.

The point process methods loc() and get_loc() might turn out to be useful in a hoc implementation of the task you want to perform, but as in my previous post, the first question is to be sure of the task itself. Just how general is your concept of the task? Do you anticipate needing to activate synapses at any arbitrary combination of locations? Is this something you need to do once, or many times?

Martenzi
Posts: 34
Joined: Thu Feb 28, 2013 4:17 am

Re: Help with Procedure!

Post by Martenzi » Tue Jun 04, 2013 11:15 pm

Im posting again since Im not sure if previous post was successful.

I want this procedure to be able to fire X alphasynapses at x branches on x location (range 0-1) at x recording sites and plot into ampl vs location. So in one procedure sentence the user can specify a list of schedule synaptic inputs and have them automatically recorded into plot and perhaps saved to file.

But Im not sure about the framework, so I should probably start very small and work my way through. The priority is thus in:
1. At least One location and specify multiple synaptic inputs between 0-1 and plot Ampl vs Location at soma. This is the most important part.
2. Add ability to schedule multiple branches with each multiple inputs 0-1.
3. Ability to specify different recording sites for either (1) each branches inputs or (2) for each individual input.
4. Ability to schedule different onsets
etc etc.

This could perhaps be implemented in the GUI instead as a schedule maker so the user can pre define everything and the hit Init & Run once?

1.
step may be to modify this procedure that "dend AlphaSynapse[0].loc($1)" can be generalised into user specified location. Right now it seems it only refers to the first dendrite. And you mentioned to move the run() outside procedure?

Code: Select all

/* putsyn.hoc for somatic epsp as a function of synaptic location
   last modified 7/15/99 NTC
*/

synloc=0	// accessible to the Gather Values tool

proc putsyn() {
	if ($1 < 0 || $1 > 1) {
		printf("%c",7)	// ring bell
		print "ERROR--location must be in the range [0, 1]" 
		synloc = -1
	} else {
		// say what we want
		dend AlphaSynapse[0].loc($1)
		// find out what we got
		synloc = AlphaSynapse[0].get_loc()
   /* Note: get_loc() pushes the section of the target point 
	process onto the section stack, so that it becomes the 
	currently accessed section.  We must restore the currently 
	accessed section to what it was before get_loc(). */
		pop_section()
		run()
	}
}

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Help with Procedure!

Post by ted » Wed Jun 05, 2013 12:23 am

Forget about recording for the moment, and forget about code.
At least One location and specify multiple synaptic inputs between 0-1 and plot Ampl vs Location at soma.
Do you want all synapses to be active so there is temporal summation, or do you want to activate them individually, and see what effect each one has, by itself, on membrane potential at the soma?

Martenzi
Posts: 34
Joined: Thu Feb 28, 2013 4:17 am

Re: Help with Procedure!

Post by Martenzi » Wed Jun 05, 2013 12:33 am

I want all synapses to be individual, without summation. Temporal summation could be added later by lets keep to individual effect.

I forgot to ask. What code is used to append synapse to a section name?
"dend AlphaSynapse[0].loc($1)" , can "dend" be changed to "dend(any specific number on your cell)" and this will target that dendrite? or do I have to change "dend" to become
objref "name" = x
"x AlphaSynapse[0].loc($1)"?

- or should I skip this part to focus on different implementation?

Is there a command for a direct "scan" of section of neuron inside procedure brackets?

proc "name" ($section[number],$range,$recordingsite)?

Can you make more $ inside $ as sub $?
In that case you could make:

For each $ four sub $ applies inside brackets?

proc name ($(section,range,section,range),$ etc)
- and then add a for loop for each new $?

is this possible?
Last edited by Martenzi on Wed Jun 05, 2013 12:52 am, edited 1 time in total.

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Help with Procedure!

Post by ted » Wed Jun 05, 2013 7:42 pm

Martenzi wrote:I forgot to ask. What code is used to append synapse to a section name?
Read chapters 5 and 6 of The NEURON Book. If you don't have the book, at least read "The NEURON Simulation Environment" http://www.neuron.yale.edu/neuron/stati ... /nctoc.htm
Can you make more $ inside $ as sub $?
Suggest you read about the elements of hoc syntax, which are detailed in chapters 12 and 13 of The NEURON Book. If you don't have the book, read these selections from the Programmer's Reference:
http://www.neuron.yale.edu/neuron/stati ... tml#syntax
http://www.neuron.yale.edu/neuron/stati ... rogramming
http://www.neuron.yale.edu/neuron/stati ... n/obj.html

Martenzi
Posts: 34
Joined: Thu Feb 28, 2013 4:17 am

Re: Help with Procedure!

Post by Martenzi » Thu Jun 06, 2013 6:01 am

So what I have got to do is to create 3-4 procedures that precedes the intended procedure that can evoke location, range, recording site etc. ?

proc 1 - Section finder save into $1 whereby an synapse is included?

proc 2 - Range finder (modify putsyn after $1)

proc 3 - Procedure to choose recording site

proc 4 - Range finder for recording site

proc fire () {
$section1 proc 1
$2 proc 2

etc. Would you say this is a good implementation?

$s1 expects a string as argument, correct? Can a section be directly expected in an argument? $section?

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Help with Procedure!

Post by ted » Thu Jun 06, 2013 11:44 am

You're on the right track but you need to impose structure. It's probably best to write an outline in pseudocode that describes what you want to do. That will be the plan for your program. Here are a couple of examples.

1. Suppose you want to see how the location of an excitatory synapse affects the EPSP observed at the soma.

Code: Select all

set up Vector recording of soma.v(0.5)
attach an AlphaSynapse to the soma
create Vectors to hold the EPSP amplitudes and synapse distances from the soma
for each section in the model {
  for each internal node in this section {
    move the AlphaSynapse to this location
    run a simulation
    determine the peak depolarization at the soma (use Vector class's max() method)
    append this to epspvec
    find distance of this point from soma(0.5) and append to distvec
  }
}
subtract resting potential from each element in epspvec
2. Suppose you only want to measure the efficacy of synapses in a particular part of the cell.

Code: Select all

create a set (SectionList) that contains the sections that are of interest
follow outline (1) but instead of iterating over each section in the model, iterate over the sections in the interesting set
Martenzi wrote:$s1 expects a string as argument, correct?
Yes, but you don't need string arguments to implement either of the two examples shown above.
Can a section be directly expected in an argument?
Not in hoc. You can do something similar with a SectionRef. But these are obscure details that are rarely necessary. In almost all cases, section stack syntax (see
http://www.neuron.yale.edu/neuron/stati ... sedSection)
eliminates the need to pass a section as an argument. Example:

Code: Select all

proc foo() {
  . . . statements . . .
}
axon[13] foo() // call foo() with axon[13] as the currently accessed section
forsec myset foo() // for each section in myset
  // make this section the currently accessed section and execute foo()
And always avoid access abuse--use only one "access" statement.
viewtopic.php?f=28&t=608

Martenzi
Posts: 34
Joined: Thu Feb 28, 2013 4:17 am

Re: Help with Procedure!

Post by Martenzi » Fri Jun 07, 2013 11:04 pm

I have the book and have read your recommended links.

Could you perhaps clarify briefly how you would, in layman a terms, use the different methods (section ref, section list, point.loc, accessed section)?

I'm would like to know the limitations of $ and if I the $ can be recognize as a section a directly from the procedure brackets?

if I understand you correctly you want me to invoke section list and save all sections to this list?
if section name .varname can be identified, couldn't this feasibly be used elsewhere?

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Help with Procedure!

Post by ted » Sat Jun 08, 2013 8:35 pm

Let's go back to this.
I want this procedure to be able to fire X alphasynapses at x branches on x location (range 0-1) at x recording sites and plot into ampl vs location.
This code will attach as many AlphaSynapses as you like, to whatever sections you want, and run a simulation. All you have to do is call
dorun()
with the necessary arguments.

Code: Select all

obfunc makesyn() { local i  localobj synlist
  i = 0
  forsec $o1 {
    synlist.append(new AlphaSynapse($o2.x[i]))
    synlist.o(i).onset = $o3.x[i]
    synlist.o(i).tau = $o4.x[i]
    synlist.o(i).gmax = $o5.x[i]
    synlist.o(i).e = $o6.x[i]
    i += 1
  }
  return synlist
}

/*
Arguments:
$o1 SectionList that contains the sections of interest
$o2 Vector of locations at which there is to be a synapse
$o3 Vector of synaptic onset times
$o4 Vector of synaptic time constants
$o5 Vector of synaptic peak conductances
$o6 Vector of synaptic reversal potentials
For each item in $o1 there is a corresponding element in each of the Vectors
*/
proc dorun() { localobj synlist
  synlist = makesyn($o1, $o2, $o3, $o4, $o5, $o6)
  run()
}
To finish the job, all I need to know is what you mean by "plot into ampl vs location."

Martenzi
Posts: 34
Joined: Thu Feb 28, 2013 4:17 am

Re: Help with Procedure!

Post by Martenzi » Sat Jun 08, 2013 9:34 pm

Much obliged! I can tell from your code that I was quite far off with my ideas of how to write the HOC code.

"All you need to know to finish the job is what do I mean by ampl vs location?"

The same thing this procedure is doing, for each argument in "dorun". The idea is simply to make NEURON plot EPSP at Soma (or other section) by invoking only one procedure.

Code: Select all

/* profile.hoc for somatic epsp as a function of synaptic location
   last modified 7/13/2000 NTC
*/

// objects must first be declared _outside_ procedures
objref location, amplitude
location = new Vector()      // stores locations along the dendrite
amplitude = new Vector()   // stores peak amplitude at each location

objref vm
vm = new Vector()   // to hold the time course of somatic Vm 
         //   evoked by a synaptic input
vm.record(&soma.v(0.5))   // "attach" vm to soma.v(0.5)

objref g
g = new Graph()      // for plot of amplitude vs. location

proc profile() {
   // next three statements discard prior results, if any
   location = new Vector()
   amplitude = new Vector()
   g = new Graph()
   dend for (x) {   // loop over each node in dend
      putsyn(x)
      // at this point, vm should contain a record of soma.v(0.5)
      maximum = vm.max()   // find maximum element in vm
      maximum -= v_init   // epsp amplitude relative to baseline
      amplitude.append(maximum)   // append this to amplitude vector
      location.append(x*dend.L)   // append x to location vector
                  //   use units of um, not range
   }
   /* plot amplitude vs. location */
   amplitude.plot(g, location)   // plot amplitude vs. location
}

Martenzi
Posts: 34
Joined: Thu Feb 28, 2013 4:17 am

Re: Help with Procedure!

Post by Martenzi » Sat Jun 08, 2013 10:10 pm

to specify section within the argument is that "dorun(dend[x],2,4 etc?

ted
Site Admin
Posts: 5591
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Help with Procedure!

Post by ted » Sun Jun 09, 2013 11:25 am

make NEURON plot EPSP at Soma
Thank you for that disambiguation. Statements like
plot the amplitude vs location
have many possible interpretations; for example, it might mean "epsp amplitude as a function of position throughout the entire cell" or "epsp amplitude at the location of each synapse."

But that raises another question. You asked for this:
I want this procedure to be able to fire X alphasynapses at x branches on x location (range 0-1) at x recording sites and plot into ampl vs location.
The code I posted answers half of your request: every time dorun() is called with appropriate arguments, synapses are placed at specified locations in a cell, each synapse having its own unique properties (including the time at which it turns on), and then a single simulation is run in which all synapses are active. The other half of your request cannot be answered, because if synapses are active at multiple locations, "location" is entirely meaningless.

Post Reply