Find spike time

Anything that doesn't fit elsewhere.
Post Reply
tony
Posts: 2
Joined: Fri Jun 23, 2006 1:34 pm

Find spike time

Post by tony »

Hi, I im trying to create a vector with the spike time (time wich there`s a spike) using NetCon. I read about NetCon but don't know how to start. Also, it say`s that to use NetCon, we must have a CVode? Maybe a litle hint could help to start the code.

BUGS
NetCon can currently only be used if a CVode object exists
http://www.neuron.yale.edu/neuron/stati ... tml#NetCon
ted
Site Admin
Posts: 6305
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Find spike time

Post by ted »

tony wrote:Hi, I im trying to create a vector with the spike time (time wich there`s a spike) using NetCon. I read about NetCon but don't know how to start.
Hint: use the working example that is provided in the documentation of
the record() method, which I quote here:

Code: Select all

objref vec, netcon, nil
vec = new Vector()
netcon = new NetCon(source, nil)
netcon.record(vec)
objref netcon
If the spike source is a biophysical model cell, just be sure that the spike
trigger zone is the "watched" location--that is, when creating the NetCon
you may wish to use the syntax
section netcon = new NetCon(&v(x), nil)
where section(x) is the spike trigger zone.

Code: Select all

Also, it say`s that to use NetCon, we must have a CVode?
            ^ syntax error--not a contraction or possessive form
but I know why you're concerned. However, if your code starts with
load_file("nrngui.hoc")
you automatically get an instance of the CVode class (even if you don't
activate variable time step integration). So everything should work fine.
tony
Posts: 2
Joined: Fri Jun 23, 2006 1:34 pm

Post by tony »

It work! Thanx Ted for the fast reply!!!
kelvin
Posts: 10
Joined: Tue Jun 07, 2005 10:00 pm
Location: Edmonton, AB Canada
Contact:

More spike times

Post by kelvin »

I decided to try out Ted's advice using NetCon.record to create a vector of spike times. I decided to use the tutorial by Andrew Gillies and David Sterratt to play with this (since many newbies *should* have done this tutorial).

Here is the hoc code with some changes. There are 4 subthalamic cells; the first one gets synaptic input from the other three which are driven by an IClamp. The goal was to get a vector of spike times (spkt) and spike id numbers (spkid) so that I could go back and figure out which cell spiked at what time.

Code: Select all

load_file("nrngui.hoc")

objref cvode

cvode = new CVode(0)

begintemplate SThcell
public soma, treeA, treeB, nclist

create soma, treeA[1], treeB[1]
objectvar f, nclist

proc init() {local i, me, child1, child2

    create soma

    nclist = new List()

    soma {
      nseg = 1
      diam = 18.8
      L = 18.8
      Ra = 123.0
      insert hh
      gnabar_hh=0.25
      gl_hh = .0001666
      el_hh = -60.0
    }

    f = new File()
    f.ropen("treeA.dat")
    
    ndendA = f.scanvar()
    create treeA[ndendA]

    for i = 0,ndendA-1 {
      me = f.scanvar() - 1
      child1 = f.scanvar() - 1
      child2 = f.scanvar() - 1

      treeA[me] {
        nseg = 1
        diam = f.scanvar()
        L = f.scanvar()
        Ra = 123
        // initialise and clear the 3D information
        pt3dclear()
	pt3dadd(f.scanvar(),f.scanvar(),f.scanvar(),diam)
	pt3dadd(f.scanvar(),f.scanvar(),f.scanvar(),diam)
        insert pas
        g_pas = .0001666
        e_pas = -60.0
	
	if (child1 >= 0) {
          //printf("connecting tree A dendrite %d (0 end) to parent %d (1 end)\n",child1,me)
          connect treeA[child1](0), 1
        }
        if (child2 >= 0) {
	  //printf("connecting tree A dendrite %d (0 end) to parent %d (1 end)\n",child2,me)
          connect treeA[child2](0), 1
        }
      }
    }
    f.close()

    f.ropen("treeB.dat")

    ndendB = f.scanvar()
    create treeB[ndendB]
    
    for i = 0,ndendB-1 {
      me = f.scanvar() - 1
      child1 = f.scanvar() - 1
      child2 = f.scanvar() - 1

      treeB[me] {
        nseg = 1
        diam = f.scanvar()
        L = f.scanvar()
        Ra = 123
        // initilise and clear the 3D information
        pt3dclear()
	pt3dadd(f.scanvar(),f.scanvar(),f.scanvar(),diam)
	pt3dadd(f.scanvar(),f.scanvar(),f.scanvar(),diam)
        insert pas
        g_pas = .0001666
        e_pas = -60.0
	
	if (child1 >= 0) {
          //printf("connecting tree B dendrite %d (0 end) to parent %d (1 end)\n",child1,me)
          connect treeB[child1](0), 1
        }
        if (child2 >= 0) {
	  //printf("connecting tree B dendrite %d (0 end) to parent %d (1 end)\n",child2,me)
          connect treeB[child2](0), 1
        }
      }
    }
    f.close()

    // Connect things to the soma
    connect treeA[0](0), soma(1)
    connect treeB[0](0), soma(0)
}

endtemplate SThcell

tstop = 300
ndend = 2
nSThcells = 4

objectvar SThcells[nSThcells]

for i = 0, nSThcells-1 {
    SThcells[i] = new SThcell()
}

objectvar stim[nSThcells]

for i = 1, nSThcells-1 SThcells[i].soma {
    stim[i] = new IClamp(0.5)
    stim[i].del = 100+(2*i)
    stim[i].dur = 100
    stim[i].amp = 0.15
}



// SThcells[1]&[2]&[3] -> SThcells[0].soma

maxsyn = 10
objectvar syn[maxsyn]

SThcells[0].treeA[7] syn[0] = new ExpSyn(0)

for i = 1, nSThcells-1 SThcells[i].soma {
   SThcells[0].nclist.append(new NetCon(&v(1), syn[0], -20, 1, 0.5))
}

// NetCon for recording spike trains

objref spkt, spkid, netcon, nil
spkt = new Vector()
spkid = new Vector()

for i = 0, nSThcells-1 SThcells[i].soma {
   netcon = new NetCon(&v(0.5), nil)
   netcon.threshold = -20
   netcon.record(spkt, spkid)
}
objref netcon

access SThcells[0].soma
Now bring up the "RunControl" from the Tools menu, hit "Init & Run" and then from the prompt you can type:

Code: Select all

oc>spkt.printf("%6.2f\n")
and,

Code: Select all

oc>spkid.printf(%1.0f\n")
to get a list of spike times and the id number that says which cell is associated with each spike time.

So, here are my questions for the NEURON sages:
1) Why does the code fragment for netcon.record (Prog Ref) include the final,

Code: Select all

objref netcon
? (I can comment it out and get the same results.)
2) How could I return the value of the last NetCon[id] so that I could change the numbers in the spkid vector to be more straight forward?
3) Did I do this right, or how would you improve this?
kelvin
Posts: 10
Joined: Tue Jun 07, 2005 10:00 pm
Location: Edmonton, AB Canada
Contact:

