Skip to content

Rank Transforms

Shifted Negative Log Ranks

Transforms ranks to negative log10 values and shifts such that the lowest value is 0.

Parameters:

Name Type Description Default
ranks ndarray

A vector of ranks

required

Returns:

Type Description
ndarray

A vector of negative log10 transformed ranks shifted such that the lowest value is 0

Raises:

Type Description
ValueError

If the ranks are not numeric.

Source code in yeastdnnexplorer/interface/rank_transforms.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def shifted_negative_log_ranks(ranks: np.ndarray) -> np.ndarray:
    """
    Transforms ranks to negative log10 values and shifts such that the lowest value is
    0.

    :param ranks: A vector of ranks
    :return np.ndarray: A vector of negative log10 transformed ranks shifted such that
        the lowest value is 0
    :raises ValueError: If the ranks are not numeric.

    """
    if not np.issubdtype(ranks.dtype, np.number):
        raise ValueError("`ranks` must be a numeric")
    max_rank = np.max(ranks)
    log_max_rank = np.log10(max_rank)
    return -1 * np.log10(ranks) + log_max_rank

Negative Log Transform by P-Value and Enrichment

This calls the rank() function and then transforms the ranks to negative log10 values and shifts to the right such that the lowest value (largest rank, least important) is 0.

Parameters:

Name Type Description Default
pvalue_vector ndarray

A vector of pvalues

required
enrichment_vector ndarray

A vector of enrichment values corresponding to the pvalues

required

Returns:

Type Description
ndarray

A vector of negative log10 transformed ranks shifted such that the lowest value is 0 and the highest value is log10(min_rank)

Raises:

Type Description
ValueError

If the primary or secondary column is not numeric.

Source code in yeastdnnexplorer/interface/rank_transforms.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def negative_log_transform_by_pvalue_and_enrichment(
    pvalue_vector: np.ndarray, enrichment_vector: np.ndarray
) -> np.ndarray:
    """
    This calls the rank() function and then transforms the ranks to negative log10
    values and shifts to the right such that the lowest value (largest rank, least
    important) is 0.

    :param pvalue_vector: A vector of pvalues
    :param enrichment_vector: A vector of enrichment values corresponding to the pvalues
    :return np.ndarray: A vector of negative log10 transformed ranks shifted such that
        the lowest value is 0 and the highest value is log10(min_rank)
    :raises ValueError: If the primary or secondary column is not numeric.

    """

    final_ranks = stable_rank(pvalue_vector, enrichment_vector)

    return shifted_negative_log_ranks(final_ranks)