Skip to content

Commit

Permalink
Add/export nsoma functions
Browse files Browse the repository at this point in the history
* count number of somata in neurons
* work for both skid specifications and neuron lists
* slow when you have a skid spec as has to fetch label_stats for whole project
* closes #96 (though some improvements possible)
  • Loading branch information
jefferis committed May 28, 2018
1 parent 854e767 commit 0d9c798
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ S3method(as.catmaidmesh,mesh3d)
S3method(as.mesh3d,catmaidmesh)
S3method(connectors,catmaidneuron)
S3method(connectors,neuronlist)
S3method(nsoma,default)
S3method(nsoma,neuron)
S3method(nsoma,neuronlist)
S3method(plot3d,catmaidneuron)
S3method(summary,catmaidneuron)
S3method(xform,catmaidneuron)
Expand Down Expand Up @@ -50,6 +53,7 @@ export(catmaid_user_history)
export(catmaid_version)
export(connectors)
export(copy_tags_connectors)
export(nsoma)
export(read.neuron.catmaid)
export(read.neurons.catmaid)
export(read_catmaid_selection)
Expand Down
56 changes: 55 additions & 1 deletion R/catmaid_nat.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,61 @@ plot3d_somarad <- function(x, soma=FALSE){
}


nsoma <- function(x) length(x[['tags']][['soma']])
#' Return the number of explicitly tagged somata in a (CATMAID) neuron
#'
#' @details These functions can cope with loaded neuron objects or CATMAID skid
#' specifications (see \code{\link{catmaid_skids}}). Note that this function
#' will return 0 for any neuron that does not contain a \code{tags$soma}
#' entry, including regular \code{\link{neuron}} objects .
#' @param x Objects to count somata e.g. one or more neurons or a specifier
#' passed to \code{\link{catmaid_skids}}
#' @param soma_label Character vector of one or more label names that identify
#' somata.
#' @param ... Additional arguments, eventually passed by \code{nsoma.default} to
#' \code{\link{catmaid_skids}}, otherwise ignored.
#'
#' @return A named integer vector corresponding to the number of neurons
#' specified by \code{x}.
#' @export
#' @examples
#' nsoma(Cell07PNs)
#' data("AV4b1")
#' nsoma(AV4b1)
#' \donttest{
#' nsoma("ORN PNs")
#' }
#' \dontrun{
#' nsoma(3486381)
#' }
nsoma <- function(x, ...) UseMethod("nsoma")

#' @export
#' @rdname nsoma
nsoma.neuronlist <- function(x, ...) sapply(x, nsoma, ...)

#' @export
#' @rdname nsoma
nsoma.neuron <- function(x, ...) length(x[['tags']][['soma']])

#' @export
#' @rdname nsoma
nsoma.default <- function(x, soma_label='soma', ...) {
skids <- catmaid_skids(x, ...)
skids_with_soma = skids_with_tags(soma_label)
# NB augment the skid list with query skids so that everybody appears in table
tt=table(c(skids_with_soma[skids_with_soma%in%skids], skids))
# ... but then subtract 1 for the dummy entry
tt=tt-1L
tt[as.character(skids)]
}

# nb returns skid once for every time it contains tag
# TODO see if we can avoid project wide catmaid_get_label_stats
skids_with_tags <- function(tags, ...) {
label_stats=catmaid_get_label_stats(...)
matches=label_stats[['labelName']] %in% tags
label_stats[matches, 'skeletonID']
}

#' @export
summary.catmaidneuron<-function(object, ...) {
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Schuler
sessionid
Sharifi
simplifyVector
somata
SortOnUpdate
syn
Torrens
Expand Down
51 changes: 51 additions & 0 deletions man/nsoma.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d9c798

Please sign in to comment.