Example #1
0
    def autoScafRaster(self, strands):
        """docstring for autoScafRaster"""
        part = self.part()
        idx = part.activeBaseIndex()
        for i in range(1, len(strands)):
            row1, col1, ss_idx1 = strands[i - 1]  # previous strand
            row2, col2, ss_idx2 = strands[i]  # current strand
            vh1 = part.virtualHelixAtCoord((row1, col1))
            vh2 = part.virtualHelixAtCoord((row2, col2))
            strand1 = vh1.scaffoldStrandSet()._strand_list[ss_idx1]
            strand2 = vh2.scaffoldStrandSet()._strand_list[ss_idx2]
            # determine if the pair of strands are neighbors
            neighbors = part.getVirtualHelixNeighbors(vh1)
            if vh2 in neighbors:
                p2 = neighbors.index(vh2)
                if vh2.number() % 2 == 1:
                    # resize and install external xovers
                    try:
                        # resize to the nearest prexover on either side of idx
                        new_lo1 = new_lo2 = util.nearest(idx, 
                            part.getPreXoversHigh(StrandType.SCAFFOLD, 
                                p2, max_idx=idx - 8))
                        new_hi = util.nearest(idx, 
                            part.getPreXoversLow(StrandType.SCAFFOLD, 
                                p2, min_idx=idx + 8))

                        if vh1.number() != 0:  # after the first helix
                            new_lo1 = strand1.lowIdx()  # leave alone the lowIdx

                        if vh2.number() != len(strands)-1:  # before the last
                            new_lo2 = strand2.lowIdx()  # leave alone the lowIdx

                        if strand1.canResizeTo(new_lo1, new_hi) and \
                           strand2.canResizeTo(new_lo2, new_hi):
                            strand1.resize((new_lo1, new_hi))
                            strand2.resize((new_lo2, new_hi))
                        else:
                            raise ValueError
                        # install xovers
                        part.createXover(strand1, new_hi, strand2, new_hi)
                    except ValueError:
                        pass  # nearest not found in the expanded list
                else:
                    # resize and install external xovers
                    idx = part.activeBaseIndex()
                    try:
                        # resize to the nearest prexover on either side of idx
                        new_lo = util.nearest(idx, 
                            part.getPreXoversHigh(StrandType.SCAFFOLD, 
                                p2, max_idx=idx - 8))

                        if strand1.canResizeTo(new_lo, strand1.highIdx()) and \
                           strand2.canResizeTo(new_lo, strand2.highIdx()):
                            strand1.resize((new_lo, strand1.highIdx()))
                            strand2.resize((new_lo, strand2.highIdx()))
                            # install xovers
                            part.createXover(strand1, new_lo, strand2, new_lo)
                        else:
                            raise ValueError
                    except ValueError:
                        pass  # nearest not found in the expanded list
