Skip to content

Commit

Permalink
use id2char in preference to id2bit64
Browse files Browse the repository at this point in the history
* more robust at (tiny) speed penalty
* id2bit64 still available when you want it and are sure noone is going to treat your vector of ids like a list (which munges the class)
* closes #41
  • Loading branch information
jefferis committed Jan 27, 2020
1 parent ccc60e6 commit a9dd9d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions R/connectivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ neuprint_connection_table <- function(bodyids, prepost = c("PRE","POST"), roi =
prepost = match.arg(prepost)
conn=neuprint_login(conn)
all_segments.json = ifelse(all_segments,"Segment","Neuron")
#
# bodyids=unique(id2bit64(bodyids))
bodyids=unique(id2char(bodyids))
if(!is.null(roi)){
roicheck = neuprint_check_roi(rois=roi, dataset = dataset, conn = conn, ...)
}
Expand Down
2 changes: 1 addition & 1 deletion R/dump.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ neuprint_dump <- function(dir, bodyids = NULL, roi = NULL, preprocess = NULL, co
inroi = neuprint_bodies_in_ROI( roi = roi,
dataset = dataset, conn=conn, ...)
inroi = subset(inroi, voxels>voxel.thresh)
bodyids = unique(c(id2bit64(inroi$bodyid),id2bit64(bodyids)))
bodyids = unique(c(id2char(inroi$bodyid),id2char(bodyids)))
}
# Fetch neuron data
message("Reading neurons from ", conn$server, " for dataset: ", dataset)
Expand Down
6 changes: 6 additions & 0 deletions R/ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ id2bit64 <- function(x) {
}
bit64::as.integer64(x)
}

# this is the easiest thing to use in your functions as character vectors
# never get munged (unlike 64 bit ints, which occasionally lose their class)
id2char <- function(x) {
as.character(id2bit64(x))
}
6 changes: 3 additions & 3 deletions R/neurons.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ neuprint_read_neurons <- function(bodyids,
resample = FALSE,
conn = NULL,
OmitFailures = TRUE, ...) {
neurons = nat::nlapply(id2bit64(bodyids),function(bodyid)
neurons = nat::nlapply(id2char(bodyids),function(bodyid)
neuprint_read_neuron(bodyid=bodyid,
nat=nat,
drvid=drvid,
Expand Down Expand Up @@ -92,7 +92,7 @@ neuprint_read_neuron <- function(bodyid,
n = drvid::read.neuron.dvid(bodyid)
d = n$d
}else{
n = neuprint_read_neuron_simple(id2bit64(bodyid), dataset=dataset,
n = neuprint_read_neuron_simple(id2char(bodyid), dataset=dataset,
conn = conn, heal = FALSE,...)
}
if(heal){
Expand Down Expand Up @@ -207,7 +207,7 @@ heal_skeleton <- function(x, ...){
#' plot(dl1s, WithNode=F)
#' }
neuprint_read_neuron_simple <- function(bodyid, dataset=NULL, conn=NULL, heal=TRUE, ...) {
bodyid=as.character(id2bit64(bodyid))
bodyid=id2char(bodyid)
if(length(bodyid)>1) {
fakenl=structure(bodyid, .Names=bodyid)
nl=nat::nlapply(fakenl, neuprint_read_neuron_simple, dataset=dataset, conn=conn, ...)
Expand Down

0 comments on commit a9dd9d3

Please sign in to comment.