Пример #1
0
def insert_gaps_in_pairs(pairs, gap_list):
    """Adjusts numbering in pairs according to the gap list.

    pairs: Pairs object
    gap_list: list of integers, gap positions in a sequence

    The main assumptionis that all positions in pairs correspond to
    ungapped positions. If this is not true, the result will be meaningless.
    """
    if not gap_list:
        new = Pairs()
        new.extend(pairs)
        return new

    ungapped = []
    for idx in range(max(gap_list)+2):
        if idx not in gap_list:
            ungapped.append(idx)
    new = Pairs()
    for x,y in pairs:
        if x is not None:
            try:
                new_x = ungapped[x]
            except IndexError:
                new_x = ungapped[-1] + (x-len(ungapped)+1)
        else:
            new_x = x
        if y is not None:
            try:
                new_y = ungapped[y]
            except IndexError:
                new_y = ungapped[-1] + (y-len(ungapped)+1)
        else:
            new_y = y
        new.append((new_x, new_y))
    return new
Пример #2
0
def insert_gaps_in_pairs(pairs, gap_list):
    """Adjusts numbering in pairs according to the gap list.

    pairs: Pairs object
    gap_list: list of integers, gap positions in a sequence

    The main assumptionis that all positions in pairs correspond to
    ungapped positions. If this is not true, the result will be meaningless.
    """
    if not gap_list:
        new = Pairs()
        new.extend(pairs)
        return new

    ungapped = []
    for idx in range(max(gap_list) + 2):
        if idx not in gap_list:
            ungapped.append(idx)
    new = Pairs()
    for x, y in pairs:
        if x is not None:
            try:
                new_x = ungapped[x]
            except IndexError:
                new_x = ungapped[-1] + (x - len(ungapped) + 1)
        else:
            new_x = x
        if y is not None:
            try:
                new_y = ungapped[y]
            except IndexError:
                new_y = ungapped[-1] + (y - len(ungapped) + 1)
        else:
            new_y = y
        new.append((new_x, new_y))
    return new
Пример #3
0
def delete_gaps_from_pairs(pairs, gap_list):
    """Returns Pairs object with pairs adjusted to gap_list

    pairs: list of tuples or Pairs object
    gap_list: list or array of gapped positions that should be removed
        from the pairs object

    Base pairs of which one of the partners or both of them are in 
        the gap list are removed. If both of them are not in the gap_list, the
        numbering is adjusted according to the gap_list.
    When at least one of the two pair members is in the gap_list, the
        pair will be removed. The rest of the structure will be left
        intact. Pairs containing None, duplicates, pseudoknots, and 
        conflicts will be maintained and adjusted according to the gap_list.
    """
    if not gap_list:
        result = Pairs()
        result.extend(pairs)
        return result

    g = array(gap_list)
    result = Pairs()
    for up, down in pairs:
        if up in g or down in g:
            continue
        else:
            if up is not None:
                new_up = up - g.searchsorted(up)
            else:
                new_up = up
            if down is not None:
                new_down = down - g.searchsorted(down)
            else:
                new_down = down
            result.append((new_up, new_down))
    return result
Пример #4
0
def delete_gaps_from_pairs(pairs, gap_list):
    """Returns Pairs object with pairs adjusted to gap_list

    pairs: list of tuples or Pairs object
    gap_list: list or array of gapped positions that should be removed
        from the pairs object

    Base pairs of which one of the partners or both of them are in 
        the gap list are removed. If both of them are not in the gap_list, the
        numbering is adjusted according to the gap_list.
    When at least one of the two pair members is in the gap_list, the
        pair will be removed. The rest of the structure will be left
        intact. Pairs containing None, duplicates, pseudoknots, and 
        conflicts will be maintained and adjusted according to the gap_list.
    """
    if not gap_list:
        result = Pairs()
        result.extend(pairs)
        return result

    g = array(gap_list)
    result = Pairs()
    for up, down in pairs:
        if equal(g, up).any() or equal(g, down).any():
            continue

        if up is not None:
            new_up = up - g.searchsorted(up)
        else:
            new_up = up
        if down is not None:
            new_down = down - g.searchsorted(down)
        else:
            new_down = down
        result.append((new_up, new_down))
    return result