From 3426922ed1142dd6161b0708e1d8123391be0b04 Mon Sep 17 00:00:00 2001 From: alexanderbates Date: Thu, 23 Jan 2020 14:10:39 +0000 Subject: [PATCH 1/2] Harmonising approach to dataset specification * Feed neuprint_fetch_custom a dataset argument --- R/connectivity.R | 8 ++++---- R/dump.R | 2 +- R/fetch.R | 8 ++++---- R/name.R | 8 ++++---- R/neurons.R | 2 +- R/roi.R | 2 +- R/soma.R | 2 +- R/synapses.R | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/R/connectivity.R b/R/connectivity.R index f903e902..07eb7794 100644 --- a/R/connectivity.R +++ b/R/connectivity.R @@ -25,7 +25,7 @@ neuprint_get_adjacency_matrix <- function(bodyids, dataset = NULL, all_segments namefield, namefield ) - nc = neuprint_fetch_custom(cypher=cypher, conn = conn, ...) + nc = neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, ...) m = matrix(0,nrow = length(bodyids),ncol = length(bodyids)) rownames(m) = colnames(m) = bodyids for(i in 1:length(nc$data)){ @@ -86,7 +86,7 @@ neuprint_connection_table <- function(bodyids, prepost = c("PRE","POST"), roi = ifelse(prepost=="POST","bodyid","partner"), ifelse(prepost=="POST","partner","bodyid") ) - nc = neuprint_fetch_custom(cypher=cypher, conn = conn) + nc = neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, ...) ## Filter out the rare cases where PSDs and tbars are in different ROIs (hence post is null) nc$data <- nc$data[sapply(nc$data,function(x) !is.null(x[[4]]))] d <- data.frame(do.call(rbind,lapply(nc$data,unlist)),stringsAsFactors = FALSE) @@ -265,7 +265,7 @@ neuprint_get_paths <- function(body_pre,body_post,n,weightT=5,roi=NULL,dataset = ifelse(is.null(roi),"",roi) ) - nc <- neuprint_fetch_custom(cypher=cypher, conn = conn) + nc <- neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, ...) connTable <- dplyr::bind_rows(lapply(nc$data, function(d){ l <- d[[1]] @@ -331,7 +331,7 @@ neuprint_get_shortest_paths <- function(body_pre,body_post,weightT=5,roi=NULL,da ifelse(is.null(roi),"",roi) ) - nc <- neuprint_fetch_custom(cypher=cypher, conn = conn) + nc <- neuprint_fetch_custom(cypher=cypher, conn = conn, dataset=dataset, ...) connTable <- dplyr::bind_rows(lapply(nc$data, function(d){ l <- d[[1]] diff --git a/R/dump.R b/R/dump.R index 3560fe8d..3711e5fb 100644 --- a/R/dump.R +++ b/R/dump.R @@ -17,7 +17,7 @@ #' @rdname neuprint_dump #' @importFrom nat write.neurons neuprint_dump <- function(dir, bodyids = NULL, roi = NULL, preprocess = NULL, connectivity = TRUE, volumes = TRUE, - meta = TRUE, nat = TRUE, drvid = TRUE, flow.centrality = FALSE, soma = TRUE, estimate.soma = FALSE, + meta = TRUE, nat = TRUE, drvid = FALSE, flow.centrality = FALSE, soma = TRUE, estimate.soma = FALSE, heal = TRUE, connectors = TRUE, all_segments = TRUE, resample = FALSE, scale = 4, voxel.thresh = 1e+07, split = c("postsynapses","presynapses","distance"), dataset = NULL, conn=NULL, OmitFailures = TRUE, ...){ diff --git a/R/fetch.R b/R/fetch.R index 38468e3a..bd3229a7 100644 --- a/R/fetch.R +++ b/R/fetch.R @@ -92,7 +92,7 @@ neuprint_list2df <- function(x, cols=NULL, return_empty_df=FALSE, ...) { } #' @importFrom memoise memoise -neuprint_name_field <- memoise(function(conn=NULL) { +neuprint_name_field <- memoise(function(conn=NULL, dataset = NULL) { if (is.null(conn)) stop( "You must do\n conn = neuprint_login(conn)\n", @@ -100,7 +100,7 @@ neuprint_name_field <- memoise(function(conn=NULL) { call. = FALSE ) q="MATCH (n :hemibrain_Neuron) WHERE exists(n.instance) RETURN count(n)" - n=unlist(neuprint_fetch_custom(q, include_headers=F)[['data']]) + n=unlist(neuprint_fetch_custom(q, dataset = dataset, include_headers=F)[['data']]) return(ifelse(n>0, "instance", "name")) }) @@ -113,7 +113,7 @@ neuprint_dataset_prefix <- memoise(function(dataset, conn=NULL) { call. = FALSE ) # q=sprintf("MATCH (n:`%s_Segment`) RETURN count(n)", dataset) - # n=unlist(neuprint_fetch_custom(q, include_headers=F)[['data']]) + # n=unlist(neuprint_fetch_custom(q, dataset = dataset, include_headers=F)[['data']]) #paste0(dataset, ifelse(n>0, "_", "-")) # I think we no longer need to specify the dataset. Might be good to keep this function in place though, in case situation changes "" }) @@ -126,7 +126,7 @@ check_dataset <- function(dataset=NULL) { # Get a default dataset if none spec warning("Please supply a dataset or set a default one using the ", "neuprint_dataset environment variable! See ?neuprint_login for details. For now we will use hemibrain:v1.0") - dataset = "hemibrain:1.0" + dataset = "hemibrain:v1.0" } } dataset diff --git a/R/name.R b/R/name.R index 2df9fb1b..1e2e807f 100644 --- a/R/name.R +++ b/R/name.R @@ -16,7 +16,7 @@ neuprint_get_neuron_names <- function(bodyids, dataset = NULL, all_segments = TR cypher = sprintf("WITH %s AS bodyIds UNWIND bodyIds AS bodyId MATCH (n:`%s`) WHERE n.bodyId=bodyId RETURN n.instance AS name", jsonlite::toJSON(as.numeric(unlist(bodyids))), paste0(dp,all_segments)) - nc = neuprint_fetch_custom(cypher=cypher, conn = conn, ...) + nc = neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, ...) d = unlist(lapply(nc$data,nullToNA)) names(d) = bodyids d @@ -47,7 +47,7 @@ neuprint_get_meta <- function(bodyids, dataset = NULL, all_segments = TRUE, conn paste0(dp, all_segments), neuprint_name_field(conn) ) - nc = neuprint_fetch_custom(cypher=cypher, conn = conn, include_headers = FALSE, ...) + nc = neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, include_headers = FALSE, ...) neuprint_list2df(nc, return_empty_df = TRUE) } @@ -71,7 +71,7 @@ neuprint_get_roiInfo <- function(bodyids, dataset = NULL, all_segments = TRUE, c jsonlite::toJSON(as.numeric(unlist(bodyids))), paste0(dp, all_segments) ) - nc = neuprint_fetch_custom(cypher=cypher, conn = conn, ...) + nc = neuprint_fetch_custom(cypher=cypher, dataset = dataset, conn = conn, ...) lc <- lapply(nc$data,function(x){cbind(bodyid=x[[1]],as.data.frame(t(unlist(jsonlite::fromJSON(x[[2]])))))}) d <- dplyr::bind_rows(lc) d @@ -103,7 +103,7 @@ neuprint_search <- function(search, meta = TRUE, all_segments = TRUE, dataset = paste0(dp, all_segments.cypher), neuprint_name_field(conn), search) - nc = neuprint_fetch_custom(cypher=cypher, ...) + nc = neuprint_fetch_custom(cypher=cypher, dataset = dataset, ...) foundbodyids=unlist(nc$data) if(meta && isTRUE(length(foundbodyids)>0)){ neuprint_get_meta(bodyids = foundbodyids, dataset = dataset, all_segments = all_segments, conn = conn, ...) diff --git a/R/neurons.R b/R/neurons.R index 0ff2864a..443033f4 100644 --- a/R/neurons.R +++ b/R/neurons.R @@ -105,7 +105,7 @@ neuprint_read_neuron <- function(bodyid, n = drvid::read.neuron.dvid(bodyid) d = n$d }else{ - n = neuprint_read_neuron_simple(as.numeric(bodyid),dataset=dataset,conn = conn,heal = FALSE,...) + n = neuprint_read_neuron_simple(as.numeric(bodyid),dataset=dataset,conn = conn, heal = FALSE,...) } if(heal|flow.centrality){ n = suppressWarnings( heal_skeleton(x = n) ) diff --git a/R/roi.R b/R/roi.R index 09a59969..2e82fd59 100644 --- a/R/roi.R +++ b/R/roi.R @@ -60,7 +60,7 @@ neuprint_bodies_in_ROI <- function(roi, dataset = NULL, all_segments = FALSE, co roi, roi, roi) - nc = neuprint_fetch_custom(cypher=cypher, conn = conn, ...) + nc = neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, ...) d = data.frame(do.call(rbind,lapply(nc$data,unlist))) colnames(d) = unlist(nc$columns) d diff --git a/R/soma.R b/R/soma.R index 1b9244c3..0754ef6e 100644 --- a/R/soma.R +++ b/R/soma.R @@ -18,7 +18,7 @@ neuprint_locate_soma <- function(bodyids, dataset = NULL, all_segments = TRUE, c cypher = sprintf("WITH %s AS bodyIds UNWIND bodyIds AS bodyId MATCH (n:`%s`) WHERE n.bodyId=bodyId RETURN n.bodyId AS bodyId, n.somaLocation AS soma", jsonlite::toJSON(as.numeric(unique(bodyids))), paste0(dp, all_segments.json)) - nc = neuprint_fetch_custom(cypher=cypher, conn = conn, ...) + nc = neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, ...) if(length(nc$data)==0){ coordinates = matrix(c(NA,NA,NA),nrow=length(bodyids),ncol=3) coordinates = cbind(data.frame(bodyid=bodyids),coordinates) diff --git a/R/synapses.R b/R/synapses.R index dcc6ee5c..4604b2ab 100644 --- a/R/synapses.R +++ b/R/synapses.R @@ -75,7 +75,7 @@ neuprint_get_synapses <- function(bodyids, roi = NULL, progress = FALSE, dataset prefixed_seg, prefixed_seg, roi) - nc.post = neuprint_fetch_custom(cypher=cypher.post, conn = conn, ...) + nc.post = neuprint_fetch_custom(cypher=cypher.post, conn = conn, dataset = dataset, ...) nc.pre = neuprint_fetch_custom(cypher=cypher.pre, conn = conn, ...) m = rbind(do.call(rbind,nc.post$data),do.call(rbind,nc.pre$data)) colnames(m) = nc.post$columns From e101c60fa3c5eca7a9fd909c0db99935dc3caba0 Mon Sep 17 00:00:00 2001 From: alexanderbates Date: Thu, 23 Jan 2020 14:38:13 +0000 Subject: [PATCH 2/2] Update neuprint_dump.Rd --- man/neuprint_dump.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/neuprint_dump.Rd b/man/neuprint_dump.Rd index 1f96c2e4..d299d876 100644 --- a/man/neuprint_dump.Rd +++ b/man/neuprint_dump.Rd @@ -13,7 +13,7 @@ neuprint_dump( volumes = TRUE, meta = TRUE, nat = TRUE, - drvid = TRUE, + drvid = FALSE, flow.centrality = FALSE, soma = TRUE, estimate.soma = FALSE,