Created
February 14, 2024 19:12
-
-
Save GabrielHoffman/c0c119a26609e5b8cd91e7cc2b4c1de5 to your computer and use it in GitHub Desktop.
Remove variance partition component and recompute fractions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Remove variance partition component and recompute fractions | |
#' | |
#' @param vp result of \code{fitVarPart()} | |
#' @param exclude array of column names to exclude | |
removeVarPartComponent = function(vp, exclude){ | |
# get column index of exclude | |
j = match(exclude, colnames(vp)[-c(1:2)]) | |
# compute new variance fractions | |
df = t(apply(vp[,-c(1:2)], 1, function(x) x[-j] / sum(x[-j]))) | |
# label with gene and cell type | |
df = data.frame(vp[,1:2], df) | |
# return | |
new("vpDF", S4Vectors::DataFrame(df)) | |
} | |
# usage | |
df2 = removeVarPartComponent(vp, exclude = c("Dx", "Sex")) | |
plotVarPart(df2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment