Skip to content

Commit

Permalink
Merge pull request #203 from natverse/feature/streamline-partner_summary
Browse files Browse the repository at this point in the history
Feature/streamline partner summary
  • Loading branch information
jefferis authored Aug 10, 2024
2 parents aa49da8 + 0e28ff9 commit 59f491f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
16 changes: 10 additions & 6 deletions R/autosyn.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ spine_svids2synapses <- function(svids, Verbose, partners, details=FALSE) {
#' details.
#' @param remove_autapses For \code{flywire_partner_summary} whether to remove
#' autapses (defaults to TRUE)
#' @param summarise Whether to collapse down the results for multiple query
#' neurons into a single entry for each partner neuron.
#' @param summarise (This was never implemented.) Whether to
#' collapse down the results for multiple query neurons into a single entry
#' for each partner neuron.
#' @param Verbose Whether to print status messages
#' @inheritParams flywire_ntplot
#' @inheritParams flywire_timestamp
Expand Down Expand Up @@ -391,6 +392,8 @@ flywire_partner_summary <- function(rootids, partners=c("outputs", "inputs"),
check_package_available('tidyselect')
partners=match.arg(partners)
method=match.arg(method)
if(!isFALSE(summarise))
warning("Ignoring summarise=TRUE; this was never implemented!")
if(!is.null(version) || !is.null(timestamp)) {
if(method=='auto') method="cave"
if(method!='cave')
Expand All @@ -416,7 +419,7 @@ flywire_partner_summary <- function(rootids, partners=c("outputs", "inputs"),
surf=surf,
...
)
df = dplyr::bind_rows(res, .id = 'query')
df = dplyr::bind_rows(res)
return(df)
}

Expand Down Expand Up @@ -450,10 +453,11 @@ flywire_partner_summary <- function(rootids, partners=c("outputs", "inputs"),
partnerdf <- partnerdf %>%
filter(nat::pointsinside(cbind(.data$pre_x, .data$pre_y, .data$pre_z), surf))
}

# rename original query column to query
colnames(partnerdf)[colnames(partnerdf)==querycol]='query'
res <- partnerdf %>%
group_by(.data[[groupingcol]]) %>%
summarise(weight=n(), n=length(unique(.data[[querycol]]))) %>%
group_by(.data[['query']], .data[[groupingcol]]) %>%
summarise(weight=n(), .groups = 'drop') %>%
arrange(desc(.data$weight)) %>%
filter(.data$weight>threshold)

Expand Down
2 changes: 2 additions & 0 deletions R/flywire-arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ flywire_connectome_data_message <- function() {
#' @param add_cell_types Whether to add cell type information to the result
#' @param by.roi Whether to break the connectivity down into rows for each
#' neuropil region containing synapses.
#' @param summarise Whether to collapse down the results for multiple query
#' neurons into a single entry for each partner neuron.
#' @inheritParams flywire_connectome_data
#' @inheritParams flywire_partner_summary
#' @importFrom dplyr ungroup n_distinct collect .data
Expand Down
5 changes: 3 additions & 2 deletions man/flywire_partners.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-autosyn.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test_that("flywire_partners / flywire_partner_summary works", {
expect_message(df <- flywire_partner_summary("720575940616243077", Verbose = T),
'Fetching supervoxel.*720575940616243077')
expect_is(df, 'data.frame')
expect_named(df, c("post_id", "weight", "n"))
expect_named(df, c("query", "post_id", "weight"))
expect_message(df2 <- flywire_partner_summary("720575940616243077", partners = 'input', Verbose = T),
'Fetching supervoxel.*720575940616243077')

Expand Down

0 comments on commit 59f491f

Please # to comment.