diff --git a/R/connectivity.R b/R/connectivity.R index 6cabca17..8eac5bff 100644 --- a/R/connectivity.R +++ b/R/connectivity.R @@ -15,7 +15,7 @@ neuprint_get_adjacency_matrix <- function(bodyids, dataset = NULL, all_segments "WHERE n.bodyId IN input AND m.bodyId IN input", "RETURN n.bodyId AS upstream, m.bodyId AS downstream, c.weight AS weight, n.%s AS upName, m.%s AS downName" ), - id2json(bodyids), + id2json(bodyids, uniqueids = TRUE), all_segments.json, namefield, namefield @@ -50,6 +50,8 @@ 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)) if(!is.null(roi)){ roicheck = neuprint_check_roi(rois=roi, dataset = dataset, conn = conn, ...) } @@ -61,6 +63,8 @@ neuprint_connection_table <- function(bodyids, prepost = c("PRE","POST"), roi = progress = FALSE, dataset = dataset, conn = conn, ...), error = function(e) NULL))) + d <- d[order(d$weight,decreasing=TRUE),] + rownames(d) <- NULL return(d) } cypher = sprintf(paste("WITH %s AS bodyIds UNWIND bodyIds AS bodyId", @@ -85,6 +89,7 @@ neuprint_connection_table <- function(bodyids, prepost = c("PRE","POST"), roi = d$weight <- as.integer(d$weight) d$prepost <- ifelse(prepost=="PRE",0,1) d <- d[order(d$weight,decreasing=TRUE),] + rownames(d) <- NULL d[,c("bodyid", "partner", "roi","weight", "prepost")] } diff --git a/tests/testthat/test-connectivity.R b/tests/testthat/test-connectivity.R new file mode 100644 index 00000000..be83a28b --- /dev/null +++ b/tests/testthat/test-connectivity.R @@ -0,0 +1,10 @@ +skip_if(as.logical(Sys.getenv("SKIP_NP_SERVER_TESTS"))) + +test_that("neuprint_connection_table works", { + expect_is(t1 <- neuprint_connection_table(c(818983130, 1796818119)), + 'data.frame') + # ensure we get the same answer with progress=TRUE + expect_equal(neuprint_connection_table(c(818983130, 1796818119), + progress = TRUE), + t1) +})