Skip to content

Commit

Permalink
Added neuropil meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbates committed Jul 4, 2024
1 parent fde9b39 commit eff17ef
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 31 deletions.
21 changes: 19 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,27 @@
#' }
"banc.surf"

# How it was obtained:
#' @export
#' @rdname banc.surf
"banc_neuropil.surf"

#' @export
#' @rdname banc.surf
"banc_brain_neuropil.surf"

#' @export
#' @rdname banc.surf
"banc_vnc_neuropil.surf"

#' @export
#' @rdname banc.surf
"banc_neck_connective.surf"

## How it was obtained:
# res <- httr::GET("https://www.googleapis.com/storage/v1/b/zetta_lee_fly_cns_001_kisuk/o/final%2Fv2%2Fvolume_meshes%2Fmeshes%2F1%3A0.drc?alt=media&neuroglancer=610000b05b6497edcf20b78f29516970")
# httr::stop_for_status(res)
# bytes <- httr::content(res, as = "raw")
# banc.mesh <- decode_neuroglancer_mesh(bytes)
# banc.mesh <- malevnc:::decode_neuroglancer_mesh(bytes)
# banc.surf <- as.hxsurf(banc.mesh)
# banc.surf$Vertices[,"Z"] <- banc.surf$Vertices[,"Z"]*0.9462 # scaling Jasper worked out
# save(banc.surf, file="data/BANC.surf.rda")
2 changes: 1 addition & 1 deletion R/meshes.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ banc_decapitate <- function(x, invert = FALSE, reference = "BANC"){
v3 <- nat.templatebrains::xform_brain(v3, sample = "BANC", reference = reference)
y.cut <- v1[,2]
}
ismesh <- any(class(x[[1]]), class(x)) %in% "mesh3d"
ismesh <- any( c(class(x[[1]]), class(x)) %in% "mesh3d")
if(!ismesh & any(class(x)%in%c("neuron","neuronlist","mesh3d"))){
if (invert){
z <- subset(x,x$y<y.cut)
Expand Down
28 changes: 19 additions & 9 deletions R/synapses.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param overwrite Logical, whether or not to overwrite an extant \code{banc_data.sqlite} file.
#' @param n_max Numeric, the maximum number of rows ot read from \code{path} if you just want to see
#' a taster of the file.
#' @param Logical Whether or not to read all data columns in the target synapse \code{.csv}. Defaults to
#' @param details Logical Whether or not to read all data columns in the target synapse \code{.csv}. Defaults to
#' \code{FALSE} in order to read only the essential presynapse position data.
#'
#' @return a data.frame
Expand All @@ -20,10 +20,13 @@
#' \dontrun{
#' syns <- banc_all_synapses()
#' }
#' Helpful scene: https://spelunker.cave-explorer.org/#!middleauth+https://global.daf-apis.com/nglstate/api/v1/4753860997414912
banc_all_synapses <- function(path = "gs://zetta_lee_fly_cns_001_synapse/240623_run/assignment/final_edgelist.df",
overwrite = FALSE,
n_max = 2000,
details = FALSE){
details = FALSE,
min_size = 10,
rawcoords = FALSE){

# Correct path to de-authenticate it, use https
path <- gsub("^gs\\:\\/","https://storage.googleapis.com",path)
Expand Down Expand Up @@ -63,8 +66,8 @@ banc_all_synapses <- function(path = "gs://zetta_lee_fly_cns_001_synapse/240623_
postsyn_y = readr::col_integer(),
postsyn_z = readr::col_integer(),
clefthash = readr::col_number(),
partnerhash= readr::col_integer(),
size = readr::col_integer()
partnerhash = readr::col_integer(),
size = readr::col_number()
)

# Are we just sampling or going for the full thing?
Expand All @@ -73,7 +76,7 @@ banc_all_synapses <- function(path = "gs://zetta_lee_fly_cns_001_synapse/240623_
syns <- readr::read_csv(file=path, col_types = col.types, lazy = TRUE, n_max = n_max)
}else{
syns <- readr::read_csv(file=path, col_types = col.types, lazy = TRUE, n_max = n_max,
select = c(presyn_segid, presyn_x, presyn_y, presyn_z, size))
col_select = c(presyn_segid, presyn_x, presyn_y, presyn_z, size))
}
return(syns)
}else if (!table_exists|overwrite){
Expand All @@ -82,23 +85,30 @@ banc_all_synapses <- function(path = "gs://zetta_lee_fly_cns_001_synapse/240623_
syns <- readr::read_csv(file=path, col_types = col.types, lazy = TRUE)
}else{
syns <- readr::read_csv(file=path, col_types = col.types, lazy = TRUE,
select = c(presyn_segid, presyn_x, presyn_y, presyn_z, size))
col_select = c(presyn_segid, presyn_x, presyn_y, presyn_z, size))
}

# Process
# # Process
# if(!is.null(min_size)){
# syns <- syns %>%
# dplyr::filter(size>=min_size)
# }
# if(!rawcoords){
# syns[,c("presyn_x", "presyn_y", "presyn_z")] <- bancr::banc_raw2nm(syns[,c("presyn_x", "presyn_y", "presyn_z")])
# }

# Connect to the SQLite database
con <- DBI::dbConnect(RSQLite::SQLite(), file_path)

# Write the data frame to the 'synapses' table
# If the table already exists, it will be overwritten
DBI::dbWriteTable(con, "synapses", df, overwrite = TRUE)
DBI::dbWriteTable(con, "synapses", syns, overwrite = TRUE)
DBI::dbDisconnect(con)
message("Added tab synapses, no. rows: ", nrow(syns))
}

