How to adapt the fgseaL function to perform rapidGSEA computation of gene ranks across 9 different phenotype labels? I wish to adapt the r language function fgseaL, https://github.com/ctlab/fgsea , to perform rapidGSEA, https://bmcbioinformatics.biomedcentral.com/articles/10.1186/s12859-016-1244-x , computation of inter-class  deviation per gene and the subsequent gene rank sorting operation on 9 different phenotype labels as illustrated in the diagram immediately below:



I thought of applying the R-language rank() function on the Expression Data Matrix D. If that is not correct, what sequence of R language commands should we
apply to the Expression Data Matrix D to calculate a key value sorted deviation measure  across 8 labeled human leukemia groups and a healthy labeled normal control group prior to running fgseaL? 

I show below how fgseaL finds the correlation matrix between the R language variable , mat, which corresponds to the Expression Data Matrix D and the R language variable , labels , which is a vector of gene phenotype labels

    tmatSc &lt;- scale(t(mat))
    labelsSc &lt;- scale(labels)[, 1]

    minSize &lt;- max(minSize, 1)

    pathwaysFiltered &lt;- lapply(pathways, function(p) { as.vector(na.omit(fmatch(p, rownames(mat)))) })
    pathwaysSizes &lt;- sapply(pathwaysFiltered, length)

    toKeep &lt;- which(minSize &lt;= pathwaysSizes &amp; pathwaysSizes &lt;= maxSize)
    m &lt;- length(toKeep)

    if (m == 0) {
        return(data.table(pathway=character(),
                          pval=numeric(),
                          padj=numeric(),
                          ES=numeric(),
                          NES=numeric(),
                          nMoreExtreme=numeric(),
                          size=integer(),
                          leadingEdge=list()))
    }

    pathwaysFiltered &lt;- pathwaysFiltered[toKeep]
    pathwaysSizes &lt;- pathwaysSizes[toKeep]

    corRanks &lt;- var(tmatSc, labelsSc)[,1]
    ranksOrder &lt;- order(corRanks, decreasing=T)
    ranksOrderInv &lt;- invPerm(ranksOrder)
    stats &lt;- corRanks[ranksOrder]

    pathwaysReordered &lt;- lapply(pathwaysFiltered, function(x) ranksOrderInv[x])

    gseaStatRes &lt;- do.call(rbind,
                           lapply(pathwaysReordered, calcGseaStat,
                                  stats=stats,
                                  returnLeadingEdge=TRUE))

I found a problem with the algorithm shown immediately below.
correcttest &lt;- data.frame(names = row.names(normal))
correcttest &lt;- cbind(correcttest3, normal)
correcttest &lt;- cbind(correcttest3, ALL3m)
rownames(correcttest) &lt;- correcttest$names
correcttest$names &lt;- NULL
correctlabelnormal &lt;- rep(0:0, 73)
correctlabelALL3m &lt;- rep(1:1, 122)
correctlabel &lt;- as.vector(c(correctlabelnormal,correctlabelALL3m))
s &lt;- apply(correcttest, 1, function(x) coef(lm(x~correctlabel))[2])
o &lt;- rank(s)
o &lt;- max(o) - o + 1
res &lt;- fgseaL(df,o,correctlabel,nperm = 2000,minSize = 1, maxSize=50000)
empty data table (0 rows) of 8 columns:   pathway,pval,padj,ES,NES,nMoreExtreme,size

I found the binary phenotype labeled group fgseaL test results below looked satisfactory.    
correcttest &lt;- data.frame(names = row.names(normal))
correcttest &lt;- cbind(correcttest3, normal)
correcttest &lt;- cbind(correcttest3, ALL3m)
rownames(correcttest) &lt;- correcttest$names
correcttest$names &lt;- NULL
correctlabelnormal &lt;- rep(0:0, 73)
correctlabelALL3m &lt;- rep(1:1, 122)
correctlabel &lt;- as.vector(c(correctlabelnormal,correctlabelALL3m))
fgseaL(df,correcttest,correctlabel,nperm = 2000,minSize = 1, maxSize=50000)
       pathway        pval        padj         ES       NES nMoreExtreme  size
1: Gene.Symbol 0.003940887 0.003940887 -0.2460126 -1.180009            3 45714
                                 leadingEdge
1: AKIRIN2,LRRC20,HSPA5,HSPA5,DTWD2,ZFYVE28,


Thank you for your consideration.
I finally found another answer to my question. Please read this great article in May 12 2017 BioMed Central (BMC) Bioinformatics article titled Ranking metrics in gene set enrichment analysis: do they matter?.

Also, please read this blog , Diving into Genetics and Genomics: Gene Set Enrichment Analysis (GSEA) explained.

After reading these two articles, my choice for the best rapidGSEA local ranking measure is Minimum Significant Difference (i.e., MSD), because it has the best overall false positive rate (i.e., FPR) for larger sample sizes.

Finally, it is important to realize that fgseaL's phenotype labeling can hypothetically be emulated by GSEA with either one of it's sixteen possible ranking metrics or a custom ranking metric.