Skip to content

Instantly share code, notes, and snippets.

@GabrielHoffman
Created February 14, 2024 19:12
Show Gist options
  • Save GabrielHoffman/c0c119a26609e5b8cd91e7cc2b4c1de5 to your computer and use it in GitHub Desktop.
Save GabrielHoffman/c0c119a26609e5b8cd91e7cc2b4c1de5 to your computer and use it in GitHub Desktop.
Remove variance partition component and recompute fractions
#' 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