示例#1
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
        doc = strandset.document()
        self._strand = Strand(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._strand.totalLength())
    # end def

    def redo(self):
        # Add the new strand to the StrandSet strand_list
        strand = self._strand
        strandset = self._strandset
        strandset._strand_list.insert(self._s_set_idx, strand)
        # Set up the new oligo
        oligo = self._new_oligo
        oligo.setStrand5p(strand)
        oligo.addToPart(strandset.part())
        strand.setOligo(oligo)

        if strandset.isStaple():
            strand.reapplySequence()
        # Emit a signal to notify on completion
        strandset.strandsetStrandAddedSignal.emit(strandset, strand)
        # 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._strand
        strandset = self._strandset
        strandset._doc.removeStrandFromSelection(strand)
        strandset._strand_list.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
示例#2
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
     doc = strandset.document()
     self._strand = Strand(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._strand.totalLength())
示例#3
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())
示例#4
0
    def deselectOligo(self, oligo: Oligo):
        """Deselect given ``Oligo``

        Args:
            oligo: ``Oligo`` object
        """
        strand5p = oligo.strand5p()
        for strand in strand5p.generator3pStrand():
            self.removeStrandFromSelection(strand)
        self.updateStrandSelection()
示例#5
0
    def deselectOligo(self, oligo: Oligo):
        """Deselect given ``Oligo``

        Args:
            oligo: ``Oligo`` object
        """
        strand5p = oligo.strand5p()
        for strand in strand5p.generator3pStrand():
            self.removeStrandFromSelection(strand)
        self.updateStrandSelection()
示例#6
0
    def selectOligo(self, oligo: Oligo):
        """Select given ``Oligo``

        Args:
            oligo: ``Oligo`` object
        """
        strand5p = oligo.strand5p()
        both_ends = (True, True)
        for strand in strand5p.generator3pStrand():
            self.addStrandToSelection(strand, both_ends)
        self.updateStrandSelection()
示例#7
0
    def selectOligo(self, oligo: Oligo):
        """Select given ``Oligo``

        Args:
            oligo: ``Oligo`` object
        """
        strand5p = oligo.strand5p()
        both_ends = (True, True)
        for strand in strand5p.generator3pStrand():
            self.addStrandToSelection(strand, both_ends)
        self.updateStrandSelection()
示例#8
0
    def isOligoSelected(self, oligo: Oligo) -> bool:
        """Determine if given ``Oligo`` is selected

        Args:
            oligo: ``Oligo`` object

        Returns:
            ``True`` if ``oligo`` is selected otherwise ``False``
        """
        strand5p = oligo.strand5p()
        for strand in strand5p.generator3pStrand():
            if self.isModelStrandSelected(strand):
                return True
        return False
示例#9
0
 def __init__(self,  strandset,
                     base_idx_low, base_idx_high,
                     color,
                     update_segments=True):
     """ TODO: Now that parts have a UUID this could be instantiated via
     a document, uuid, id_num, is_fwd, base_idx_low, ... instead of an object
     to be independent of parts keeping strandsets live
     """
     super(CreateStrandCommand, self).__init__("create strand")
     self._strandset = strandset
     doc = strandset.document()
     self._strand = Strand(strandset, base_idx_low, base_idx_high)
     self._new_oligo = Oligo(None, color, length=self._strand.totalLength())  # redo will set part
     self.update_segments = update_segments
示例#10
0
    def isOligoSelected(self, oligo: Oligo) -> bool:
        """Determine if given ``Oligo`` is selected

        Args:
            oligo: ``Oligo`` object

        Returns:
            ``True`` if ``oligo`` is selected otherwise ``False``
        """
        strand5p = oligo.strand5p()
        for strand in strand5p.generator3pStrand():
            if self.isModelStrandSelected(strand):
                return True
        return False
示例#11
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
        doc = strandset.document()
        self._strand = Strand(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._strand.totalLength())

    # end def

    def redo(self):
        # Add the new strand to the StrandSet strand_list
        strand = self._strand
        strandset = self._strandset
        strandset._strand_list.insert(self._s_set_idx, strand)
        # Set up the new oligo
        oligo = self._new_oligo
        oligo.setStrand5p(strand)
        oligo.addToPart(strandset.part())
        strand.setOligo(oligo)

        if strandset.isStaple():
            strand.reapplySequence()
        # Emit a signal to notify on completion
        strandset.strandsetStrandAddedSignal.emit(strandset, strand)
        # 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._strand
        strandset = self._strandset
        strandset._doc.removeStrandFromSelection(strand)
        strandset._strand_list.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