def propagate_taxids(res, ranks):
    """
    Transfer taxonomy ids to unassigned ranks based on best known taxonomy
    Example:

    {'species': -1, 'family': -171549, 'genus': -171549, 'order': 171549, 'phylum': 976, 'class': 200643, 'superkingdom': 2}

    should become
    {'species': -171549, 'family': -171549, 'genus': -171549, 'order': 171549, 'phylum': 976, 'class': 200643, 'superkingdom': 2}

    Parameters
    ----------
    res: dict
        Dictionary of ranks and taxonomy ids
    ranks: list
        Ranks to assign taxonomy to

    Returns
    -------
    res: dict
        Dictionary with updated taxonomy ids
    """

    known = -1
    for rank in ranks:
        # If not -1 (Unclassified) at rank, store assignment as known
        if res[rank] != -1:
            known = res[rank]
            continue
        # If -1 at rank (Unclassified), add the taxid with the '-' prefix
        if res[rank] == -1:
            res[rank] = -abs(known)
    return res