示例#1
0
    def _strandMergeUpdate(self, old_strand_low: Strand,
                                old_strand_high: Strand,
                                new_strand: Strand):
        """This method sets the isCircular status of the oligo and the oligo's
        5' strand.
        """
        # check loop status
        if old_strand_low.oligo() == old_strand_high.oligo():
            self._is_circular = True
            self._strand5p = new_strand
            return
            # leave the _strand5p as is?
        # end if

        # Now get correct 5p end to oligo
        if old_strand_low.isForward():
            if old_strand_low.connection5p() is not None:
                self._strand5p = old_strand_low.oligo()._strand5p
            else:
                self._strand5p = new_strand
        else:
            if old_strand_high.connection5p() is not None:
                self._strand5p = old_strand_high.oligo()._strand5p
            else:
                self._strand5p = new_strand
示例#2
0
    def __init__(self, strandset: StrandSetT, strand: Strand, solo: bool = True):
        super(RemoveStrandCommand, self).__init__("remove strands")
        self._strandset = strandset
        self._strand = strand
        self._solo = solo
        self._old_strand5p = strand.connection5p()
        self._old_strand3p = strand.connection3p()
        self._oligo = olg = strand.oligo()

        part = strand.part()
        # idxs = strand.idxs()
        self.mids = (part.getModID(strand, strand.lowIdx()),
                     part.getModID(strand, strand.highIdx()))

        # only create a new 5p oligo if there is a 3' connection
        self._new_oligo5p = olg.shallowCopy() if self._old_strand5p else None
        if olg.isCircular() or self._old_strand3p is None:
            self._new_oligo3p = olg3p = None
            if self._new_oligo5p:
                self._new_oligo5p._setLoop(False)
        else:
            self._new_oligo3p = olg3p = olg.shallowCopy()
            olg3p.setStrand5p(self._old_strand3p)
            # color_list = styles.STAP_COLORS if strandset.isStaple() else prefs.SCAF_COLORS
            color_list = pathstyles.STAP_COLORS
            color = random.choice(color_list)
            olg3p._setColor(color)
            olg3p.refreshLength(emit_signals=True)
    def __init__(self,
                 strandset: StrandSetT,
                 strand: Strand,
                 solo: bool = True):
        super(RemoveStrandCommand, self).__init__("remove strands")
        self._strandset = strandset
        self._strand = strand
        self._solo = solo
        self._old_strand5p = strand.connection5p()
        self._old_strand3p = strand.connection3p()
        self._oligo = olg = strand.oligo()

        part = strand.part()
        # idxs = strand.idxs()
        self.mids = (part.getModID(strand, strand.lowIdx()),
                     part.getModID(strand, strand.highIdx()))

        # only create a new 5p oligo if there is a 3' connection
        self._new_oligo5p = olg.shallowCopy() if self._old_strand5p else None
        if olg.isCircular() or self._old_strand3p is None:
            self._new_oligo3p = olg3p = None
            if self._new_oligo5p:
                self._new_oligo5p._setLoop(False)
        else:
            self._new_oligo3p = olg3p = olg.shallowCopy()
            olg3p.setStrand5p(self._old_strand3p)
            # color_list = styles.STAP_COLORS if strandset.isStaple() else prefs.SCAF_COLORS
            color_list = pathstyles.STAP_COLORS
            color = random.choice(color_list)
            olg3p._setColor(color)
            olg3p.refreshLength(emit_signals=True)
示例#4
0
 def _strandSplitUpdate(self, new_strand5p: Strand, new_strand3p: Strand,
                        oligo3p: OligoT, old_merged_strand: Strand):
     """If the oligo is a loop, splitting the strand does nothing. If the
     oligo isn't a loop, a new oligo must be created and assigned to the
     new_strand and everything connected to it downstream.
     """
     # if you split it can't be a loop
     self._is_circular = False
     if old_merged_strand.oligo().isCircular():
         self._strand5p = new_strand3p
         return
     else:
         if old_merged_strand.connection5p() is None:
             self._strand5p = new_strand5p
         else:
             self._strand5p = old_merged_strand.oligo()._strand5p
         oligo3p._strand5p = new_strand3p
示例#5
0
    def __init__(self, strand_low: Strand, strand_high: Strand,
                 priority_strand: Strand):
        super(MergeCommand, self).__init__("merge strands")
        # Store strands
        self._strand_low = strand_low
        self._strand_high = strand_high

        self._s_set = s_set = priority_strand.strandSet()
        # Store oligos
        self._new_oligo = priority_strand.oligo().shallowCopy()
        self._s_low_oligo = s_low_olg = strand_low.oligo()
        self._s_high_oligo = s_high_olg = strand_high.oligo()

        # self._s_set_idx = low_strandset_idx

        # update the new oligo length if it's not a loop
        if s_low_olg != s_high_olg:
            self._new_oligo._setLength(s_low_olg.length() +
                                       s_high_olg.length(),
                                       emit_signals=True)

        # Create the new_strand by copying the priority strand to
        # preserve its properties
        new_idxs = strand_low.lowIdx(), strand_high.highIdx()
        new_strand = strand_low.shallowCopy()
        new_strand.setIdxs(new_idxs)
        new_strand.setConnectionHigh(strand_high.connectionHigh())

        self._new_strand = new_strand
        # Update the oligo for things like its 5prime end and isCircular
        self._new_oligo._strandMergeUpdate(strand_low, strand_high, new_strand)

        # set the new sequence by concatenating the sequence properly
        if strand_low._sequence or strand_high._sequence:
            tL = strand_low.totalLength()
            tH = strand_high.totalLength()
            seqL = strand_low._sequence if strand_low._sequence else "".join(
                [" " for i in range(tL)])
            seqH = strand_high._sequence if strand_high._sequence else "".join(
                [" " for i in range(tH)])
            if new_strand.isForward():
                new_strand._sequence = seqL + seqH
            else:
                new_strand._sequence = seqH + seqL
