Page 1 of 1

Extract network connectivity

Posted: Wed Apr 18, 2012 8:52 am
by manyi
Hi there!

I want to extract the connectivity of the network. I'm using an artificial cell as Poisson input sources and a usual neuron model for neurons. When printing the pre and post cells with

Code: Select all

for i=0, nclist.count-1 {dfile.printf("%s\t%s\t%s\n", nclist.object[i].precell, nclist.object[i].postcell, nclist.object[i].syn)}
I got correct labels for neurons (Let's say "Cell[0]") but "NULLobject" for Poisson sources, and so I cannot trace the Poisson sources to a particular neuron. If I replace precell by pre, I got the correct labels for Poisson input sources (say "NetStim[0]") but "NULLobject" for neurons.

How can I get correct labels to both at the same time? Many thanks!

Re: Extract network connectivity

Posted: Wed Apr 18, 2012 12:06 pm
by ted
That's how the NetCon class's precell() and pre() methods work. The workaround is to write your own "precell" function that anticipates possible outcomes and takes appropriate action in each case. Something like this might work:

Code: Select all

// argument is a NetCon
obfunc myprecell() { local nil
  // nil points to NULLobject
  if ($o1.precell() == nil) {
    return $o1.pre()
  } else {
    return $o1.precell()
  }
}
A minor comment, for the benefit of subsequent readers of this thread: the square brackets [ ] in the example you provided should be parentheses ( ).

Re: Extract network connectivity

Posted: Tue Apr 24, 2012 12:45 pm
by manyi
I have the following code in a proc

Code: Select all

for i=0, nclist.count-1 {
		dfile.printf("%s\t%s\n", myprecell(nclist.object(i)), nclist.object(i).postcell)}
obfunc myprecell(){...} is defined in the same file, just above the proc. I get the following error message and do not know what's wrong:

bad stack access: expecting (Object **); really (double)
/usr/local/nrn/i686/bin/nrniv: interpreter stack type error
in test.hoc near line 151
rrun()
^
myprecell(...)
saveNet()
rrun()
initcode failed with 2 left

Re: Extract network connectivity

Posted: Tue Apr 24, 2012 8:28 pm
by ted
Is the problem in myprecell(), or is it elsewhere?

First of all, what does
nclist.o(0)
return?
And what about
printf("%s\n", nclist.o(0))
?

Does
for i=0, nclist.count-1 printf("%s\n", nclist.o(i))
produce the expected result?

What about
myprecell(nclist.o(0))
?
And
for i=0, nclist.count-1 printf("%s\n", myprecell(nclist.o(i)))
?

Re: Extract network connectivity

Posted: Wed Apr 25, 2012 10:14 am
by manyi
It works when 'local nil' is removed from the obfunc.
Thanks!

Re: Extract network connectivity

Posted: Wed Apr 25, 2012 10:27 am
by ted
My mistake. The first line of the definition of myprecell() was supposed to be
obfunc myprecell() { localobj nil

If your code works with
obfunc myprecell() {
i.e. after deleting the declaration that nil is a localobj,
then there must have been a
localobj nil
statement somewhere else in your code at the top level, i.e. outside of any object.

For future readers of this thread: the corrected procedure is

Code: Select all

// argument is a NetCon
obfunc myprecell() { local nil
  // nil points to NULLobject
  if ($o1.precell() == nil) {
    return $o1.pre()
  } else {
    return $o1.precell()
  }
}