gseapy/algorithm.py
def normalize(es, esnull):
    """normalize the ES(S,pi) and the observed ES(S), separately rescaling
       the positive and negative scores by dividing the mean of the ES(S,pi).
       
       return: NES, NESnull
    """

    nEnrichmentScores =np.zeros(es.shape)
    nEnrichmentNulls=np.zeros(esnull.shape)

    esnull_pos = (esnull * (esnull >= 0)).mean(axis=1)
    esnull_neg = (esnull * (esnull < 0)).mean(axis=1)
    # calculate nESnulls
    for i in range(esnull.shape[0]):
        # NES
        if es[i] >= 0:
            nEnrichmentScores[i] = es[i] / esnull_pos[i]
        else:
            nEnrichmentScores[i] = - es[i] / esnull_neg[i]

        # NESnull
        for j in range(esnull.shape[1]):
            if esnull[i,j] >= 0:
                nEnrichmentNulls[i,j] = esnull[i,j] / esnull_pos[i]
            else:
                nEnrichmentNulls[i,j] = - esnull[i,j] / esnull_neg[i]

    return nEnrichmentScores, nEnrichmentNulls
def normalize(es, esnull):
    """normalize the ES(S,pi) and the observed ES(S), separately rescaling
       the positive and negative scores by dividing the mean of the ES(S,pi).
       
       return: NES, NESnull
    """

    nEnrichmentScores =np.zeros(es.shape)
    nEnrichmentNulls=np.zeros(esnull.shape)

    esnull_pos = (esnull * (esnull >= 0)).mean(axis=1)
    esnull_neg = (esnull * (esnull < 0)).mean(axis=1)
    # calculate nESnulls
    for i in range(esnull.shape[0]):
        # NES
        if es[i] >= 0:
            nEnrichmentScores[i] = es[i] / esnull_pos[i]
        else:
            nEnrichmentScores[i] = - es[i] / esnull_neg[i]

        # NESnull
        for j in range(esnull.shape[1]):
            if esnull[i,j] >= 0:
                nEnrichmentNulls[i,j] = esnull[i,j] / esnull_pos[i]
            else:
                nEnrichmentNulls[i,j] = - esnull[i,j] / esnull_neg[i]

    return nEnrichmentScores, nEnrichmentNulls
normalize the ES(S,pi) and the observed ES(S), separately rescaling
       the positive and negative scores by dividing the mean of the ES(S,pi).
       
       return: NES, NESnull