subset.neuronlist | R Documentation |
Subset neuronlist returning either new neuronlist or names of chosen neurons
## S3 method for class 'neuronlist'
subset(
x,
subset,
filterfun,
rval = c("neuronlist", "names", "data.frame"),
...
)
x |
a neuronlist |
subset |
An expression that can be evaluated in the context of the dataframe attached to the neuronlist. See details. |
filterfun |
a function which can be applied to each neuron returning
|
rval |
What to return (character vector, default='neuronlist') |
... |
additional arguments passed to |
The subset expression should evaluate to one of
character vector of names
logical vector
vector of numeric indices
Any missing names are dropped with a warning. The filterfun
expression is wrapped in a try. Neurons returning an error will be dropped
with a warning.
You may also be interested in find.neuron
, which enables
objects in a neuronlist to be subsetted by a 3D selection box. In addition
subset.neuron
, subset.dotprops
methods exist:
these are used to remove points from neurons (rather than to remove neurons
from neuronlists).
A neuronlist
, character vector of names or the attached
data.frame according to the value of rval
neuronlist, find.neuron,
subset.data.frame, subset.neuron, subset.dotprops
da1pns=subset(Cell07PNs,Glomerulus=='DA1')
with(da1pns,stopifnot(all(Glomerulus=='DA1')))
gammas=subset(kcs20,type=='gamma')
with(gammas,stopifnot(all(type=='gamma')))
# define a function that checks whether a neuron has points in a region in
# space, specifically the tip of the mushroom body alpha' lobe
aptip<-function(x) {xyz=xyzmatrix(x);any(xyz[,'X']>350 & xyz[,'Y']<40)}
# this should identify the alpha'/beta' kenyon cells only
apbps=subset(kcs20,filterfun=aptip)
# look at which neurons are present in the subsetted neuronlist
head(apbps)
# combine global variables with dataframe columns
odds=rep(c(TRUE,FALSE),10)
stopifnot(all.equal(subset(kcs20,type=='gamma' & odds),
subset(kcs20,type=='gamma' & rep(c(TRUE,FALSE),10))))
## Not run:
# make a 3D selection function using interactive rgl::select3d() function
s3d=select3d()
# Apply a 3D search function to the first 100 neurons in the neuronlist dataset
subset(dps[1:100],filterfun=function(x) {sum(s3d(xyzmatrix(x)))>0},
rval='names')
# combine a search by metadata, neuropil location and 3D location
subset(dps, Gender=="M" & rAL>1000, function(x) sum(s3d(x))>0, rval='name')
# The same but specifying indices directly, which can be considerably faster
# when neuronlist is huge and memory is in short supply
subset(dps, names(dps)[1:100],filterfun=function(x) {sum(s3d(xyzmatrix(x)))>0},
rval='names')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.