def getLegacyStrandSetArray(ss: StrandSetT, max_base_idx: int) -> List[List[int]]: """Given a strandset and max_base_idx, return legacy serialization array format.""" num = ss.idNum() ret = [[-1, -1, -1, -1] for i in range(max_base_idx)] if ss.isForward(): for strand in ss.strands(): lo, hi = strand.idxs() assert strand.idx5Prime() == lo and strand.idx3Prime() == hi # map the first base (5' xover if necessary) s5p = strand.connection5p() if s5p is not None: ret[lo][0] = s5p.idNum() ret[lo][1] = s5p.idx3Prime() ret[lo][2] = num ret[lo][3] = lo + 1 # map the internal bases for idx in range(lo + 1, hi): ret[idx][0] = num ret[idx][1] = idx - 1 ret[idx][2] = num ret[idx][3] = idx + 1 # map the last base (3' xover if necessary) ret[hi][0] = num ret[hi][1] = hi - 1 s3p = strand.connection3p() if s3p is not None: ret[hi][2] = s3p.idNum() ret[hi][3] = s3p.idx5Prime() # end if # end for # end if else: for strand in ss.strands(): lo, hi = strand.idxs() assert strand.idx3Prime() == lo and strand.idx5Prime() == hi # map the first base (3' xover if necessary) ret[lo][0] = num ret[lo][1] = lo + 1 s3p = strand.connection3p() if s3p is not None: ret[lo][2] = s3p.idNum() ret[lo][3] = s3p.idx5Prime() # map the internal bases for idx in range(lo + 1, hi): ret[idx][0] = num ret[idx][1] = idx + 1 ret[idx][2] = num ret[idx][3] = idx - 1 # map the last base (5' xover if necessary) ret[hi][2] = num ret[hi][3] = hi - 1 s5p = strand.connection5p() if s5p is not None: ret[hi][0] = s5p.idNum() ret[hi][1] = s5p.idx3Prime() # end if # end for return ret
def initStrandItemFromVHI(self, virtual_helix_item: PathVirtualHelixItemT, strand_set: StrandSetT, idx: int): """Called from VHI createToolMousePress. Stores the starting point of the strand to be created. Args: virtual_helix_item: reference to the VHI strand_set (StrandSet): reference to the clicked strand_set idx (int): index where clicked """ s_i = self._temp_strand_item self._start_idx = idx self._start_strand_set = strand_set s_i.resetStrandItem(virtual_helix_item, strand_set.isForward()) self._low_drag_bound, self._high_drag_bound = strand_set.getBoundsOfEmptyRegionContaining(idx)
def initStrandItemFromVHI(self, virtual_helix_item: PathVirtualHelixItemT, strand_set: StrandSetT, idx: int): """Called from VHI createToolMousePress. Stores the starting point of the strand to be created. Args: virtual_helix_item: reference to the VHI strand_set (StrandSet): reference to the clicked strand_set idx (int): index where clicked """ s_i = self._temp_strand_item self._start_idx = idx self._start_strand_set = strand_set s_i.resetStrandItem(virtual_helix_item, strand_set.isForward()) self._low_drag_bound, self._high_drag_bound = strand_set.getBoundsOfEmptyRegionContaining( idx)
def __init__(self, strandset: StrandSetT, base_idx_low: int, base_idx_high: int, oligo: OligoT = None): self._document = strandset.document() super(Strand, self).__init__(strandset) self._strandset = strandset self._id_num = strandset.idNum() """Keep track of its own segments. Updated on creation and resizing """ self._base_idx_low = base_idx_low # base index of the strand's left bound self._base_idx_high = base_idx_high # base index of the right bound self._oligo = oligo self._strand5p = None # 5' connection to another strand self._strand3p = None # 3' connection to another strand self._sequence = None self.segments = [] self.abstract_sequence = [] # dynamic methods for mapping high/low connection /indices # to corresponding 3Prime 5Prime is_forward = strandset.isForward() if is_forward: self.idx5Prime = self.lowIdx self.idx3Prime = self.highIdx self.connectionLow = self.connection5p self.connectionHigh = self.connection3p self.setConnectionLow = self.setConnection5p self.setConnectionHigh = self.setConnection3p else: self.idx5Prime = self.highIdx self.idx3Prime = self.lowIdx self.connectionLow = self.connection3p self.connectionHigh = self.connection5p self.setConnectionLow = self.setConnection3p self.setConnectionHigh = self.setConnection5p self._is_forward = is_forward