Example #1
0
    def _reverseSequence(self, itemIndex):
        """
        Reverse the strand sequence and update the StrandTextEdit widgets.
        This is used when the 'strand direction' combobox item changes.
        Example: If the sequence direction option is 5' to 3' then while
        adding the bases, those get added to extend the 3' end.
        Changing the direction (3' to 5') reverses the existing sequence in
        the text edit (which was meant to be for 5' to 3')
        @param itemIndex: currentIndex of combobox
        @type  itemIndex: int
        @see self._determine_complementSequence() and bug 2787
        """
        sequence = str(self.getPlainSequence())
        complementSequence = str(self.sequenceTextEdit_mate.toPlainText())

        reverseSequence = getReverseSequence(sequence)

        #Important to reverse the complement sequence separately
        #see bug 2787 for implementation notes.
        #@see self._determine_complementSequence()
        reverseComplementSequence = getReverseSequence(complementSequence)

        self._setComplementSequence(reverseComplementSequence)
        self._setSequence(reverseSequence)
        return
Example #2
0
 def _reverseSequence(self, itemIndex):
     """
     Reverse the strand sequence and update the StrandTextEdit widgets. 
     This is used when the 'strand direction' combobox item changes. 
     Example: If the sequence direction option is 5' to 3' then while
     adding the bases, those get added to extend the 3' end. 
     Changing the direction (3' to 5') reverses the existing sequence in 
     the text edit (which was meant to be for 5' to 3')
     @param itemIndex: currentIndex of combobox
     @type  itemIndex: int
     @see self._determine_complementSequence() and bug 2787
     """
     sequence = str(self.getPlainSequence())
     complementSequence = str(self.sequenceTextEdit_mate.toPlainText())
     
     reverseSequence = getReverseSequence(sequence)
     
     #Important to reverse the complement sequence separately 
     #see bug 2787 for implementation notes. 
     #@see self._determine_complementSequence()
     reverseComplementSequence = getReverseSequence(complementSequence)
     
     self._setComplementSequence(reverseComplementSequence)
     self._setSequence(reverseSequence)  
     return
Example #3
0
    def invokeAction(self, inActionName):
        """
        Applies an action on the current sequence displayed in the PM.

        @param inActionName: The action name.
        @type  inActionName: str

        @return: The sequence after the action has been applied.
        @rtype:  str
        """
        sequence, allKnown = self._getSequence()
        outResult = ""

        if inActionName == self._action_Complement:
            outResult = getComplementSequence(sequence)
        elif inActionName == self._action_Reverse:
            outResult = getReverseSequence(sequence)
        elif inActionName == self._action_ConvertUnrecognized:
            outResult = replaceUnrecognized(sequence, replaceBase='N')
            self.setSequence(outResult)
        elif inActionName == self._action_RemoveUnrecognized:
            outResult = replaceUnrecognized(sequence, replaceBase='')

        self.setSequence(outResult)

        return
    def invokeAction( self, inActionName ):
        """
        Applies an action on the current sequence displayed in the PM.

        @param inActionName: The action name.
        @type  inActionName: str

        @return: The sequence after the action has been applied.
        @rtype:  str
        """
        sequence, allKnown = self._getSequence()
        outResult  =  ""

        if inActionName == self._action_Complement:
            outResult  =  getComplementSequence(sequence)
        elif inActionName == self._action_Reverse:
            outResult  =  getReverseSequence(sequence)
        elif inActionName == self._action_ConvertUnrecognized:
            outResult  =  replaceUnrecognized(sequence, replaceBase = 'N')
            self.setSequence( outResult )
        elif inActionName == self._action_RemoveUnrecognized:
            outResult  =  replaceUnrecognized(sequence, replaceBase = '')

        self.setSequence( outResult )

        return
    def _getSequence( self, 
                      reverse = False, 
                      complement = False, 
                      resolve_random = False, 
                      cdict = {} ):
        """
        Get the current DNA sequence from the Property Manager.
        
        This method is not fully private. It's used repeatedly to get the 
        same sequence when making the DNA (which means its return value 
        should be deterministic, even when making sequences with randomly 
        chosen bases [nim]), and it's also called from class 
        DnaGeneratorPropertyManager to return data to be stored back into the 
        Property Manager, for implementing the reverse and complement actions.
        (Ideally it would preserve whitespace and capitalization when used 
        that way, but it doesn't.)
        
        @param reverse: If true, returns the reverse sequence.
        @type  reverse: bool
        
        @param complement: If true, returns the complement sequence.
        @type  complement: bool
        
        @param resolve_random:
        @type  resolve_random: True
        
        @param cdict:
        @type  cdict: dictionary
        
        @return: (sequence, allKnown) where I{sequence} is a string in which 
                 each letter describes one base of the sequence currently
                 described by the UI, as modified by the passed reverse, 
                 complement, and resolve_random flags, and I{allKnown} is a 
                 boolean which says whether every base in the return value 
                 has a known identity.
        @rtype:  tuple
        
        @note: All punctuation/symbols are purged from the sequence and
               any bogus/unknown bases are substituted as 'N' (unknown).
        """
        
        sequence = ''
        allKnown = True
        
        cdict    =  basesDict
        
        # (Note: I think this code implies that it can no longer be a 
        #        number of bases. [bruce 070518 comment])
        currentSequence  =  str(self.getPlainSequence(inOmitSymbols = True))

        for ch in currentSequence:
            if ch in cdict.keys():  #'CGATN':
                properties = cdict[ch]
                if ch == 'N': ###e soon: or any other letter indicating a random base
                    if resolve_random: #bruce 070518 new feature
                        i    = len(sequence)
                        data = self._random_data_for_index(i) 
                        # a random int in range(12), in a lazily extended cache
                        ch   = list(cdict)[data%4]  
                        # modulus must agree with number of valid entries in 
                        # cdict.
                    else:
                        allKnown = False
                if complement:
                    try:
                        ch = properties['Complement']
                    except (KeyError):
                        raise KeyError("DNA dictionary doesn't have a \
                        'Complement' key for '%r'." % ch)
                        ch = 'N'
            elif ch in self.validSymbols: #'\ \t\r\n':
                ch  =  ''
            else:              
                allKnown  =  False

            sequence += ch

        if reverse: 
            sequence = getReverseSequence(sequence)
        
        return (sequence, allKnown)