Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/neuprint bodies in roi #79

Merged
merged 2 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions R/roi.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,24 @@ 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, ...)
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
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-roi.R
Original file line number Diff line number Diff line change
@@ -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"))
})