#' Get the mechanism of action object
#'
#' @param dsea is a drug set enrichment object as an output of the function getActiveDSEA()
#'
#' @return MoA Mechanism of Action object
#' @export
#' @importFrom fgsea fgsea
#'
#' @examples # from the data-sets provided as examples within the package load the .rda files
#' # DrugsAnnot, mDrugEnrich, mFC
#' dsea <- getActiveDSEA(mDrugEnrich, DrugsAnnot, mFC, contr = colnames(mFC)[1])
#' Moa <- getMOA(dsea)
getMOA <- function(dsea) {
## meta-GSEA on MOA terms
dt <- dsea$table
moa.list <- lapply(
as.character(dt$moa),
function(s) trimws(strsplit(s, split = "[\\|;,]")[[1]])
)
names(moa.list) <- rownames(dt)
moa <- setdiff(unlist(moa.list), c("", NA, " "))
gmt <- lapply(moa, function(g) names(which(sapply(moa.list, function(t) (g %in% t)))))
names(gmt) <- moa
targets.list <- lapply(
as.character(dt$target),
function(s) trimws(strsplit(s, split = "[\\|;,]")[[1]])
)
names(targets.list) <- rownames(dt)
targets <- setdiff(unique(unlist(targets.list)), c(NA, "", " "))
gmtar <- lapply(targets, function(g) {
names(which(sapply(targets.list, function(t) (g %in% t))))
})
names(gmtar) <- targets
rnk <- dt$NES
names(rnk) <- rownames(dt)
# get drug class
suppressWarnings(
moa.class <- fgsea::fgsea(gmt, rnk, nperm = 20000)
)
moa.class <- moa.class[order(-abs(moa.class$NES)), ]
# get gene targets
suppressWarnings(
moa.target <- fgsea::fgsea(gmtar, rnk, nperm = 20000)
)
moa.target <- moa.target[order(-abs(moa.target$NES)), ]
moa <- list("drugClass" = moa.class, "geneTargets" = moa.target)
return(moa)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.