Created
August 17, 2020 21:02
-
-
Save kieranrcampbell/2b2b1aeb58ce58c16e5443360aa3299a to your computer and use it in GitHub Desktop.
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
#' Sort the results of a gsva() call so that the | |
#' pathway activation always correlates positively | |
#' on average with the gene set listed | |
#' @param g Result of call to gsva() (pathway x cell) | |
#' @param genesets List of genes corresponding to genesets of g | |
#' @param sce A SingleCellExperiment with a logcounts assay | |
fix_gsva_direction <- function(g, genesets, sce) { | |
stopifnot(nrow(g) == length(genesets)) | |
genesets <- lapply(genesets, intersect, rownames(sce)) | |
signs <- sapply(seq_along(genesets), function(i) { | |
gg <- g[i,] | |
cors <- apply( | |
logcounts(sce)[genesets[[i]],], | |
1, | |
cor, | |
gg | |
) | |
sign(mean(cors, na.rm=TRUE)) | |
}) | |
signs * g | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment