Is it possible to know if a section is in sectionlist

Anything that doesn't fit elsewhere.
Post Reply
oren
Posts: 54
Joined: Fri Mar 22, 2013 1:03 am

Is it possible to know if a section is in sectionlist

Post by oren » Wed Jan 29, 2014 7:54 pm

Is it possible to know if a section is in sectionlist?

For example soma{ print = sectionlist.in()}
What I managed to do is
sl = new SectionList()
soma {
sl.append()
n1 = sl.unique()
if n1==0{
sl.remove()}
}
Then id n1>0 I know that the section was in the sectionlist. Is this method good? Is there another way?

EDIT this is the other way...

Code: Select all

ifsec sectionlist stmt
Executes stmt if the currently accessed section is in the sectionlist.
And I have another question about issection("regular expression"). How can I do alternation?
from what I read http://unix.stackexchange.com/questions ... e-patterns
soma2{issection("soma{1-10}\|soma{20-25}")}
should return 1 but I receive 0

Thank You.
Last edited by oren on Tue Feb 04, 2014 3:17 am, edited 2 times in total.

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

Re: Is it possible to know if a section is in sectionlist

Post by ted » Thu Jan 30, 2014 11:42 am

oren wrote:Is it possible to know if a section is in sectionlist?
One problem with your code is that it corrupts the section list that you are trying to test. sl.append() ensures that n1 will be >=1, so

Code: Select all

if n1==0{
sl.remove()}
is guaranteed to fail to remove the appended section. Another problem is that it won't be very useful unless it's written as a function. Here's something that addresses both of these problems

Code: Select all

func insl() { localobj tobj
  // first copy $o1's contents into a new SectionList()
  tobj = new SectionList()
  forsec $o1 tobj.append()
  // now append the section of interest
  tobj.append()
  return (tobj.unique>0)
}
and an example of usage

Code: Select all

create soma, dend, axon
objref sl1, sl2
sl1 = new SectionList()
sl2 = new SectionList()
forall sl1.append()
forall sl2.append()
axon sl2.remove()

result = -1
axon result = insl(sl1)
print "is axon in sl1? ", result
axon result = insl(sl2)
print "is axon in sl2? ", result
soma2{issection("soma{1-10}\|soma{20-25}")}
should return 1 but I receive 0
It doesn't surprise me that
soma2{issection("soma{1-10}")}
returns nothing, because embedding statements in curly brackets suppresses printout of values returned by funcs, e.g.
oc>sqrt(2)
returns
1.414...
but
oc>{ sqrt(2) }
returns nothing. That said,
oc>{ print sqrt(2) }
prints
1.414...
to the terminal, and
oc>soma2{ print issection("soma{1-10}") }
prints 1.

But when I try
soma2{ print issection("soma{1-10}\|soma{20-25}") }
sure enough, the result is 0!

The workaround is to split this into two calls to issection, and OR the results.
soma2{print issection("soma{1-10}") || issection("soma{20-25}")}
prints 1.

oren
Posts: 54
Joined: Fri Mar 22, 2013 1:03 am

Re: Is it possible to know if a section is in sectionlist

Post by oren » Thu Jan 30, 2014 12:37 pm

ted wrote:
oren wrote:Is it possible to know if a section is in sectionlist?
One problem with your code is that it corrupts the section list that you are trying to test. sl.append() ensures that n1 will be >=1, so

Code: Select all

if n1==0{
sl.remove()}
is guaranteed to fail to remove the appended section. Another problem is that it won't be very useful unless it's written as a function. Here's something that addresses both of these problems

Code: Select all

func insl() { localobj tobj
  // first copy $o1's contents into a new SectionList()
  tobj = new SectionList()
  forsec $o1 tobj.append()
  // now append the section of interest
  tobj.append()
  return (tobj.unique>0)
}
and an example of usage

Code: Select all

create soma, dend, axon
objref sl1, sl2
sl1 = new SectionList()
sl2 = new SectionList()
forall sl1.append()
forall sl2.append()
axon sl2.remove()

result = -1
axon result = insl(sl1)
print "is axon in sl1? ", result
axon result = insl(sl2)
print "is axon in sl2? ", result
Thank You Ted. Nice function. But each time we need to copy the full sectionList . This can be very slow ? Is there a faster way?
ted wrote:
soma2{issection("soma{1-10}\|soma{20-25}")}
should return 1 but I receive 0
It doesn't surprise me that
soma2{issection("soma{1-10}")}
returns nothing, because embedding statements in curly brackets suppresses printout of values returned by funcs, e.g.
Indeed I forgot the print.
ted wrote: oc>sqrt(2)
returns
1.414...
but
oc>{ sqrt(2) }
returns nothing. That said,
oc>{ print sqrt(2) }
prints
1.414...
to the terminal, and
oc>soma2{ print issection("soma{1-10}") }
prints 1.

