hi,
if you mean to get ranks per gene set from the GSVA enrichment scores, you can do that using the R base function 'rank()' as follows:
library(GSVA)
example(gsva)
gsva_rnk1 <- apply(gsva_es, 2, rank)
if you mean to get the ranks 'r_ij' per gene, specified in Equation (3) of the article, then you need to call some internal functions as follows (i keep using the example of the help page of the 'gsva()' function):
library(GSVA)
example(gsva)
expr <- GSVA:::.filterFeatures(y, "gsva")
mapped.gset.idx.list <- lapply(geneSets, function(x, y) na.omit(match(x, y)), rownames(expr))
gene.density <- GSVA:::compute.gene.density(expr, 1:ncol(y), FALSE, TRUE)
rank.scores <- rep(0, nrow(y))
sort.sgn.idxs <- apply(gene.density, 2, order, decreasing=TRUE)
compute_rank_score <- function(sort_idx_vec, p){
tmp <- rep(0, p)
tmp[sort_idx_vec] <- abs(seq(from=p,to=1) - p/2)
return (tmp)
}
gsva_rnk2 <- apply(sort.sgn.idxs, 2, compute_rank_score, nrow(y))
This code is adapted from internal code of the GSVA package, so it may have an unexpected behavior in your hands if you're not familiar with R and with the GSVA methodology. If you want to have that matrix 'r_ij' of ranks as possible output in the GSVA package, please file it as a feature request, opening a new issue in the GSVA GitHub repo.
cheers,
robert.