def get_all_ancestors(tax_id, tax_id_to_parent):
    """
    Given a tax ID, this function returns a list of all of its ancestors (including the tax ID
    itself). The list is ordered with the tax ID at the start and the root (tax ID 1) at the end.
    """
    ancestors = [tax_id]
    while tax_id != 1:  # loop until we hit the root
        tax_id = tax_id_to_parent[tax_id]
        ancestors.append(tax_id)
    assert ancestors[-1] == 1  # all ancestor lists should end with node 1 (the root)
    return ancestors