Exemplo n.º 1
0
def create_toggle_partial_tree_scorer(model_list, 
                                      data,
                                      tree,
                                      num_extra_nodes=0
                                      ):
    '''Simple constructor for a TogglePartialTreeScorer and LikeCalcEnvironment
    to support it.
    
    Infers:
        data_type (num_states) and asrv from the models in model_list
        num_leaves, num_state_code_arrays, num_partials for len(data)
        num_patterns from len(data[0]) 
        
        
        
        Assumes that you will want a enough prob_matrix for every edge in a rooted,
            binary tree to have two sets of matrices for each model/rate-category 
            combination.
        Assumes that you want only two eigen solution per model.

        Assumes that you want only two partials for internal nodes solution per
            model and `num_extra_partials` in addition to this (thus if you want
            one "extra" node that can be swapped in and out of the tree you 
            should use num_extra_partials=1, and then manually load up the 
            _LCE_xxx attributes for that node.

        Assumes that you want one rescaling array for every 6 edges (every 4 leaves)
    '''
    from pytbeaglehon.like_calc_environ import LikeCalcEnvironment
    asrv_list = []
    num_model_rate_cats = 0
    num_leaves = len(data)
    num_patterns = len(data[0])
    num_models = len(model_list) #TODO more generic for mixtures!
    for model in model_list:
        a = model.asrv
        if a is None:
            num_model_rate_cats += 1
        else:
            num_model_rate_cats += a.num_categories
    num_internals = (num_leaves - 1)
    num_nodes = num_internals + num_leaves
    LCE = LikeCalcEnvironment(model_list=model_list,
                               num_patterns=num_patterns,
                               num_leaves=num_leaves,
                               num_state_code_arrays=num_leaves,
                               num_partials=(num_internals + num_extra_nodes)*2*num_model_rate_cats,
                               num_prob_matrices=(num_nodes + num_extra_nodes)*2*num_model_rate_cats,
                               num_eigen_storage_structs=2*num_models,
                               num_rescalings_multipliers= 2*(1 + num_leaves//4))
    for n, row in enumerate(data):
        LCE.set_state_code_array(n, row)
    scorer = TogglePartialTreeScorer(LCE, tree)
    return scorer