def leave_node(key, node, population, cofmat): if node_is_non_admixture(node): return [follow_branch(parent_key=node[0],branch=(key,0), population=population, cofmat=cofmat)] else: new_pop=population.remove_partition(1.0-node[2]) return [follow_branch(parent_key=node[0],branch=(key,0), population=population, cofmat=cofmat, dependent='none'), #changed dependent='none' to go to most loose restriction that still makes sense. To go back,put dependent=node[1 follow_branch(parent_key=node[1],branch=(key,1), population=new_pop, cofmat=cofmat, dependent='none')]
def leave_node_and_check_admixtures(key, node, population, covmat): if node_is_non_admixture(node): return [ follow_branch(parent_key=node[0], branch_length=node[3], population=population, covmat=covmat) ], [] else: members = population.members[:] new_pop = population.remove_partition(1.0 - node[2]) return [ follow_branch( parent_key=node[0], branch_length=node[3], population=population, covmat=covmat, dependent='none' ), #changed dependent='none' to go to most loose restriction that still makes sense. To go back,put dependent=node[1 follow_branch(parent_key=node[1], branch_length=node[4], population=new_pop, covmat=covmat, dependent='none') ], members
def leave_node(key, node, population, target_nodes, follow_branch): if node_is_non_admixture(node): return [ follow_branch(parent_key=node[0], branch=0, population=population, target_nodes=target_nodes, child_key=key) ] else: new_pop = population.remove_partition(1.0 - node[2]) return [ follow_branch( parent_key=node[0], branch=0, population=population, target_nodes=target_nodes, child_key=key, dependent='none' ), #changed dependent='none' to go to most loose restriction that still makes sense. To go back,put dependent=node[1 follow_branch(parent_key=node[1], branch=1, population=new_pop, target_nodes=target_nodes, child_key=key, dependent='none') ]
def _check_node(tree, key, direction): parent_key = tree[key][direction] return ((parent_key == 'r' or node_is_non_admixture(tree[parent_key])) and not parent_is_spouse(tree, key, other_branch(direction)) and (parent_key == 'r' or not halfbrother_is_uncle(tree, key, parent_key)) and (parent_key == 'r' or not (parent_is_spouse(tree, key, direction) and parent_is_sibling(tree, key, direction))))
def _add_to_waiting(dic, add, tree): key, pop, dep = add if key in dic: #this means that the node is a coalescence node dic[key][0][1] = pop dic[key][1][1] = dep else: if key == 'r' or node_is_non_admixture(tree[key]): dic[key] = [[pop, None], [dep, "empty"]] else: dic[key] = [[pop], [dep]] return dic
def get_possible_regrafters(tree): res = [] for key in tree: parents = get_real_parents(tree[key]) #print parents for branch, parent in enumerate(parents): #print key,(not is_root(parent)),node_is_non_admixture(tree[parent]),(not has_child_admixture(tree, parent)) #if (not is_root(parent)) and node_is_non_admixture(tree[parent]) and (not has_child_admixture(tree, parent)): if parent == 'r' or (node_is_non_admixture(tree[parent]) and not halfbrother_is_uncle(tree, key, parent)): res.append((key, branch)) return res