Example #1
0
 def __init__(self, strandset, base_idx_low, base_idx_high, strandset_idx):
     super(CreateStrandCommand, self).__init__("create strand")
     self._strandset = strandset
     self._s_set_idx = strandset_idx
     self._domain = Domain(strandset,base_idx_low,base_idx_high)
     colorList = prefs.STAP_COLORS if strandset.isStaple() else prefs.SCAF_COLORS
     color = random.choice(colorList).name()
     self._new_oligo = Oligo(None, color)  # redo will set part
     self._new_oligo.setLength(self._domain.totalLength())
Example #2
0
class CreateStrandCommand(UndoCommand):
    """
    Create a new Strand based with bounds (base_idx_low, base_idx_high),
    and insert it into the strandset at position strandset_idx. Also,
    create a new Oligo, add it to the Part, and point the new Strand
    at the oligo.
    """
    def __init__(self, strandset, base_idx_low, base_idx_high, strandset_idx):
        super(CreateStrandCommand, self).__init__("create strand")
        self._strandset = strandset
        self._s_set_idx = strandset_idx
        self._domain = Domain(strandset,base_idx_low,base_idx_high)
        colorList = prefs.STAP_COLORS if strandset.isStaple() else prefs.SCAF_COLORS
        color = random.choice(colorList).name()
        self._new_oligo = Oligo(None, color)  # redo will set part
        self._new_oligo.setLength(self._domain.totalLength())
    # end def

    def redo(self):
        # Add the new strand to the StrandSet strand_list
        domain = self._domain
        strandset = self._strandset
        strandset._addToStrandList(domain,self._s_set_idx)
        # Set up the new oligo
        oligo = self._new_oligo
        oligo.setStrand5p(domain)
        oligo.addToPart(strandset.part())
        domain.setOligo(oligo)
        # Emit signal to virtual helix item upon completion
        strandset.strandsetStrandAddedSignal.emit(strandset, domain) #vhitem strandAddedSlot
        # for updating the Slice View displayed helices
        strandset.part().partStrandChangedSignal.emit(strandset.part(), strandset.virtualHelix())
    # end def

    def undo(self):
        # Remove the strand from StrandSet strand_list and selectionList
        strand = self._domain
        strandset = self._domainset
        strandset._doc.removeStrandFromSelection(strand)
        strandset.removeDomainFromStrandList.pop(self._s_set_idx)
        # Get rid of the new oligo
        oligo = self._new_oligo
        oligo.setStrand5p(None)
        oligo.removeFromPart()
        # Emit a signal to notify on completion
        strand.strandRemovedSignal.emit(strand)
        strand.setOligo(None)
        # for updating the Slice View displayed helices
        strandset.part().partStrandChangedSignal.emit(strandset.part(), strandset.virtualHelix())
    # end def
# end class
    def redo(self):
        '''
        domains connected by connection3p or connection5p will have the same oligo;
        connection3p and connection5p are pointers to domains crossover-ed to, added
        when installing xover.
        '''
        visited = {}
        doc = self._part.document()
        for vh in self._part.getVirtualHelices():
            stap_ss = vh.stapleStrandSet()
            list = stap_ss.getStrandList()
            for strand in stap_ss:
                visited[strand] = False
            if self.include_scaffold:
                scap_ss = vh.scaffoldStrandSet()
                for strand in scap_ss:
                    visited[strand] = False

        colors = self.colors
        for strand in visited.keys():
            if visited[strand]:
                continue
            visited[strand] = True
            start_oligo = strand.oligo()

            if colors is not None:
                if strand.isStaple():
                    start_oligo.setColor(colors[1])
                else:
                    start_oligo.setColor(colors[0])

            strand5gen = strand.generator5pStrand()
            # this gets the oligo and burns a strand in the generator
            strand5 = next(strand5gen)
            for strand5 in strand5gen:
                oligo5 = strand5.oligo()
                if oligo5 != start_oligo:
                    oligo5.removeFromPart()
                    Domain.setOligo(strand5, start_oligo)  # emits strandHasNewOligoSignal
                visited[strand5] = True
            # end for
            start_oligo.setStrand5p(strand5)
            # is it a loop?
            if strand.connection3p() == strand5:
                start_oligo.setLoop(True)
            else:
                strand3gen = strand.generator3pStrand()
                strand3 = next(strand3gen)   # burn one
                for strand3 in strand3gen:
                    oligo3 = strand3.oligo()
                    if oligo3 != start_oligo:
                        oligo3.removeFromPart()
                        Domain.setOligo(strand3, start_oligo)  # emits strandHasNewOligoSignal
                    visited[strand3] = True
                # end for
            start_oligo.refreshLength()

        # end for

        for strand in visited.keys():
            strand.strandUpdateSignal.emit(strand)