Answering my own question #2

Post by kelvin »

2) How could I return the value of the last NetCon[id] so that I could change the numbers in the spkid vector to be more straight forward?
Whoops... I noticed that there was another argument to netcon.record that solves this. In the for loop where the spike times are recorded just change one line to,

Code: Select all

netcon.record(spkt, spkid, i)
Yay, now when SThcell[0] fires an AP, the spkid vector reports '0' instead of '3'.
ted
Site Admin
Posts: 6305
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

1) Why does the code fragment for netcon.record (Prog Ref) include the final,
objref netcon
Destroying the NetCon prevents reusing the NetCon for some other purpose, which
would have the side effect of interfering with the recording. In the Programmer's
Reference see
http://www.neuron.yale.edu/neuron/stati ... tml#record
in particular this sentence:
If a source is recording a vector, that source is not destroyed when the last netcon
connecting to it is destroyed and it continues to record.
Here "source" means the bit of code that watches for threshold crossing.

Also please read chapter 13 Object-oriented programming in The NEURON Book, if
you haven't already done so. If you don't have the book, at least read this excerpt from
the old reference manual
http://www.neuron.yale.edu/neuron/stati ... n/obj.html
(somehow I suspect that you have read one or both of these).
3) Did I do this right, or how would you improve this?
One suggestion: modularize the code. Makes development and debugging easier.
Relegate the template to a file by itself.
Put the code that actually creates new cells in a second file.
Put the code that sets up synaptic connections in a third file.
Put simulation control code in a fourth file (e.g. cvode stuff, anything to do with tstop etc.).
Then use an init.hoc to pull it all together.

Code: Select all

load_file("nrngui.hoc") // or load_file("noload.hoc") 
  // if you don't want to see the NEURON Main Menu toolbar
load_file("cellclass.hoc") // contains the template
load_file("spawncells.hoc")
load_file("makenet.hoc")
load_file("simctrl.hoc")
// load_file("graphs.hoc") or load_file("graphs.ses") if you're plotting stuff
ted
Site Admin
Posts: 6305
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Answering my own question #2

Post by ted »

kelvin wrote:
2) How could I return the value of the last NetCon[id] so that I could change the numbers in the spkid vector to be more straight forward?
Whoops... I noticed that there was another argument to netcon.record that solves this. In the for loop where the spike times are recorded just change one line to,

Code: Select all

netcon.record(spkt, spkid, i)
Yay, now when SThcell[0] fires an AP, the spkid vector reports '0' instead of '3'.
Excellent, Kelvin!
Post Reply