def _zero_nontop_genes(trait_vector, n_top, use_abs=True):
    """
    It takes a pandas Series (with genes/LVs in index, and association values),
    sorts it, and leave only the top values, putting zeros in the rest.

    Args:
        trait_vector:
            A pandas Series with numerical data.
        n_top:
            Number of top genes/LVs to keep. The rest will be zeroed.
        use_abs:
            If True, then it uses the absolute value.

    Returns:
        A new pandas Series keeping only the top n_top values (the rest is
        zeroed).
    """
    if use_abs:
        df = trait_vector.abs()
    else:
        df = trait_vector

    trait_top_genes = df.sort_values(ascending=False).head(n_top).index

    trait_vector = trait_vector.copy()
    trait_vector[~trait_vector.index.isin(trait_top_genes)] = 0.0

    return trait_vector