Skip to content

Commit

Permalink
add fanc_cellid_table() and use it for cell ids
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferis committed Mar 16, 2024
1 parent 19b38b2 commit 8494bc7
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions R/ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ fanc_ids <- function(x, integer64=NA) {
#' second edits.
#' @param rval Whether to return the cell ids or the whole of the CAVE table
#' with additional columns.
#' @param cellid_table Optional name of cell id table (the default value should
#' be correct).
#' @param cellid_table Optional name of cell id table (the default value of
#' \code{NULL} should find the correct table).
#' @return Either a vector of ids or a data.frame depending on \code{rval}. For
#' cell ids the vector will be an integer for root ids (segment ids), a
#' character vector or an \code{bit64::integer64} vector depending on the
Expand Down Expand Up @@ -233,8 +233,10 @@ fanc_cellid_from_segid <- function(rootids=NULL, timestamp=NULL, version=NULL, c
#' \donttest{
#' fanc_cellid_from_segid(fanc_latestid("648518346486614449"))
#' }
fanc_segid_from_cellid <- function(cellids=NULL, timestamp=NULL, version=NULL, rval=c("ids", 'data.frame'), integer64=FALSE, cellid_table = 'cell_ids') {
fanc_segid_from_cellid <- function(cellids=NULL, timestamp=NULL, version=NULL, rval=c("ids", 'data.frame'), integer64=FALSE, cellid_table = NULL) {
rval=match.arg(rval)
if(is.null(cellid_table))
cellid_table=fanc_cellid_table()
if(!is.null(cellids)) {
cellids <- checkmate::assert_integerish(cellids, coerce = T)
idlist=list(id=cellids)
Expand All @@ -254,3 +256,12 @@ fanc_segid_from_cellid <- function(cellids=NULL, timestamp=NULL, version=NULL, r
fanc_ids(res[['pt_root_id']][match(cellids, res[['id']])], integer64 = integer64)
} else res
}

# private function to return the latest cellids table
# this is a configurable option in the python package
fanc_cellid_table <- memoise::memoise(function(fac=fanc_cave_client()) {
tables=fac$materialize$tables
tablenames=names(tables)
seltable=rev(sort(grep("cell_ids", tablenames, value = T)))[1]
return(seltable)
})

0 comments on commit 8494bc7

Please sign in to comment.