From 2b4592ebe4a46ea55c0ffa10d007d0d3695bb897 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Fri, 31 Jul 2020 09:15:13 +0100 Subject: [PATCH] Apply threshold to ROIweight * the cypher got a bit hairy so I actually only apply the ROI weight threshold to downloaded data. * I'm sure there must be a way to apply it on the server in a multi-level query. --- R/connectivity.R | 12 +++++++++--- man/neuprint_connection_table.Rd | 3 ++- tests/testthat/test-connectivity.R | 9 +++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/R/connectivity.R b/R/connectivity.R index e8a7960d..dd71a97b 100644 --- a/R/connectivity.R +++ b/R/connectivity.R @@ -103,7 +103,8 @@ neuprint_get_adjacency_matrix <- function(bodyids=NULL, inputids=NULL, #' @param by.roi logical, whether or not to break neurons' connectivity down by #' region of interest (ROI) #' @param threshold Only return partners >= to an integer value. Default of 1 -#' returns all partners. +#' returns all partners. This threshold will be applied to the ROI weight when +#' the \code{roi} argument is specified, otherwise to the whole neuron. #' @param superLevel When \code{by.roi=TRUE}, should we look at low-level ROIs #' (\code{superLevel=FALSE}) or only super-level ROIs #' (\code{superLevel=TRUE}). A super-level ROIs can contain multiple @@ -261,13 +262,18 @@ neuprint_connection_table <- function(bodyids, if(!is.null(roi)){ d <- d[d$roi%in%roi,] } - if(by.roi&is.null(roi)){ + if(by.roi && is.null(roi)){ rois <- neuprint_ROIs(superLevel = superLevel) d <- d[d$roi%in%rois,] } d <- d[order(d$weight,decreasing=TRUE),] rownames(d) <- NULL - d[,sort(colnames(d))] + d=d[,sort(colnames(d))] + + if(!is.null(roi) && threshold>1) + d=d[d$ROIweight>=threshold,] + + d } #' @title Get the common synaptic partners for a set of neurons diff --git a/man/neuprint_connection_table.Rd b/man/neuprint_connection_table.Rd index 2a1e9e8b..2ef36202 100644 --- a/man/neuprint_connection_table.Rd +++ b/man/neuprint_connection_table.Rd @@ -33,7 +33,8 @@ inputs) or \code{POST}: postsynaptic (downstream outputs) to the given region of interest (ROI)} \item{threshold}{Only return partners >= to an integer value. Default of 1 -returns all partners.} +returns all partners. This threshold will be applied to the ROI weight when +the \code{roi} argument is specified, otherwise to the whole neuron.} \item{superLevel}{When \code{by.roi=TRUE}, should we look at low-level ROIs (\code{superLevel=FALSE}) or only super-level ROIs diff --git a/tests/testthat/test-connectivity.R b/tests/testthat/test-connectivity.R index 48851025..436eb922 100644 --- a/tests/testthat/test-connectivity.R +++ b/tests/testthat/test-connectivity.R @@ -28,6 +28,15 @@ test_that("neuprint_connection_table works", { 'data.frame') # equivalent so we don't worry about rownames expect_equivalent(subset(t2, roi=='LH(R)'), t3) + expect_equivalent( + neuprint_connection_table( + c(818983130, 1796818119), + prepost = "POST", + roi = "LH(R)", + threshold = 3 + ), + subset(t3, ROIweight >= 3) + ) }) test_that("other connectivity functions work", {