Skip to content

Commit

Permalink
Let banc_updateids use super voxel IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbates committed Aug 29, 2024
1 parent 8f35bbd commit 6a7464c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions R/ggplot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ banc_neuron_comparison_plot <- function(neuron1 = NULL,
#' Plot a neuron in the BANC connectomic dataset using ggplot2
#'
#' This function visualizes a neuron or neuron-related object from the BANC connectomic dataset using ggplot2.
#' The only thing specific to the BANC data set is are the prreset 'view' angles.
#'
#' @param x A 'neuron', 'neuronlist', 'mesh3d', or 'hxsurf' object to be visualized.
#' @param volume A brain/neuropil volume to be plotted in grey, for context.
Expand Down
45 changes: 37 additions & 8 deletions R/ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,44 @@ banc_latestid <- function(rootid, sample=1000L, cloudvolume.url=NULL, Verbose=FA

#' @export
#' @rdname banc_latestid
banc_updateids <- function(rootid, ...){
old <- !banc_islatest(rootid, ...)
old[is.na(old)] <- TRUE
#cat("latest/outdated: ",table(old))
updated <- banc_latestid(rootid[old], ...)
rootid[old] <- updated
rootid
}
banc_updateids <- function(x, ...){
if(is.data.frame(x)){
# what needs updating?
root.col <- intersect(c("root_id","pt_root_id"),colnames(x))[1]
if(!length(root.col)){
root.col <- "root_id"
}
if(any(c("root_id","pt_root_id")%in%colnames(x))){
old <- !banc_islatest(x[[root.col]], ...)
}else{
old <- rep(TRUE,nrow(x))
}

# update based on supervoxels
if(any(c("supervoxel_id","pt_supervoxel_id")%in%colnames(x))){
svid.col <- intersect(c("supervoxel_id","pt_supervoxel_id"),colnames(x))[1]
x[old,][[root.col]] <- banc_root(x[old,][[svid.col]], ...)
new <- is.na(x[old,][[svid.col]])|x[old,][[root.col]]=="0"
old <- old+!new
}

# update based on root Ids
if(any(c("root_id","pt_root_id")%in%colnames(x)) && any(sum(old))){
x[old,][[root.col]] <- banc_latestid(x[old,][[root.col]], ...)
new <- is.na(x[old,][[root.col]])|x[old,][[root.col]]=="0"
old <- old+!new
if(sum(old)){
warning("Failed to update: ", sum(old))
}
}
}else{
old <- !banc_islatest(x, ...)
old[is.na(old)] <- TRUE
updated <- banc_latestid(x[old], ...)
x[old] <- updated
x
}
}
#' Return a vector of banc root ids from diverse inputs
#'
#' @param x A data.frame, URL or vector of ids
Expand Down

0 comments on commit 6a7464c

Please sign in to comment.