def filter_percentile(matrix, top, percentile=<NUM_LIT:50>):
assert isinstance(matrix, ExpMatrix)<EOL>assert isinstance(top, int)<EOL>assert isinstance(percentile, (int, float))<EOL>if top >= matrix.p:<EOL><INDENT>logger.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>top = matrix.p<EOL><DEDENT>a = np.argsort(np.percentile(matrix.X, percentile, axis=<NUM_LIT:1>))<EOL>a = a[::-<NUM_LIT:1>]<EOL>sel = np.zeros(matrix.p, dtype=np.bool_)<EOL>sel[a[:top]] = True<EOL>matrix = matrix.loc[sel]<EOL>return matrix<EOL>
Filter genes in an expression matrix by percentile expression.

    Parameters
    ----------
    matrix: ExpMatrix
        The expression matrix.
    top: int
        The number of genes to retain.
    percentile: int or float, optinonal
        The percentile to use  Defaults to the median (50th percentile).

    Returns
    -------
    ExpMatrix
        The filtered expression matrix.