示例#6
0
    def __init__(self,  part: NucleicAcidPartT,
                        strand5p: Strand, strand3p: Strand):
        super(RemoveXoverCommand, self).__init__("remove xover")
        self._part = part
        self._strand5p = strand5p
        self._strand5p_idx = strand5p.idx3Prime()
        self._strand3p = strand3p
        self._strand3p_idx = strand3p.idx5Prime()
        n_o3p = self._new_oligo3p = strand3p.oligo().shallowCopy()

        color_list = pathstyles.STAP_COLORS
        n_o3p._setColor(random.choice(color_list))
        n_o3p._setLength(0, emit_signals=True)
        for strand in strand3p.generator3pStrand():
            n_o3p._incrementLength(strand.totalLength(), emit_signals=True)
        # end def
        n_o3p.setStrand5p(strand3p)

        self._isCircular = strand3p.oligo().isCircular()
示例#7
0
    def __init__(self, part: NucleicAcidPartT, strand5p: Strand,
                 strand3p: Strand):
        super(RemoveXoverCommand, self).__init__("remove xover")
        self._part = part
        self._strand5p = strand5p
        self._strand5p_idx = strand5p.idx3Prime()
        self._strand3p = strand3p
        self._strand3p_idx = strand3p.idx5Prime()
        n_o3p = self._new_oligo3p = strand3p.oligo().shallowCopy()

        color_list = pathstyles.STAP_COLORS
        n_o3p._setColor(random.choice(color_list))
        n_o3p._setLength(0, emit_signals=True)
        for strand in strand3p.generator3pStrand():
            n_o3p._incrementLength(strand.totalLength(), emit_signals=True)
        # end def
        n_o3p.setStrand5p(strand3p)

        self._isCircular = strand3p.oligo().isCircular()
示例#8
0
 def _strandSplitUpdate(self, new_strand5p: Strand,
                             new_strand3p: Strand,
                             oligo3p: OligoT,
                             old_merged_strand: Strand):
     """If the oligo is a loop, splitting the strand does nothing. If the
     oligo isn't a loop, a new oligo must be created and assigned to the
     new_strand and everything connected to it downstream.
     """
     # if you split it can't be a loop
     self._is_circular = False
     if old_merged_strand.oligo().isCircular():
         self._strand5p = new_strand3p
         return
     else:
         if old_merged_strand.connection5p() is None:
             self._strand5p = new_strand5p
         else:
             self._strand5p = old_merged_strand.oligo()._strand5p
         oligo3p._strand5p = new_strand3p
示例#9
0
    def __init__(self, strand_low: Strand,
                        strand_high: Strand,
                        priority_strand: Strand):
        super(MergeCommand, self).__init__("merge strands")
        # Store strands
        self._strand_low = strand_low
        self._strand_high = strand_high

        self._s_set = s_set = priority_strand.strandSet()
        # Store oligos
        self._new_oligo = priority_strand.oligo().shallowCopy()
        self._s_low_oligo = s_low_olg = strand_low.oligo()
        self._s_high_oligo = s_high_olg = strand_high.oligo()

        # self._s_set_idx = low_strandset_idx

        # update the new oligo length if it's not a loop
        if s_low_olg != s_high_olg:
            self._new_oligo._setLength(s_low_olg.length() + s_high_olg.length(),
                                       emit_signals=True)

        # Create the new_strand by copying the priority strand to
        # preserve its properties
        new_idxs = strand_low.lowIdx(), strand_high.highIdx()
        new_strand = strand_low.shallowCopy()
        new_strand.setIdxs(new_idxs)
        new_strand.setConnectionHigh(strand_high.connectionHigh())

        self._new_strand = new_strand
        # Update the oligo for things like its 5prime end and isCircular
        self._new_oligo._strandMergeUpdate(strand_low, strand_high, new_strand)

        # set the new sequence by concatenating the sequence properly
        if strand_low._sequence or strand_high._sequence:
            tL = strand_low.totalLength()
            tH = strand_high.totalLength()
            seqL = strand_low._sequence if strand_low._sequence else "".join([" " for i in range(tL)])
            seqH = strand_high._sequence if strand_high._sequence else "".join([" " for i in range(tH)])
            if new_strand.isForward():
                new_strand._sequence = seqL + seqH
            else:
                new_strand._sequence = seqH + seqL
