def find_right_bound(range_interval, align, node_index, tree_info, mapping_t, neighbors_ranges, ret_tuple_as_trans_desc): right_bound = cur_pos = range_interval.upper_bound while True: if cur_pos < range_interval.lower_bound: return -1 move = align[cur_pos] if not align_utils.is_log_move(move, ret_tuple_as_trans_desc): if align_utils.move_in_subtree(move, tree_info[node_index].tree_range, mapping_t): break move_in_right_neighbors = neighbors_ranges.is_in_range( align_utils.move_index(move, mapping_t, ret_tuple_as_trans_desc)) if align_utils.is_sync_move( move, ret_tuple_as_trans_desc) and move_in_right_neighbors: right_bound = cur_pos - 1 elif align_utils.is_model_move( move, ret_tuple_as_trans_desc) and move_in_right_neighbors: if cur_pos != right_bound: move_move(align, cur_pos, right_bound) right_bound -= 1 cur_pos -= 1 return right_bound
def find_left_bound(range_interval, align, node_index, tree_info, mapping_t, ret_tuple_as_trans_desc): left_bound = range_interval.lower_bound tree_range = tree_info[node_index].tree_range while True: if left_bound > range_interval.upper_bound: return -1 move = align[left_bound] if not align_utils.is_log_move(move, ret_tuple_as_trans_desc): model_index = align_utils.move_index(move, mapping_t, ret_tuple_as_trans_desc) if tree_range.is_in_range(model_index): break left_bound += 1 return left_bound
def remove_first_log_move(align, begin, mapping_t, subtree_range, ret_tuple_as_trans_desc): left_bound = begin while True: if left_bound == len(align): return None move = align[left_bound] if not align_utils.is_log_move(move, ret_tuple_as_trans_desc): move_cur_index = align_utils.move_index(move, mapping_t, ret_tuple_as_trans_desc) if subtree_range.is_in_range(move_cur_index): break left_bound += 1 return RangeInterval(left_bound, len(align) - 1)
def find_right_bound(range_interval, align, node_index, tree_info, mapping_t, ret_tuple_as_trans_desc): right_bound = cur_index = range_interval.upper_bound tree_range = tree_info[node_index].tree_range while True: if cur_index < range_interval.lower_bound: return -1 move = align[cur_index] if not align_utils.is_log_move(move, ret_tuple_as_trans_desc): model_index = align_utils.move_index(move, mapping_t, ret_tuple_as_trans_desc) if tree_range.is_in_range(model_index): break else: right_bound = cur_index - 1 cur_index -= 1 return right_bound
def apply(align, tree_info, mapping_t, com_res, stop_condition, ret_tuple_as_trans_desc): ranges = list() subtree_range = tree_info[com_res.subtree1.index].tree_range anchor = True range_interval = remove_first_log_move(align, 0, mapping_t, subtree_range, ret_tuple_as_trans_desc) if range_interval is not None: cur_index = left_bound = right_bound = range_interval.lower_bound while cur_index < len(align): move = align[cur_index] if align_utils.is_log_move(move, ret_tuple_as_trans_desc): if anchor: right_bound += 1 else: move_cur_index = align_utils.move_index( move, mapping_t, ret_tuple_as_trans_desc) if subtree_range.is_in_range(move_cur_index): anchor = True right_bound = cur_index elif stop_condition[0].is_in_range( move_cur_index) or stop_condition[1].is_in_range( move_cur_index): ranges.append(RangeInterval(left_bound, right_bound)) anchor = True range_interval = remove_first_log_move( align, cur_index, mapping_t, subtree_range, ret_tuple_as_trans_desc) if range_interval is None: break cur_index = left_bound = right_bound = range_interval.lower_bound else: anchor = False if cur_index == len(align) - 1: ranges.append(RangeInterval(left_bound, right_bound)) cur_index += 1 return ranges
def compute_ranges_for_loop(align, tree_info, mapping_t, node_index, ranges, ret_tuple_as_trans_desc): parent_node_index = tree_info[node_index].tree.parent.index if node_index == parent_node_index + 1: ub = tree_info[parent_node_index].tree_range.upper_bound nei_ranges = RangeInterval(tree_info[node_index].tree_range.upper_bound + 1, ub) else: lb = tree_info[parent_node_index].tree_range.lower_bound nei_ranges = RangeInterval(lb, tree_info[node_index].tree_range.lower_bound - 1) new_ranges = list() for range_interval in ranges: ri = compute_one_range_for_sequence(align, tree_info, mapping_t, node_index, range_interval, ret_tuple_as_trans_desc) if ri is not None: cur_pos = left_bound = ri.lower_bound while cur_pos <= ri.upper_bound: move = align[cur_pos] if not align_utils.is_log_move(move, ret_tuple_as_trans_desc): move_cur_index = align_utils.move_index(move, mapping_t, ret_tuple_as_trans_desc) move_in_nei = nei_ranges.is_in_range(move_cur_index) else: move_in_nei = False if move_in_nei or cur_pos == ri.upper_bound: new_ranges.append(compute_one_range_for_sequence(align, tree_info, mapping_t, node_index, RangeInterval(left_bound, cur_pos), ret_tuple_as_trans_desc)) ri = compute_one_range_for_sequence(align, tree_info, mapping_t, node_index, RangeInterval(cur_pos + 1, ri.upper_bound), ret_tuple_as_trans_desc) if ri is None: break elif ri.upper_bound == ri.lower_bound: new_ranges.append(RangeInterval(ri.lower_bound, ri.upper_bound)) left_bound = cur_pos = ri.lower_bound cur_pos += 1 return new_ranges
def compute_ranges_for_loop(align, tree_info, mapping_t, node_index, ranges, ret_tuple_as_trans_desc): parent_node_index = tree_info[node_index].tree.parent.index if node_index == parent_node_index + 1: ub = tree_info[parent_node_index].tree_range.upper_bound nei_ranges = RangeInterval( tree_info[node_index].tree_range.upper_bound + 1, ub) else: lb = tree_info[parent_node_index].tree_range.lower_bound nei_ranges = RangeInterval( lb, tree_info[node_index].tree_range.lower_bound - 1) new_ranges = list() for range_interval in ranges: ri = compute_one_range_for_sequence(align, tree_info, mapping_t, node_index, range_interval, nei_ranges, nei_ranges, ret_tuple_as_trans_desc) if ri is not None: left_bound = cur_pos = ri.lower_bound scatter_align = False while cur_pos <= ri.upper_bound: move = align[cur_pos] move_in_nei = True if not align_utils.is_log_move(move, ret_tuple_as_trans_desc): move_cur_index = align_utils.move_index( move, mapping_t, ret_tuple_as_trans_desc) move_in_nei = nei_ranges.is_in_range(move_cur_index) scatter_align = True if move_in_nei else scatter_align if scatter_align and align_utils.move_in_subtree( move, tree_info[node_index].tree_range, mapping_t): new_ranges.append( compute_one_range_for_sequence( align, tree_info, mapping_t, node_index, RangeInterval(left_bound, cur_pos - 1), nei_ranges, nei_ranges, ret_tuple_as_trans_desc)) ri = compute_one_range_for_sequence( align, tree_info, mapping_t, node_index, RangeInterval(cur_pos, ri.upper_bound), nei_ranges, nei_ranges, ret_tuple_as_trans_desc) if ri is None: break left_bound = cur_pos = ri.lower_bound scatter_align = False if (align_utils.is_sync_move(move, True) and move_in_nei) or cur_pos == ri.upper_bound: new_ranges.append( compute_one_range_for_sequence( align, tree_info, mapping_t, node_index, RangeInterval(left_bound, cur_pos), nei_ranges, nei_ranges, ret_tuple_as_trans_desc)) ri = compute_one_range_for_sequence( align, tree_info, mapping_t, node_index, RangeInterval(cur_pos + 1, ri.upper_bound), nei_ranges, nei_ranges, ret_tuple_as_trans_desc) if ri is None: break left_bound = cur_pos = ri.lower_bound scatter_align = False else: cur_pos += 1 return new_ranges