Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bridging graph environment #41

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions R/templatebrain.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
24 changes: 22 additions & 2 deletions R/transformation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

invisible()
}

.bridging_graph <- new.env()
5 changes: 5 additions & 0 deletions tests/testthat/test-template-brain-data.r
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})