Example #2
0
    def autoScafRaster(self, strands):
        """docstring for autoScafRaster"""
        part = self.part()
        idx = part.activeBaseIndex()
        for i in range(1, len(strands)):
            row1, col1, ss_idx1 = strands[i - 1]  # previous strand
            row2, col2, ss_idx2 = strands[i]  # current strand
            vh1 = part.virtualHelixAtCoord((row1, col1))
            vh2 = part.virtualHelixAtCoord((row2, col2))
            strand1 = vh1.scaffoldStrandSet()._strand_list[ss_idx1]
            strand2 = vh2.scaffoldStrandSet()._strand_list[ss_idx2]
            # determine if the pair of strands are neighbors
            neighbors = part.getVirtualHelixNeighbors(vh1)
            if vh2 in neighbors:
                p2 = neighbors.index(vh2)
                if vh2.number() % 2 == 1:
                    # resize and install external xovers
                    try:
                        # resize to the nearest prexover on either side of idx
                        new_lo1 = new_lo2 = util.nearest(
                            idx,
                            part.getPreXoversHigh(StrandType.SCAFFOLD,
                                                  p2,
                                                  max_idx=idx - 8))
                        new_hi = util.nearest(
                            idx,
                            part.getPreXoversLow(StrandType.SCAFFOLD,
                                                 p2,
                                                 min_idx=idx + 8))

                        if vh1.number() != 0:  # after the first helix
                            new_lo1 = strand1.lowIdx(
                            )  # leave alone the lowIdx

                        if vh2.number() != len(strands) - 1:  # before the last
                            new_lo2 = strand2.lowIdx(
                            )  # leave alone the lowIdx

                        if strand1.canResizeTo(new_lo1, new_hi) and \
                           strand2.canResizeTo(new_lo2, new_hi):
                            strand1.resize((new_lo1, new_hi))
                            strand2.resize((new_lo2, new_hi))
                        else:
                            raise ValueError
                        # install xovers
                        part.createXover(strand1, new_hi, strand2, new_hi)
                    except ValueError:
                        pass  # nearest not found in the expanded list
                else:
                    # resize and install external xovers
                    idx = part.activeBaseIndex()
                    try:
                        # resize to the nearest prexover on either side of idx
                        new_lo = util.nearest(
                            idx,
                            part.getPreXoversHigh(StrandType.SCAFFOLD,
                                                  p2,
                                                  max_idx=idx - 8))

                        if strand1.canResizeTo(new_lo, strand1.highIdx()) and \
                           strand2.canResizeTo(new_lo, strand2.highIdx()):
                            strand1.resize((new_lo, strand1.highIdx()))
                            strand2.resize((new_lo, strand2.highIdx()))
                            # install xovers
                            part.createXover(strand1, new_lo, strand2, new_lo)
                        else:
                            raise ValueError
                    except ValueError:
                        pass  # nearest not found in the expanded list
