Esempio n. 1
0
    def update(self, strand5p: StrandT, idx: int = None):
        """Pass ``idx`` to this method in order to install a floating
        Xover for the forced xover tool

        Args:
            strand5p: Description
            idx: Default is ``None``
        """
        self._strand5p = strand5p
        strand3p = strand5p.connection3p()
        vhi5p = self._virtual_helix_item
        part_item = vhi5p.partItem()

        # This condition is for floating xovers
        idx_3_prime = idx if idx else strand5p.idx3Prime()

        if self._node5 is None:
            self._node5 = XoverNode5(vhi5p, self, strand5p, idx_3_prime)
        if strand3p is not None:
            if self._node3 is None:
                vhi3p = part_item.idToVirtualHelixItem(strand3p.idNum())
                self._node3 = XoverNode3(vhi3p, self, strand3p,
                                         strand3p.idx5Prime())
            else:
                self._node5.setIdx(idx_3_prime)
                self._node3.setIdx(strand3p.idx5Prime())
            self._node5.setPartnerVirtualHelix(strand5p)
            self._updatePath(strand5p)
        else:
            if self._node3:
                self._node3.destroyItem()
                self._node3 = None
Esempio n. 2
0
    def canInstallXoverAt(self, idx: int,
                                from_strand: StrandT,
                                from_idx: int) -> bool:
        """Assumes idx is:
        self.lowIdx() <= idx <= self.highIdx()
        """

        if self.hasXoverAt(idx):
            return False
        ss = self.strandSet()
        is_same_strand = from_strand == self

        is_forward = ss.isForward()
        index_diff_H = self.highIdx() - idx
        index_diff_L = idx - self.lowIdx()
        idx3p = self.idx3Prime()
        idx5p = self.idx5Prime()
        # ensure 2 bps from 3p end if not the 3p end
        index3_lim = idx3p - 1 if is_forward else idx3p + 1

        if is_same_strand:
            index_diff_strands = from_idx - idx
            if idx == idx5p or idx == index3_lim:
                return True
            elif index_diff_strands > -3 and index_diff_strands < 3:
                return False
        # end if for same Strand
        else:
            from_idx3p = from_strand.idx3Prime()
            from_idx5p = from_strand.idx5Prime()
            if idx == idx5p or idx == index3_lim:
                if from_idx3p == from_idx:
                    return True
                elif (abs(from_idx3p - from_idx) > 1 and
                      abs(from_idx5p - from_idx) > 1):
                    return True
                else:
                    # print("this:", idx, idx3p, idx5p)
                    # print("from:", from_idx, from_idx3p, from_idx5p)
                    return False
            elif index_diff_H > 2 and index_diff_L > 1:
                if from_idx3p == from_idx:
                    return True
                elif (abs(from_idx3p - from_idx) > 1 and
                      abs(from_idx5p - from_idx) > 1):
                    return True
                else:
                    return False
            else:
                # print("default", index_diff_H, index_diff_L)
                return False