Skip to content

Commit

Permalink
Merge pull request #36 from natverse/feature/cosineplot-warn-no-partners
Browse files Browse the repository at this point in the history
Handle missing partners in cf_cosine_plot
  • Loading branch information
jefferis authored Dec 31, 2024
2 parents c4be6a1 + 7b32c98 commit 58e1e06
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions R/datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ match_datasets <- function(ds) {
#' @examples
#' abbreviate_datasets(c("flywire", "flywire", "hemibrain"))
abbreviate_datasets <- function(ds) {
if(length(ds)<1) return(ds)
ds=match_datasets(ds)
abbrevlist=c(hemibrain='hb', flywire='fw', manc='mv', fanc='fv', malecns='mc',
opticlobe='ol', banc='bc')
Expand Down
14 changes: 12 additions & 2 deletions R/partners.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,22 @@ cf_partners <- function(ids, threshold=1L, partners=c("inputs", "outputs"),
))
}
tres=coconat:::standardise_partner_summary(tres)
tres$dataset=n
if(nrow(tres)>0) {
tres$dataset=n
} else {
tres$dataset=character()
warning("no ", partners, " found for `", n, "` dataset.")
}
tres$pre_key=keys(tres, idcol="pre_id")
tres$post_key=keys(tres, idcol='post_id')
res[[n]]=tres
}
if(isTRUE(bind.rows)) bind_rows2(res) else res
if(isTRUE(bind.rows)) {
res=bind_rows2(res)
# record the datasets we tried to find
attr(res, 'datasets')=names(ids)
res
} else res
}


Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-cosine.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ test_that("cosine plots work", {
expect_equal(cf_cosine_plot(lalids, min_datasets = 1, heatmap = F),
hc1)))
})


test_that("cosine plot with no partners", {
op <- options(fafbseg.use_static_celltypes=T)
on.exit(options(op))

suppressWarnings(
suppressMessages(
expect_warning(cf_cosine_plot(cf_ids(hemibrain = 'ORN_DA1', flywire = 'ORN_DA1'), threshold = 8),
"no inputs.*flywire")
))
})

0 comments on commit 58e1e06

Please sign in to comment.