Exemplo n.º 1
0
 def removeRestrictionSites(self, sourceSeq, optimizedSeq, restrictionSites):
     '''
     get the best sequence that does not contain any restriction sites
     by re-randomizing until no restriction site remains
     '''
     
     codons = re.findall('...', optimizedSeq)
     remainder = SeqUtils.getRemainderSuffix(optimizedSeq)
     
     restrictionSites = SeqUtils.expandAmbiguousMult(restrictionSites)
     restrictionLocations = SeqUtils.searchSubseqs(optimizedSeq, restrictionSites)
     restrictionCodons = SeqUtils.getCodonsForRanges(restrictionLocations)
     
     # try to re-randomize a finite amount of times
     ITERMAX = 10000
     iteration = 0
     
     while iteration < ITERMAX:
         
         for i in restrictionCodons:
             codons[i] = self.getRandomOptimizedCodon(codons[i])
             
         tSeq = "".join(codons) + remainder
         
         tRL = SeqUtils.searchSubseqs(tSeq, restrictionSites)
         tRC = SeqUtils.getCodonsForRanges(tRL)
         
         if not tRC:
             return tSeq
             
         iteration += 1
     
     return None
 
     
Exemplo n.º 2
0
 def removeRestrictionSites(self, sourceSeq, optimizedSeq, restrictionSites):
     '''
     get the best sequence that does not contain any restriction sites
     by substituting codons in the optimizedSeq in a shortest-paths manner
     '''
     
     checkedSeqs = set()
     worklist = list()
     
     restrictionSites = SeqUtils.expandAmbiguousMult(restrictionSites)
     
     heapq.heappush(worklist, (self.scoreSequence(sourceSeq, optimizedSeq), optimizedSeq))
     
     while len(worklist) > 0:
         
         tScore, tSeq = heapq.heappop(worklist)
         restrictionLocations = SeqUtils.searchSubseqs(tSeq, restrictionSites)
         restrictionCodons = SeqUtils.getCodonsForRanges(restrictionLocations)
         
         if not restrictionCodons:
             
             return tSeq
         else:
             checkedSeqs.add(tSeq)
             possibleChanges = self.getPossibleOneStepChanges(sourceSeq, tSeq, restrictionCodons)
             if possibleChanges:
                 for tNewSeq in possibleChanges:
                     if not tNewSeq in checkedSeqs:
                         heapq.heappush(worklist, (self.scoreSequence(sourceSeq, tNewSeq), tNewSeq))
     
     return None
Exemplo n.º 3
0
 def SequenceToPrint(self, seq, restrictionSites, source=True):
     '''
     return tuples of the form (codon, usage, isRestrictionSite) for the sequence
     '''
     codons = re.findall('...', seq)
     remainder = SeqUtils.getRemainderSuffix(seq)
     
     result = list()
     restrictionSites = SeqUtils.expandAmbiguousMult(restrictionSites)
     restrictionLocations = SeqUtils.searchSubseqs(seq, restrictionSites)
     restrictionCodons = SeqUtils.getCodonsForRanges(restrictionLocations)
     
     for i in range(len(codons)):
         usage = self.sourceCU.getCodonRelativeUsage(codons[i]) if source else self.targetCU.getCodonRelativeUsage(codons[i])
         result.append((codons[i], usage, i in restrictionCodons))
     
     if remainder:
         result.append((remainder, None, None))
     
     return result