diff --git a/DESCRIPTION b/DESCRIPTION index 89d8e04..946eb89 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,11 +19,12 @@ Imports: igraph, digest, rappdirs, - memoise + memoise, + purrr Suggests: testthat (>= 0.10), git2r (>= 0.22.1), nabor URL: https://github.com/jefferislab/nat.templatebrains -RoxygenNote: 6.1.1 +RoxygenNote: 6.1.1.9000 Encoding: UTF-8 diff --git a/R/templatebrain.R b/R/templatebrain.R index 0ecfe16..52979bb 100644 --- a/R/templatebrain.R +++ b/R/templatebrain.R @@ -159,9 +159,10 @@ print.templatebrain <- function(x, ...) { cat("Sex: ", x$sex, "\n") cat(sprintf("Dimensions:%d x %d x %d voxels\n", x$dims[1], x$dims[2], x$dims[3])) cat(paste0("Voxel size:\n")) - cat(" x =", paste0(x$voxdims[1], " ", x$units[1], "\n")) - cat(" y =", paste0(x$voxdims[2], " ", x$units[2], "\n")) - cat(" z =", paste0(x$voxdims[3], " ", x$units[3], "\n")) + dimension_names = c('x','y','z') + for (dimidx in 1:length(x$voxdims)) { + cat(" ",dimension_names[dimidx] ,"=", paste0(x$voxdims[dimidx], " ", + purrr::pluck(x$units,dimidx,.default = x$units[1]), "\n")) } cat(paste0("Bounding box (", x$units[1], "):\n")) cat(" x =", paste0(x$BoundingBox[1, 1], ", y = ", x$BoundingBox[1, 2], ", z = ", x$BoundingBox[1, 3], ",\n")) cat(" x =", paste0(x$BoundingBox[2, 1], ", y = ", x$BoundingBox[2, 2], ", z = ", x$BoundingBox[2, 3], ".\n")) diff --git a/R/transformation.R b/R/transformation.R index 1761628..c1fb0c2 100644 --- a/R/transformation.R +++ b/R/transformation.R @@ -185,6 +185,21 @@ allreg_dataframe<-function(regdirs=getOption('nat.templatebrains.regdirs')) { #' plot(bridging_graph(), vertex.size=25) #' } bridging_graph <- function(regdirs=getOption('nat.templatebrains.regdirs'), reciprocal=NA) { + sha512=digest(list(regdirs, reciprocal), algo = "sha512") + bg=.bridging_graph[[sha512]] + if(is.null(bg)){ + bg=make_bridging_graph(regdirs, reciprocal) + .bridging_graph[[sha512]]=bg + } + bg +} + +set_bridging_graph <- function(bg, regdirs=getOption('nat.templatebrains.regdirs'), reciprocal=NA) { + sha512=digest(list(regdirs, reciprocal), algo = "sha512") + .bridging_graph[[sha512]]=bg +} + +make_bridging_graph <- function(regdirs, reciprocal) { df=allreg_dataframe(regdirs) if(nrow(df)==0) return(NULL) # just keep the bridging registrations @@ -205,10 +220,15 @@ bridging_graph <- function(regdirs=getOption('nat.templatebrains.regdirs'), reci g } + + + + #' @importFrom memoise forget memoise reset_cache <- function() { - memoise::forget(shortest_bridging_seq) - memoise::memoise(shortest_bridging_seq) + # memoise::forget(shortest_bridging_seq) + # memoise::memoise(shortest_bridging_seq) + rm(list=ls(.bridging_graph), envir = .bridging_graph) } #' @description \code{shortest_bridging_seq} finds the shortest bridging diff --git a/R/zzz.R b/R/zzz.R index cbdf437..b24f45d 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -7,3 +7,5 @@ invisible() } + +.bridging_graph <- new.env() diff --git a/tests/testthat/test-template-brain-data.r b/tests/testthat/test-template-brain-data.r index b37f223..5be8969 100644 --- a/tests/testthat/test-template-brain-data.r +++ b/tests/testthat/test-template-brain-data.r @@ -64,4 +64,9 @@ test_that("as.templatebrain.im3d works", { test_that("print.templatebrain",{ expect_output(print(FCWB.demo), "Name: FlyCircuit Whole Brain") + + #Check if it can cycle through units that are not explicity given (for e.g. y and z direction units) + dummy_templatebrain <- as.templatebrain(im3d(dims = c(3,4),voxdims = c(2,3,4)), regName="FAFB", name='Full Adult') + dummy_templatebrain$units = 'nm' + expect_output(print(dummy_templatebrain), "\\nVoxel size:\\n x = 2 nm\\n y = 3 nm\\n z = 4 nm") })