R/neuronlist.R
Subset neuronlist returning either new neuronlist or names of chosen neurons
# S3 method for 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 |
A neuronlist
, character vector of names or the attached
data.frame according to the value of rval
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).
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)#> gene_name Name idid soma_side #> GadMARCM-F000142_seg002 GadMARCM-F000142_seg002 Gad1-F-300043 10647 L #> GadMARCM-F000423_seg001 GadMARCM-F000423_seg001 Gad1-F-300107 9541 R #> ChaMARCM-F000586_seg002 ChaMARCM-F000586_seg002 Cha-F-300150 7113 R #> flipped Driver Gender X Y Z #> GadMARCM-F000142_seg002 FALSE Gad1-Gal4 F 349.5917 78.18986 96.69280 #> GadMARCM-F000423_seg001 TRUE Gad1-Gal4 F 401.4795 76.32671 97.92564 #> ChaMARCM-F000586_seg002 TRUE Cha-Gal4 F 340.1020 79.79322 92.21622 #> exemplar cluster idx type #> GadMARCM-F000142_seg002 GadMARCM-F000142_seg002 71 1535 apbp #> GadMARCM-F000423_seg001 GadMARCM-F000423_seg001 61 1265 apbp #> ChaMARCM-F000586_seg002 ChaMARCM-F000586_seg002 52 898 apbp# 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') # }