def W_from_rep(data: 'AnnData', rep: str) ->'csr_matrix':
    """
    Return affinity matrix W based on representation rep.
    """
    rep_key = 'W_' + rep
    if rep_key not in data.uns:
        raise ValueError(
            'Affinity matrix does not exist. Please run neighbors first!')
    return data.uns[rep_key]