But when I try
soma2{ print issection("soma{1-10}\|soma{20-25}") }
sure enough, the result is 0!
Thank you, But in the specification I see that
Regular expressions are like those of grep except {} are used in place of [] to avoid conflict with indexed sections.
So I thought the code is grep based.. and in grep ""soma{1-10}\|soma{20-25}" suppose to work..
Thank You.

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

Re: Is it possible to know if a section is in sectionlist

Post by ted » Fri Jan 31, 2014 12:50 pm

oren wrote:each time we need to copy the full sectionList . This can be very slow ?
Are you asking a question, or have you already found that it is slow? How does it compare to model setup time, or the time required to advance the simulation through a few (hundreds or thousands) of ms of model time? My guess is that the time required to copy a SectionList will be a small fraction of the time required to execute a simulation.
Is there a faster way?
If it really does take "too long" to copy the original SectionList, I'd suggest revising your program's code so that it doesn't involve checking whether a section is in a particular SectionList. Of all the hoc code that I've seen, I've never run into a situation in which it was necessary to check whether a section was present in a particular SectionList, let alone run such a check more than once in the course of model setup, simulation execution, or analysis of simulation results.
in the specification I see that
Regular expressions are like those of grep except {} are used in place of [] to avoid conflict with indexed sections.
So I thought the code is grep based
It's possible that you found a bug. Or maybe the underlying code implements only a subset of grep's functionality.

hines
Site Admin
Posts: 1576
Joined: Wed May 18, 2005 3:32 pm

Re: Is it possible to know if a section is in sectionlist

Post by hines » Fri Jan 31, 2014 1:46 pm

{1-10} as a regular expression does not mean ' from one to 10 inclusive' but, ironically 1 to 1 or 0. ie it would select 0 and 1. One typically sees things line
{a-zA-Z0-9} which means any alphanumeric character.

By the way, if one is doing a lot of name processing on sections in Python, I would think it is easiest to use a normal python list.

forall if (issection("regexp")) is slow as is forsec "regexp" and hence, in hoc, it is good to set up a sectionlist once during setup time and store in a sectionlist
forsec "regexp" { sl.append() } for later reuse as forsec sl { ... } But in the python world one can choose between h.SectionList and any number of alternatives such as list and dict for
fast iteration over a set of sections.

note that 20 to 25 would be [2{0-5}] and 1 to 10 would be a concatentation of results for [{1-9}] and [10]
Regular expressions are not that great for emulation of arithmetic expressions.

oren
Posts: 54
Joined: Fri Mar 22, 2013 1:03 am

Re: Is it possible to know if a section is in sectionlist

Post by oren » Sat Feb 01, 2014 3:06 pm

hines wrote:{1-10} as a regular expression does not mean ' from one to 10 inclusive' but, ironically 1 to 1 or 0. ie it would select 0 and 1. One typically sees things line
{a-zA-Z0-9} which means any alphanumeric character.

By the way, if one is doing a lot of name processing on sections in Python, I would think it is easiest to use a normal python list.

forall if (issection("regexp")) is slow as is forsec "regexp" and hence, in hoc, it is good to set up a sectionlist once during setup time and store in a sectionlist
forsec "regexp" { sl.append() } for later reuse as forsec sl { ... } But in the python world one can choose between h.SectionList and any number of alternatives such as list and dict for
fast iteration over a set of sections.

note that 20 to 25 would be [2{0-5}] and 1 to 10 would be a concatentation of results for [{1-9}] and [10]
Regular expressions are not that great for emulation of arithmetic expressions.
Thank You. So this means that the "regular expression" from issection("regular expression") of Neruon is different from normal regexp ?
Because in the specification of the issection
"Thus a[{8-15}] matches sections a[8] through a[15] "

hines
Site Admin
Posts: 1576
Joined: Wed May 18, 2005 3:32 pm

Re: Is it possible to know if a section is in sectionlist

Post by hines » Sun Feb 02, 2014 7:55 pm

My previous reply is wrong and needs to go to the memory hole. The documentation is almost correct (note that<> is used in place of [] to denote character ranges) and {8-13} does mean an integer range. Thus

Code: Select all

oc>create a[30]
oc>forall if (issection("a[{8-13}]")) { print secname() }
a[8]
a[9]
a[10]
a[11]
a[12]
a[13]
forsec "a[{8-13}]" print secname()
a[8]
a[9]
a[10]
a[11]
a[12]
a[13]
At least my message was correct if I change {1-10} to <1-10> since

Code: Select all

oc>forsec "a[<1-10>]" print secname()
a[0]
a[1]
However, surpirsingly the invalid character range <8-15>, instead of an error gives

Code: Select all

oc>forsec "a[<8-15>]" print secname()
a[1]
a[5]
a[8]

hines
Site Admin
Posts: 1576
Joined: Wed May 18, 2005 3:32 pm

Re: Is it possible to know if a section is in sectionlist

Post by hines » Sun Feb 02, 2014 8:08 pm

In updating the documentation, I see that the answer to the original question is in
http://www.neuron.yale.edu/neuron/stati ... word-ifsec

Post Reply