From 8494bc7dbb8b98c04da3d12e7d1b89558267aa98 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Sat, 16 Mar 2024 11:53:06 +0000 Subject: [PATCH 1/3] add fanc_cellid_table() and use it for cell ids --- R/ids.R | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/R/ids.R b/R/ids.R index 6dd68cf..07dd934 100644 --- a/R/ids.R +++ b/R/ids.R @@ -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 @@ -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) @@ -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) +}) From 0cae869e603b6b2a6c6b4e70052ec620cc596dd8 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Sun, 17 Mar 2024 14:00:55 +0000 Subject: [PATCH 2/3] roxygen update --- DESCRIPTION | 2 +- man/fanc_cave_query.Rd | 2 +- man/fanc_cellid_from_segid.Rd | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 97df3f7..8491f02 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,4 +46,4 @@ Encoding: UTF-8 Language: en-GB LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/man/fanc_cave_query.Rd b/man/fanc_cave_query.Rd index 4a75b38..68b6791 100644 --- a/man/fanc_cave_query.Rd +++ b/man/fanc_cave_query.Rd @@ -7,7 +7,7 @@ fanc_cave_query(table, datastack_name = NULL, live = TRUE, ...) } \arguments{ -\item{table}{The name of the table to query} +\item{table}{The name of the table (or view, see views section) to query} \item{datastack_name}{An optional CAVE \code{datastack_name}. If unset a sensible default is chosen.} diff --git a/man/fanc_cellid_from_segid.Rd b/man/fanc_cellid_from_segid.Rd index d9d7fde..c3501b8 100644 --- a/man/fanc_cellid_from_segid.Rd +++ b/man/fanc_cellid_from_segid.Rd @@ -19,7 +19,7 @@ fanc_segid_from_cellid( version = NULL, rval = c("ids", "data.frame"), integer64 = FALSE, - cellid_table = "cell_ids" + cellid_table = NULL ) } \arguments{ @@ -35,8 +35,8 @@ give only one of \code{version} or \code{timestamp}. When both are missing, ids should match the live materialisation version including up to the second edits.} -\item{cellid_table}{Optional name of cell id table (the default value should -be correct).} +\item{cellid_table}{Optional name of cell id table (the default value of +\code{NULL} should find the correct table).} \item{rval}{Whether to return the cell ids or the whole of the CAVE table with additional columns.} From 7ea1c568083fdab70e4460c190647e11e87cb3a4 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 1 May 2024 18:28:03 +0100 Subject: [PATCH 3/3] fanc_cellid_from_segid also respects latest table --- R/ids.R | 7 ++++++- man/fanc_cellid_from_segid.Rd | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/R/ids.R b/R/ids.R index 07dd934..f9593bf 100644 --- a/R/ids.R +++ b/R/ids.R @@ -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 @@ -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) diff --git a/man/fanc_cellid_from_segid.Rd b/man/fanc_cellid_from_segid.Rd index c3501b8..d4e9455 100644 --- a/man/fanc_cellid_from_segid.Rd +++ b/man/fanc_cellid_from_segid.Rd @@ -9,7 +9,7 @@ fanc_cellid_from_segid( rootids = NULL, timestamp = NULL, version = NULL, - cellid_table = "cell_ids", + cellid_table = NULL, rval = c("ids", "data.frame") ) @@ -54,7 +54,8 @@ character vector or an \code{bit64::integer64} vector depending on the \code{integer64} argument. } \description{ -Convert between FANC cell ids and root ids +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