Example #3
0
    def autoScafMidSeam(self, strands):
        """docstring for autoScafMidSeam"""
        part = self.part()
        strand_type = StrandType.SCAFFOLD
        idx = part.activeBaseIndex()
        for i in range(1, len(strands)):
            row1, col1, ss_idx1 = strands[i - 1]  # previous strand
            row2, col2, ss_idx2 = strands[i]  # current strand
            vh1 = part.virtualHelixAtCoord((row1, col1))
            vh2 = part.virtualHelixAtCoord((row2, col2))
            strand1 = vh1.scaffoldStrandSet()._strand_list[ss_idx1]
            strand2 = vh2.scaffoldStrandSet()._strand_list[ss_idx2]
            # determine if the pair of strands are neighbors
            neighbors = part.getVirtualHelixNeighbors(vh1)
            if vh2 in neighbors:
                p2 = neighbors.index(vh2)
                if vh2.number() % 2 == 1:
                    # resize and install external xovers
                    try:
                        # resize to the nearest prexover on either side of idx
                        new_lo = util.nearest(idx, 
                            part.getPreXoversHigh(strand_type, p2, max_idx=idx - 10))
                        new_hi = util.nearest(idx, 
                            part.getPreXoversLow(strand_type, p2, min_idx=idx + 10))
                        if strand1.canResizeTo(new_lo, new_hi) and \
                           strand2.canResizeTo(new_lo, new_hi):
                            # do the resize
                            strand1.resize((new_lo, new_hi))
                            strand2.resize((new_lo, new_hi))
                            # install xovers
                            part.createXover(strand1, new_hi, strand2, new_hi)
                            part.createXover(strand2, new_lo, strand1, new_lo)
                    except ValueError:
                        pass  # nearest not found in the expanded list

                    # go back an install the internal xovers
                    if i > 2:
                        row0, col0, ss_idx0 = strands[i - 2]  # two strands back
                        vh0 = part.virtualHelixAtCoord((row0, col0))
                        strand0 = vh0.scaffoldStrandSet()._strand_list[ss_idx0]
                        if vh0 in neighbors:
                            p0 = neighbors.index(vh0)
                            l0, h0 = strand0.idxs()
                            l1, h1 = strand1.idxs()
                            o_low, o_high = util.overlap(l0, h0, l1, h1)
                            try:
                                l_list = list(filter(lambda x: x > o_low and \
                                        x < o_high,
                                        part.getPreXoversLow(strand_type, p0)))
                                l_x = l_list[len(l_list) // 2]
                                h_list = list(filter(lambda x: x > o_low and \
                                        x < o_high,
                                        part.getPreXoversHigh(strand_type, p0)))
                                h_x = h_list[len(h_list) // 2]
                                # install high xover first
                                part.createXover(strand0, h_x, strand1, h_x)
                                # install low xover after getting new strands
                                # following the breaks caused by the high xover
                                strand3 = vh0.scaffoldStrandSet()._strand_list[ss_idx0]
                                strand4 = vh1.scaffoldStrandSet()._strand_list[ss_idx1]
                                part.createXover(strand4, l_x, strand3, l_x)
                            except IndexError:
                                pass  # filter was unhappy
Example #4
0
    def autoScafMidSeam(self, strands):
        """docstring for autoScafMidSeam"""
        part = self.part()
        strand_type = StrandType.SCAFFOLD
        idx = part.activeBaseIndex()
        for i in range(1, len(strands)):
            row1, col1, ss_idx1 = strands[i - 1]  # previous strand
            row2, col2, ss_idx2 = strands[i]  # current strand
            vh1 = part.virtualHelixAtCoord((row1, col1))
            vh2 = part.virtualHelixAtCoord((row2, col2))
            strand1 = vh1.scaffoldStrandSet()._strand_list[ss_idx1]
            strand2 = vh2.scaffoldStrandSet()._strand_list[ss_idx2]
            # determine if the pair of strands are neighbors
            neighbors = part.getVirtualHelixNeighbors(vh1)
            if vh2 in neighbors:
                p2 = neighbors.index(vh2)
                if vh2.number() % 2 == 1:
                    # resize and install external xovers
                    try:
                        # resize to the nearest prexover on either side of idx
                        new_lo = util.nearest(
                            idx,
                            part.getPreXoversHigh(strand_type,
                                                  p2,
                                                  max_idx=idx - 10))
                        new_hi = util.nearest(
                            idx,
                            part.getPreXoversLow(strand_type,
                                                 p2,
                                                 min_idx=idx + 10))
                        if strand1.canResizeTo(new_lo, new_hi) and \
                           strand2.canResizeTo(new_lo, new_hi):
                            # do the resize
                            strand1.resize((new_lo, new_hi))
                            strand2.resize((new_lo, new_hi))
                            # install xovers
                            part.createXover(strand1, new_hi, strand2, new_hi)
                            part.createXover(strand2, new_lo, strand1, new_lo)
                    except ValueError:
                        pass  # nearest not found in the expanded list

                    # go back an install the internal xovers
                    if i > 2:
                        row0, col0, ss_idx0 = strands[i -
                                                      2]  # two strands back
                        vh0 = part.virtualHelixAtCoord((row0, col0))
                        strand0 = vh0.scaffoldStrandSet()._strand_list[ss_idx0]
                        if vh0 in neighbors:
                            p0 = neighbors.index(vh0)
                            l0, h0 = strand0.idxs()
                            l1, h1 = strand1.idxs()
                            o_low, o_high = util.overlap(l0, h0, l1, h1)
                            try:
                                l_list = list(filter(lambda x: x > o_low and \
                                        x < o_high,
                                        part.getPreXoversLow(strand_type, p0)))
                                l_x = l_list[len(l_list) // 2]
                                h_list = list(filter(lambda x: x > o_low and \
                                        x < o_high,
                                        part.getPreXoversHigh(strand_type, p0)))
                                h_x = h_list[len(h_list) // 2]
                                # install high xover first
                                part.createXover(strand0, h_x, strand1, h_x)
                                # install low xover after getting new strands
                                # following the breaks caused by the high xover
                                strand3 = vh0.scaffoldStrandSet(
                                )._strand_list[ss_idx0]
                                strand4 = vh1.scaffoldStrandSet(
                                )._strand_list[ss_idx1]
                                part.createXover(strand4, l_x, strand3, l_x)
                            except IndexError:
                                pass  # filter was unhappy