From 7b5422f2ce6b88d7cd9db2093aa7be86bf33220b Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Sun, 9 Feb 2020 18:45:53 +0000 Subject: [PATCH 1/2] fox neuprint_bodies_in_ROI * NB I am not recovering the ROI name int he return column - worth considering if that is best thing to do. --- R/roi.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/roi.R b/R/roi.R index 109fe24c..eff52563 100644 --- a/R/roi.R +++ b/R/roi.R @@ -55,15 +55,16 @@ neuprint_find_neurons <- function(input_ROIs, neuprint_bodies_in_ROI <- function(roi, dataset = NULL, all_segments = FALSE, conn = NULL, ...){ 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", + 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 AS pre, n.post as post, roiInfo.`%s`.pre AS roipre, roiInfo.`%s`.post AS roipost", all_segments, roi, roi, roi) 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 + df=neuprint_list2df(nc, return_empty_df = T) + df$roipre[is.na(df$roipre)]=0 + df$roipost[is.na(df$roipost)]=0 + df } #' @title Get the connectivity between ROIs in a neuPrint dataset From 88e8eca74701c45767e6bbe23f38210d9fb7eb88 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Sun, 9 Feb 2020 18:51:32 +0000 Subject: [PATCH 2/2] Add example and test --- R/roi.R | 5 +++++ tests/testthat/test-roi.R | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/testthat/test-roi.R diff --git a/R/roi.R b/R/roi.R index eff52563..ec8be6e6 100644 --- a/R/roi.R +++ b/R/roi.R @@ -52,6 +52,11 @@ neuprint_find_neurons <- function(input_ROIs, #' @export #' @rdname neuprint_find_neurons +#' @examples +#' \donttest{ +#' lhr=neuprint_bodies_in_ROI('LH(R)') +#' head(lhr) +#' } neuprint_bodies_in_ROI <- function(roi, dataset = NULL, all_segments = FALSE, conn = NULL, ...){ all_segments = ifelse(all_segments,"Segment","Neuron") roicheck = neuprint_check_roi(rois=roi, dataset = dataset, conn = conn, ...) diff --git a/tests/testthat/test-roi.R b/tests/testthat/test-roi.R new file mode 100644 index 00000000..94cc7fd0 --- /dev/null +++ b/tests/testthat/test-roi.R @@ -0,0 +1,6 @@ +skip_if(as.logical(Sys.getenv("SKIP_NP_SERVER_TESTS"))) + +test_that("neuprint_bodies_in_ROI works", { + expect_is(df <- neuprint_bodies_in_ROI('ATL(L)'), 'data.frame') + expect_named(df, c("bodyid", "voxels", "pre", "post", "roipre", "roipost")) +})