示例#10
0
 def __init__(self,  part: NucleicAcidPartT,
                     strand5p: Strand, strand5p_idx: int,
                     strand3p: Strand, strand3p_idx: int,
                     update_oligo: bool = True):
     super(CreateXoverCommand, self).__init__("create xover")
     self._part = part
     self._strand5p = strand5p
     self._strand5p_idx = strand5p_idx
     self._strand3p = strand3p
     self._strand3p_idx = strand3p_idx
     self._old_oligo3p = strand3p.oligo()
     self._update_oligo = update_oligo
示例#11
0
    def _strandMergeUpdate(self, old_strand_low: Strand,
                           old_strand_high: Strand, new_strand: Strand):
        """This method sets the isCircular status of the oligo and the oligo's
        5' strand.
        """
        # check loop status
        if old_strand_low.oligo() == old_strand_high.oligo():
            self._is_circular = True
            self._strand5p = new_strand
            return
            # leave the _strand5p as is?
        # end if

        # Now get correct 5p end to oligo
        if old_strand_low.isForward():
            if old_strand_low.connection5p() is not None:
                self._strand5p = old_strand_low.oligo()._strand5p
            else:
                self._strand5p = new_strand
        else:
            if old_strand_high.connection5p() is not None:
                self._strand5p = old_strand_high.oligo()._strand5p
            else:
                self._strand5p = new_strand
示例#12
0
 def __init__(self,
              part: NucleicAcidPartT,
              strand5p: Strand,
              strand5p_idx: int,
              strand3p: Strand,
              strand3p_idx: int,
              update_oligo: bool = True):
     super(CreateXoverCommand, self).__init__("create xover")
     self._part = part
     self._strand5p = strand5p
     self._strand5p_idx = strand5p_idx
     self._strand3p = strand3p
     self._strand3p_idx = strand3p_idx
     self._old_oligo3p = strand3p.oligo()
     self._update_oligo = update_oligo
示例#13
0
    def __init__(self, strand: Strand, base_idx: int, update_sequence: bool = True):
        super(SplitCommand, self).__init__("split strand")
        # Store inputs
        self._old_strand = strand
        # TODO possibly implement selection preserving
        # doc = strand.document()
        # self.was_selected = was_selected = doc.isModelStrandSelected(strand)
        # if was_selected:
        #     self.select_values = doc.getSelectedStrandValue(strand)
        # else:
        #     self.select_values = (None, None)

        old_sequence = strand._sequence
        is5to3 = strand.isForward()

        self._s_set = strand.strandSet()
        self._old_oligo = oligo = strand.oligo()
        # Create copies
        self.strand_low = strand_low = strand.shallowCopy()
        self.strand_high = strand_high = strand.shallowCopy()

        if oligo.isCircular():
            self._l_oligo = self._h_oligo = l_oligo = h_oligo = oligo.shallowCopy()
        else:
            self._l_oligo = l_oligo = oligo.shallowCopy()
            self._h_oligo = h_oligo = oligo.shallowCopy()

        color_list = pathstyles.STAP_COLORS

        # Determine oligo retention based on strand priority
        if is5to3:  # strand_low has priority
            i_new_low = base_idx
            color_low = oligo.getColor()
            color_high = random.choice(color_list)
            olg5p, olg3p = l_oligo, h_oligo
            std5p, std3p = strand_low, strand_high
        else:  # strand_high has priority
            i_new_low = base_idx - 1
            color_low = random.choice(color_list)
            color_high = oligo.getColor()
            olg5p, olg3p = h_oligo, l_oligo
            std5p, std3p = strand_high, strand_low
        # this is for updating a connected xover view object
        # there is only ever one xover a strand is in charge of
        self._strand3p = std3p
        self._strand5p = std5p

        # Update strand connectivity
        strand_low.setConnectionHigh(None)
        strand_high.setConnectionLow(None)

        # Resize strands and update decorators
        strand_low.setIdxs((strand.lowIdx(), i_new_low))
        strand_high.setIdxs((i_new_low + 1, strand.highIdx()))

        # Update the oligo for things like its 5prime end and isCircular
        olg5p._strandSplitUpdate(std5p, std3p, olg3p, strand)

        if not oligo.isCircular():
            # Update the oligo color if necessary
            l_oligo._setColor(color_low)
            h_oligo._setColor(color_high)
            # settle the oligo length
            length = 0
            for strand in std3p.generator3pStrand():
                length += strand.totalLength()
            # end for
            olg5p._setLength(olg5p.length() - length, emit_signals=True)
            olg3p._setLength(length, emit_signals=True)
        # end if

        if update_sequence and old_sequence:
            if is5to3:  # strand_low has priority
                tL = strand_low.totalLength()
                strand_low._sequence = old_sequence[0:tL]
                strand_high._sequence = old_sequence[tL:]
            else:
                tH = strand_high.totalLength()
                strand_high._sequence = old_sequence[0:tH]
                strand_low._sequence = old_sequence[tH:]