Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: clustering, drop partner neurons with type=NA #28

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions R/coconatfly-package.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
#' @keywords internal
#' @import nat
#' @section Package options:
#'
#' coconatfly itself currently only has one option, which is to use a historical
#' behaviour for collating cell types for multi-connectome cosine clustering.
#'
#' \itemize{
#'
#' \item \code{options(coconatfly.cluster.dropna)}
#'
#' }
#'
#' @examples
#' # list any package options that have been set
#' options()[grepl("^coconatfly.*", names(options()))]
#'
#' # return to behaviour of coconatfly < v0.2
#' options(coconatfly.cluster.dropna=FALSE)
#' # return to default behaviour of coconatfly >= v0.2
#' options(coconatfly.cluster.dropna=TRUE)
#'
"_PACKAGE"

## usethis namespace: start
Expand Down
13 changes: 12 additions & 1 deletion R/partners.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,25 @@ cf_partners <- function(ids, threshold=1L, partners=c("inputs", "outputs"),
# different datasets so that when cell types are found in the dataset but
# missing from the partners we can use that negative result.
# partners argument is just used to construct a warning message
match_types <- function(x, group="type", partners="", min_datasets=Inf) {
# historically drop.na was FALSE but I think should have been TRUE
# We allow users to revert to the old behaviour using:
# options("coconatfly.cluster.dropna")
match_types <- function(x, group="type", partners="", min_datasets=Inf,
drop.na=getOption("coconatfly.cluster.dropna", TRUE)) {
stopifnot(is.data.frame(x))
if(!is.finite(min_datasets)) min_datasets=dplyr::n_distinct(x$dataset)

xg <- x %>%
dplyr::group_by_at(group) %>%
dplyr::mutate(nd=dplyr::n_distinct(dataset)) %>%
dplyr::ungroup()
if(drop.na) {
xg <- xg %>%
dplyr::mutate(nd=case_when(
is.na(.data[[group]]) ~ 0,
T ~ nd
))
}
todrop <- xg %>%
dplyr::filter(nd<min_datasets)
message("Matching types across datasets. Dropping ",
Expand Down
23 changes: 23 additions & 0 deletions man/coconatfly-package.Rd

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

Loading