def unalter_zero_tip_allowed_states(tree, feature, state2index):
    """
    Unalters the bottom-up likelihood arrays for zero-distance tips
    to contain ones only in their states.

    :param state2index: dict, mapping between states and their indices in the likelihood array
    :param tree: ete3.Tree, the tree of interest
    :param feature: str, character for which the likelihood was altered
    :return: void, modifies the get_personalised_feature_name(feature, BU_LH) feature to zero-distance tips.
    """
    allowed_state_feature = get_personalized_feature_name(feature, ALLOWED_STATES)
    for tip in tree:
        if tip.dist > 0:
            continue
        state = getattr(tip, feature, set())
        if state:
            initial_allowed_states = np.zeros(len(state2index), np.int)
            for _ in state:
                initial_allowed_states[state2index[_]] = 1
            allowed_states = getattr(tip, allowed_state_feature) & initial_allowed_states
            tip.add_feature(allowed_state_feature, (allowed_states
                                                    if np.any(allowed_states > 0) else initial_allowed_states))
def unalter_zero_tip_allowed_states ( tree , feature , state2index ) : allowed_state_feature = get_personalized_feature_name ( feature , ALLOWED_STATES ) for tip in tree : if tip . dist > 0 : continue state = getattr ( tip , feature , set ( ) ) if state : initial_allowed_states = np . zeros ( len ( state2index ) , np . int ) for _ in state : initial_allowed_states [ state2index [ _ ] ] = 1 allowed_states = getattr ( tip , allowed_state_feature ) & initial_allowed_states tip . add_feature ( allowed_state_feature , ( allowed_states if np . any ( allowed_states > 0 ) else initial_allowed_states ) )
Unalters the bottom-up likelihood arrays for zero-distance tips
    to contain ones only in their states.

    :param state2index: dict, mapping between states and their indices in the likelihood array
    :param tree: ete3.Tree, the tree of interest
    :param feature: str, character for which the likelihood was altered
    :return: void, modifies the get_personalised_feature_name(feature, BU_LH) feature to zero-distance tips.