Skip to content

Commit

Permalink
Merge pull request #7 from flyconnectome/feature/cell_ids-update
Browse files Browse the repository at this point in the history
add fanc_cellid_table() and use it for cell ids
  • Loading branch information
jefferis authored Jun 1, 2024
2 parents 19b38b2 + 7ea1c56 commit effc489
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ Encoding: UTF-8
Language: en-GB
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
24 changes: 20 additions & 4 deletions R/ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ fanc_ids <- function(x, integer64=NA) {

#' Convert between FANC cell ids and root ids
#'
#' @description Converts between FANC cell ids (should survive most edits) and
#' root ids (guaranteed to match just one edit state). See details.
#'
#' @details CAVE/PyChunkedGraph assigns a 64 bit integer root id to all bodies
#' in the segmentation. These root ids are persistent in a computer science
#' sense, which is often the exact opposite of what neuroscientists might
Expand Down Expand Up @@ -188,8 +191,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 All @@ -202,8 +205,10 @@ fanc_ids <- function(x, integer64=NA) {
#' \donttest{
#' fanc_cellid_from_segid(fanc_latestid("648518346486614449"))
#' }
fanc_cellid_from_segid <- function(rootids=NULL, timestamp=NULL, version=NULL, cellid_table = 'cell_ids', rval=c("ids", 'data.frame')) {
fanc_cellid_from_segid <- function(rootids=NULL, timestamp=NULL, version=NULL, cellid_table = NULL, rval=c("ids", 'data.frame')) {
rval=match.arg(rval)
if(is.null(cellid_table))
cellid_table=fanc_cellid_table()
if(!is.null(rootids)) {
rootids=fanc_ids(rootids, integer64=F)
idlist=list(pt_root_id=rootids)
Expand Down Expand Up @@ -233,8 +238,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 +261,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)
})
2 changes: 1 addition & 1 deletion man/fanc_cave_query.Rd

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

11 changes: 6 additions & 5 deletions man/fanc_cellid_from_segid.Rd

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

0 comments on commit effc489

Please sign in to comment.