Skip to content

Commit

Permalink
Apply threshold to ROIweight
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jefferis committed Jul 31, 2020
1 parent ddb170f commit c08da3e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 9 additions & 3 deletions R/connectivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion man/neuprint_connection_table.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test-connectivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit c08da3e

Please sign in to comment.