diff --git a/R/connectivity.R b/R/connectivity.R index 07eb7794..4ef0aa42 100644 --- a/R/connectivity.R +++ b/R/connectivity.R @@ -9,7 +9,7 @@ neuprint_get_adjacency_matrix <- function(bodyids, dataset = NULL, all_segments = TRUE, conn = NULL, ...){ dataset <- check_dataset(dataset) conn=neuprint_login(conn) - dp=neuprint_dataset_prefix(dataset, conn=conn) + #dp=neuprint_dataset_prefix(dataset, conn=conn) all_segments.json = ifelse(all_segments,"Segment","Neuron") namefield=neuprint_name_field(conn) cypher = sprintf( @@ -21,7 +21,7 @@ neuprint_get_adjacency_matrix <- function(bodyids, dataset = NULL, all_segments jsonlite::toJSON(as.numeric(unique(unlist( bodyids )))), - paste0(dataset, "_", all_segments.json), + all_segments.json, namefield, namefield ) @@ -71,7 +71,7 @@ neuprint_connection_table <- function(bodyids, prepost = c("PRE","POST"), roi = } dp=neuprint_dataset_prefix(dataset, conn=conn) - prefixed=paste0(dp, all_segments.json) + #prefixed=paste0(dp, all_segments.json) cypher = sprintf(paste("WITH %s AS bodyIds UNWIND bodyIds AS bodyId", "MATCH (a:`%s`)-[c:ConnectsTo]->(b:`%s`)", "WHERE %s.bodyId=bodyId", @@ -79,8 +79,8 @@ neuprint_connection_table <- function(bodyids, prepost = c("PRE","POST"), roi = "RETURN a.bodyId AS %s, b.bodyId AS %s, k AS roi,", "apoc.convert.fromJsonMap(c.roiInfo)[k].post AS weight"), jsonlite::toJSON(unique(as.numeric(unlist(bodyids)))), - prefixed, - prefixed, + all_segments.json, + all_segments.json, ifelse(prepost=="POST","a","b"), ifelse(is.null(roi),"keys(apoc.convert.fromJsonMap(c.roiInfo))",paste("['",paste(roi,collapse="','"),"']",sep="")), ifelse(prepost=="POST","bodyid","partner"), @@ -179,11 +179,11 @@ neuprint_simple_connectivity <- function(bodyids, dataset <- check_dataset(dataset) find_inputs = ifelse(prepost=="PRE", "false","true") if(length(bodyids)>10){ - m = do.call(rbind, pbapply::pblapply(bodyids, function(bi) tryCatch(neuprint_simple_connectivity( + m = Reduce(function(x,y,...) dplyr::full_join(x,y,by=c("name",ifelse(prepost=="PRE","output","input"),"type")),(pbapply::pblapply(bodyids, function(bi) tryCatch(neuprint_simple_connectivity( bodyids = bi, prepost = prepost, dataset = dataset, conn = conn, ...), - error = function(e) NULL))) + error = function(e) NULL)))) return(m) } Payload = noquote(sprintf('{"dataset":"%s","neuron_ids":%s,"find_inputs":%s}', @@ -244,8 +244,8 @@ neuprint_get_paths <- function(body_pre,body_post,n,weightT=5,roi=NULL,dataset = } all_segments.json <- ifelse(all_segments,"Segment","Neuron") - dp <- neuprint_dataset_prefix(dataset, conn=conn) - prefixed <- paste0(dp, all_segments.json) + #dp <- neuprint_dataset_prefix(dataset, conn=conn) + #prefixed <- paste0(dp, all_segments.json) cypher <- sprintf(paste("WITH [%s,%s] AS bodies", "UNWIND bodies[0] AS bodypre", @@ -257,10 +257,10 @@ neuprint_get_paths <- function(body_pre,body_post,n,weightT=5,roi=NULL,dataset = ), jsonlite::toJSON(unique(as.numeric(unlist(body_pre)))), jsonlite::toJSON(unique(as.numeric(unlist(body_post)))), - prefixed, + all_segments.json, n[1]-1, n[2], - prefixed, + all_segments.json, weightT, ifelse(is.null(roi),"",roi) ) @@ -306,8 +306,8 @@ neuprint_get_shortest_paths <- function(body_pre,body_post,weightT=5,roi=NULL,da dataset <- check_dataset(dataset) conn <- neuprint_login(conn) all_segments.json <- ifelse(all_segments,"Segment","Neuron") - dp <- neuprint_dataset_prefix(dataset, conn=conn) - prefixed <- paste0(dp, all_segments.json) + #dp <- neuprint_dataset_prefix(dataset, conn=conn) + #prefixed <- paste0(dp, all_segments.json) if(!is.null(roi)){ roicheck = neuprint_check_roi(rois=roi, dataset = dataset, conn = conn, ...) @@ -325,8 +325,8 @@ neuprint_get_shortest_paths <- function(body_pre,body_post,weightT=5,roi=NULL,da ), jsonlite::toJSON(unique(as.numeric(unlist(body_pre)))), jsonlite::toJSON(unique(as.numeric(unlist(body_post)))), - prefixed, - prefixed, + all_segments.json, + all_segments.json, weightT, ifelse(is.null(roi),"",roi) ) diff --git a/R/name.R b/R/name.R index 1e2e807f..301f72b9 100644 --- a/R/name.R +++ b/R/name.R @@ -11,11 +11,12 @@ neuprint_get_neuron_names <- function(bodyids, dataset = NULL, all_segments = TRUE, conn = NULL, ...){ dataset <- check_dataset(dataset) conn=neuprint_login(conn) - dp=neuprint_dataset_prefix(dataset, conn=conn) - all_segments = ifelse(all_segments,"Segment","Neuron") + + all_segments.json = ifelse(all_segments,"Segment","Neuron") 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)) + all_segments.json) + nc = neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, ...) d = unlist(lapply(nc$data,nullToNA)) names(d) = bodyids @@ -36,7 +37,7 @@ neuprint_get_meta <- function(bodyids, dataset = NULL, all_segments = TRUE, conn dataset <- check_dataset(dataset) all_segments = ifelse(all_segments,"Segment","Neuron") conn=neuprint_login(conn) - dp=neuprint_dataset_prefix(dataset, conn=conn) + #dp=neuprint_dataset_prefix(dataset, conn=conn) cypher = sprintf( paste( "WITH %s AS bodyIds UNWIND bodyIds AS bodyId ", @@ -44,7 +45,7 @@ neuprint_get_meta <- function(bodyids, dataset = NULL, all_segments = TRUE, conn "RETURN n.bodyId AS bodyid, n.%s AS name, n.type AS type, n.status AS status, n.size AS voxels, n.pre AS pre, n.post AS post, n.cropped AS cropped" ), jsonlite::toJSON(as.numeric(unlist(bodyids))), - paste0(dp, all_segments), + all_segments, neuprint_name_field(conn) ) nc = neuprint_fetch_custom(cypher=cypher, conn = conn, dataset = dataset, include_headers = FALSE, ...) @@ -64,12 +65,12 @@ neuprint_get_meta <- function(bodyids, dataset = NULL, all_segments = TRUE, conn neuprint_get_roiInfo <- function(bodyids, dataset = NULL, all_segments = TRUE, conn = NULL, ...){ dataset <- check_dataset(dataset) conn=neuprint_login(conn) - dp=neuprint_dataset_prefix(dataset, conn=conn) + #dp=neuprint_dataset_prefix(dataset, conn=conn) all_segments = ifelse(all_segments,"Segment","Neuron") cypher = sprintf( "WITH %s AS bodyIds UNWIND bodyIds AS bodyId MATCH (n:`%s`) WHERE n.bodyId=bodyId RETURN n.bodyId AS bodyid, n.roiInfo AS roiInfo", jsonlite::toJSON(as.numeric(unlist(bodyids))), - paste0(dp, all_segments) + all_segments ) 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]])))))}) @@ -97,10 +98,10 @@ neuprint_get_roiInfo <- function(bodyids, dataset = NULL, all_segments = TRUE, c neuprint_search <- function(search, meta = TRUE, all_segments = TRUE, dataset = NULL, conn = NULL, ...){ dataset <- check_dataset(dataset) conn=neuprint_login(conn) - dp=neuprint_dataset_prefix(dataset, conn=conn) + # dp=neuprint_dataset_prefix(dataset, conn=conn) all_segments.cypher = ifelse(all_segments,"Segment","Neuron") cypher = sprintf("MATCH (n:`%s`) WHERE n.%s=~'%s' RETURN n.bodyId", - paste0(dp, all_segments.cypher), + all_segments.cypher, neuprint_name_field(conn), search) nc = neuprint_fetch_custom(cypher=cypher, dataset = dataset, ...) diff --git a/R/roi.R b/R/roi.R index 2e82fd59..cc318129 100644 --- a/R/roi.R +++ b/R/roi.R @@ -52,11 +52,11 @@ neuprint_find_neurons <- function(input_ROIs, neuprint_bodies_in_ROI <- function(roi, dataset = NULL, all_segments = FALSE, conn = NULL, ...){ dataset <- check_dataset(dataset) conn=neuprint_login(conn) - dp=neuprint_dataset_prefix(dataset, conn=conn) + #dp=neuprint_dataset_prefix(dataset, conn=conn) all_segments = ifelse(all_segments,"Segment","Neuron") roicheck = neuprint_check_roi(rois=roi, dataset = dataset, conn = conn, ...) cypher = sprintf("MATCH (n :`%s`) WHERE n.%s WITH n AS n, apoc.convert.fromJsonMap(n.roiInfo) AS roiInfo RETURN n.bodyId AS bodyid, n.size AS voxels, n.pre, n.post, roiInfo.%s.pre, roiInfo.%s.post", - paste0(dp, all_segments), + all_segments, roi, roi, roi)