Skip to content

Commit

Permalink
Add mirror_banc
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferis committed Jul 1, 2024
1 parent 2498abf commit 7ee26fc
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Imports:
jsonlite,
pbapply,
dplyr,
checkmate
checkmate,
utils
Suggests:
testthat (>= 3.0.0),
reticulate,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export(fanc_segid_from_cellid)
export(fanc_set_token)
export(fanc_voxdims)
export(fanc_xyz2id)
export(mirror_banc)
export(read_fanc_meshes)
export(transform_fanc2manc)
export(with_banc)
Expand Down
12 changes: 12 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@
#' boundingbox(BANC)
"BANC"

#' Provisional mirroring registration for BANC (lanmarks+thin plate splines)
#'
#' @name mirror_banc_lm
#' @docType data
#' @description This is calibrated in nm. See \code{data-raw/mirror_banc.R} for
#' details of how it was generated. It is still provisional pending synpase
#' cloud-based registrations.
#'
#' @examples
#' utils::str(mirror_banc_lm)
"mirror_banc_lm"

50 changes: 50 additions & 0 deletions R/xform.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,53 @@ transform_fanc2manc <- function(x, inverse = F, ...) {
reg = fanc_to_manc_reg()
xform(x, reg=reg, swap=inverse,... )
}


#' Mirror points, neurons in BANC space
#'
#' @param x Points, neurons or other objects compatible with \code{xyzmatrix}
#' @param units Units for both input \emph{and} output data.
#' @param subset Optional argument to transform only a subset of a neuron list.
#'
#' @return Trge transformed object (calibrated according to the units argument)
#' @export
#'
#' @examples
#' BANC.surf.m <- mirror_banc(BANC.surf)
#' \dontrun{
#' library(nat)
#' wire3d(BANC.surf)
#' # clearly not great in some places, especially optic lobe, but still useful
#' wire3d(BANC.surf.m, col='red')
#' }
mirror_banc <- function(x, units=c("nm", "microns", "raw"), subset=NULL) {
units=match.arg(units)

if(!is.null(subset)) {
xs=x[subset]
xst=mirror_banc(xs, units = units, mirror_reg = fancr::mirror_banc_lm)
x[subset]=xst
return(x)
}
BANCmesh=templatebrain("BANC",
BoundingBox = structure(c(79392.9, 966179.9, 35524.5, 1131169.6, -62.8, 315466.7
), dim = 2:3, class = "boundingbox"))
# convert to nm if necessary
xyz=xyzmatrix(x)
if(units=='microns')
xyz=xyz*1e3
else if(units=='raw')
xyz=banc_raw2nm(xyz)

xyzf=mirror_brain(x, brain = BANCmesh, mirrorAxis = 'X', transform = 'flip')
xyzf2=xform(xyzf, reg = fancr::mirror_banc_lm)

# convert from nm to original units if necessary
if(units=='microns')
xyzf2=xyzf2/1e3
else if(units=='raw')
xyzf2=banc_nm2raw(xyzf2)

xyzmatrix(x)=xyzf2
x
}
17 changes: 17 additions & 0 deletions data-raw/mirror-banc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# construct a mirroring registration from landmarks
mirror_banc_tps <- function(anns) {
if(is.character(anns)) {
anns=ngl_annotations(anns)
}
AB=rbind(banc_raw2nm(anns$pointA), banc_raw2nm(anns$pointB))
BA=rbind(banc_raw2nm(anns$pointB), banc_raw2nm(anns$pointA))
# have decided to use this rather than "official" space
BANCmesh=nat.templatebrains::templatebrain("BANC",
BoundingBox = structure(c(79392.9, 966179.9, 35524.5, 1131169.6, -62.8, 315466.7), dim = 2:3, class = "boundingbox"))
ABf=nat.templatebrains::mirror_brain(AB, brain = BANCmesh, mirrorAxis = 'X', transform = 'flip')
delta=BA-ABf
tpsreg(sample = ABf, reference = BA)
}
mirror_banc_lm=mirror_banc_tps('https://spelunker.cave-explorer.org/#!middleauth+https://global.daf-apis.com/nglstate/api/v1/5486159028289536')

usethis::use_data(mirror_banc_lm, overwrite = TRUE)
Binary file added data/mirror_banc_lm.rda
Binary file not shown.
30 changes: 30 additions & 0 deletions man/mirror_banc.Rd

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

21 changes: 21 additions & 0 deletions man/mirror_banc_lm.Rd

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

0 comments on commit 7ee26fc

Please sign in to comment.