nat
nat copied to clipboard
Transparent support for indexing neuronlists with numeric ids
At the moment if a numeric id e.g. that used as the unique identified for a neuron in a database is used to index a neuronlist
, it will be interpreted as an int
. This is not what one wants. The current workaround is to convert such ids to character vectors before the indexing call, but this must be done explicitly. Perhaps we could make a simple class e.g. nlid
that would indicate that the contents (which could be any class including R primitives) should be used for indexing by equality not by position.
tenthousandneurons=read.neurons("bigfolder")
# ouch
tenthousandneurons[12134567]
# ok
tenthousandneurons[as.character("12134567")]
# a (little bit) better
tenthousandneurons[nlid(12134567)]
# likewise
plot3d(tenthousandneurons, nlid(12134567))
# could work with `plot3d.nlid` method (which could just pass through to `plot3d.character`)
plot3d(nlid(12134567))
# But more useful would be e.g.
x=read.neurons.catmaid(nlid(...))
selids=find.neurons(x)
plot3d(x, selids)
Would need to check any existing locations where subsets are processed because sometimes existing logic might get in the way e.g.
https://github.com/jefferis/nat/blob/5ef3314ea2cc8edd685754b921b0dc6193b8ba69/R/neuronlist.R#L432-L446
where it is assumed that if our subset is not a character
then we should be using it to subset literally the names of the neuronlist. We would instead need to have special case logic for nlid
or be more restrictive in which types we continue to convert into names.