subset.neuronlist: Subset neuronlist returning either new neuronlist or names of...

Description Usage Arguments Details Value See Also Examples

View source: R/neuronlist.R

Description

Subset neuronlist returning either new neuronlist or names of chosen neurons

Usage

1
2
3
4
5
6
7
8
## S3 method for class 'neuronlist'
subset(
  x,
  subset,
  filterfun,
  rval = c("neuronlist", "names", "data.frame"),
  ...
)

Arguments

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 TRUE when that neuron should be included in the return list.

rval

What to return (character vector, default='neuronlist')

...

additional arguments passed to filterfun

Details

The subset expression should evaluate to one of

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).

Value

A neuronlist, character vector of names or the attached data.frame according to the value of rval

See Also

neuronlist, find.neuron, subset.data.frame, subset.neuron, subset.dotprops

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)

nat documentation built on Sept. 6, 2021, 5:09 p.m.