Extract GSVA gene rank matrix
1
0
Entering edit mode
dylan • 0
@dylan-23983
Last seen 13 months ago

Hi! I am really enjoying the GSVA package.

I was wondering, is there any way to currently pull out the gene-rank matrix from the gsva function? Another tool I am using requires gene ranks as input, and I would like to use the method described in GSVA to generate those ranks.

gsva • 209 views
0
Entering edit mode
Robert Castelo ★ 2.7k
@rcastelo
Last seen 12 weeks ago
Barcelona/Universitat Pompeu Fabra

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.