# Read
DBI::dbReadTable(con, "synapses")
dplyr::tbl(src = con, from = "synapses")

}

Expand Down
82 changes: 63 additions & 19 deletions R/xform.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,77 @@

# for nm
#' Set Default View for BANC EM Dataset
#'
#' @description
#' This function sets a default view for visualizing the 'BANC' Electron Microscopy (EM) dataset
#' using the rgl package. It adjusts the viewpoint to a specific orientation and zoom level
#' that is optimal for viewing this particular dataset.
#'
#' @details
#' The function uses `rgl::rgl.viewpoint()` to set a predefined user matrix and zoom level.
#' This matrix defines the rotation and translation of the view, while the zoom parameter
#' adjusts the scale of the visualization.
#'
#' @return
#' This function is called for its side effect of changing the rgl viewpoint.
#' It does not return a value.
#'
#' @examples
#' \dontrun{
#' # Assuming you have already plotted your BANC EM data
#' banc_view()
#' }
#'
#' @note
#' This function assumes that an rgl device is already open and that the BANC EM dataset
#' has been plotted. It will not create a new plot or open a new rgl device.
#'
#' @seealso
#' \code{\link[rgl]{rgl.viewpoint}} for more details on setting viewpoints in rgl.
#'
#' @export
banc_view <- function(){
rgl::rgl.viewpoint(userMatrix = structure(c(0.961547076702118, 0.037275392562151,
0.27209860086441, 0, 0.0369537360966206, -0.999296963214874,
0.00630810856819153, 0, 0.272142440080643, 0.00398948788642883,
-0.962248742580414, 0, 0, 0, 0, 1), dim = c(4L, 4L)), zoom = 0.822702646255493)
rgl::rgl.viewpoint(userMatrix = banc_rotation_matrices[["main"]], zoom = 0.82)
}

# for nm
#' @export
#' @rdname banc_view
banc_side_view <- function(){
rgl::rgl.viewpoint(userMatrix = structure(c(0.188666880130768, 0.137750864028931,
-0.972331881523132, 0, 0.130992725491524, -0.98479551076889,
-0.114099271595478, 0, -0.97326534986496, -0.105841755867004,
-0.203842639923096, 0, 0, 0, 0, 1), dim = c(4L, 4L)), zoom = 0.783526360988617)
rgl::rgl.viewpoint(userMatrix = banc_rotation_matrices[["side"]], zoom = 0.29)
}

# for nm
#' @export
#' @rdname banc_view
banc_front_view <- function(){
rgl::rgl.viewpoint(userMatrix = structure(c(0.99931389093399, 0.0139970388263464,
-0.0342894680798054, 0, -0.0321401171386242, -0.132316529750824,
-0.990686297416687, 0, -0.0184037387371063, 0.991108655929565,
-0.131775915622711, 0, 0, 0, 0, 1), dim = c(4L, 4L)), zoom = 0.613913536071777)
rgl::rgl.viewpoint(userMatrix = banc_rotation_matrices[["front"]], zoom = 0.62)
}

# for nm
#' @export
#' @rdname banc_view
banc_vnc_view <- function(){
rgl::rgl.viewpoint(userMatrix = structure(c(0.992902159690857, 0.113465532660484,
0.0356490463018417, 0, 0.103959240019321, -0.973584711551666,
0.203286483883858, 0, 0.0577733889222145, -0.198137611150742,
-0.978470027446747, 0, 33598.359375, 191755.796875, -6508.533203125,
1), dim = c(4L, 4L)), zoom = 0.505068242549896)
rgl::rgl.viewpoint(userMatrix = banc_rotation_matrices[["vnc"]], zoom = 0.51)
}

# hidden
banc_rotation_matrices <- list(
main = structure(c(0.961547076702118, 0.037275392562151,
0.27209860086441, 0, 0.0369537360966206, -0.999296963214874,
0.00630810856819153, 0, 0.272142440080643, 0.00398948788642883,
-0.962248742580414, 0, 0, 0, 0, 1), dim = c(4L, 4L)),
side = structure(c(0.188666880130768, 0.137750864028931,
-0.972331881523132, 0, 0.130992725491524, -0.98479551076889,
-0.114099271595478, 0, -0.97326534986496, -0.105841755867004,
-0.203842639923096, 0, 0, 0, 0, 1), dim = c(4L, 4L)),
front = structure(c(0.99931389093399, 0.0139970388263464,
-0.0342894680798054, 0, -0.0321401171386242, -0.132316529750824,
-0.990686297416687, 0, -0.0184037387371063, 0.991108655929565,
-0.131775915622711, 0, 0, 0, 0, 1), dim = c(4L, 4L)),
vnc = structure(c(0.159858450293541, -0.951453745365143,
0.263022243976593, 0, -0.95634800195694, -0.0832427442073822,
0.280123054981232, 0, -0.244629606604576, -0.296320915222168,
-0.923228204250336, 0, 169877.109375, 8134.845703125, -597.831604003906,
1), dim = c(4L, 4L)))



Binary file modified data/BANC.surf.rda
Binary file not shown.
Binary file added data/banc_brain_neuropil.surf.rda
Binary file not shown.
Binary file added data/banc_neck_connective.surf.rda
Binary file not shown.
Binary file added data/banc_neuropil.surf.rda
Binary file not shown.
Binary file added data/banc_vnc_neuropil.surf.rda
Binary file not shown.

0 comments on commit eff17ef

Please sign in to comment.