Skip to content

Commit

Permalink
implement intuitive behaviour into groupNhoods so groups do not conta…
Browse files Browse the repository at this point in the history
…in _any_ discordant LFCs
  • Loading branch information
MikeDMorgan committed Nov 20, 2024
1 parent 959804d commit b7a2881
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: miloR
Type: Package
Title: Differential neighbourhood abundance testing on a graph
Version: 2.3.0
Version: 2.3.1
Authors@R:
c(person("Mike", "Morgan", role=c("aut", "cre"), email="michael.morgan@abdn.ac.uk",
comment=c(ORCID="0000-0003-0757-0711")),
Expand Down
Empty file added NEWS
Empty file.
21 changes: 16 additions & 5 deletions R/groupNhoods.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#' adjacency matrix if already present.
#' @param na.function A valid NA action function to apply, should be one of
#' \code{na.fail, na.omit, na.exclude, na.pass} (default='na.pass').
#' @param original.behaviour A logical scalar indicating whether to use the original nhood grouping
#' behaviour that \emph{can} give rise to nhood groups with discordant LFC. If \code{original.behaviour=FALSE}
#' then the more intuitive functionality that forces nhood groups to have \emph{only} concordant LFC signs.
#'
#' @return A \code{data.frame} of model results (as \code{da.res} input) with a new column storing the assigned
#' group label for each neighbourhood (\code{NhoodGroup} column)
Expand All @@ -45,7 +48,8 @@ groupNhoods <- function(x, da.res, da.fdr=0.1,
merge.discord=FALSE,
subset.nhoods=NULL,
compute.new=FALSE,
na.function="na.pass"
na.function="na.pass",
original.behaviour=TRUE
){
if(!is(x, "Milo")){
stop("Unrecognised input type - must be of class Milo")
Expand Down Expand Up @@ -92,7 +96,8 @@ groupNhoods <- function(x, da.res, da.fdr=0.1,
merge.discord=merge.discord,
max.lfc.delta=max.lfc.delta,
overlap=overlap,
subset.nhoods=subset.nhoods
subset.nhoods=subset.nhoods,
orig.behave=original.behaviour
)

## Save in DAres data.frame
Expand All @@ -110,7 +115,8 @@ groupNhoods <- function(x, da.res, da.fdr=0.1,
merge.discord=FALSE,
max.lfc.delta=NULL,
overlap=1,
subset.nhoods=NULL
subset.nhoods=NULL,
orig.behave=TRUE
){

if(is.null(colnames(nhs))){
Expand Down Expand Up @@ -150,8 +156,13 @@ groupNhoods <- function(x, da.res, da.fdr=0.1,

## check for concordant signs (only for significant DA) - assume order is the same as nhoods
if(isFALSE(merge.discord)){
discord.sign <- sign(da.res[is.da, 'logFC'] %*% t(da.res[is.da, 'logFC'])) < 0
nhood.adj[is.da, is.da][discord.sign] <- 0
if(isFALSE(orig.behave)){
discord.sign <- sign(as.matrix(da.res[, 'logFC', drop=FALSE]) %*% as.matrix(t(da.res[, 'logFC', drop=FALSE]))) < 0
nhood.adj[discord.sign] <- 0
} else{
discord.sign <- sign(as.matrix(da.res[is.da, 'logFC', drop=FALSE]) %*% as.matrix(t(da.res[is.da, 'logFC', drop=FALSE]))) < 0
nhood.adj[is.da, is.da][discord.sign] <- 0
}
}

if(overlap > 1){
Expand Down
7 changes: 6 additions & 1 deletion man/groupNhoods.Rd

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

0 comments on commit b7a2881

Please sign in to comment.