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
def getBestSequence(self, sourceSequence): sourceCodons = re.findall('...', sourceSequence) remainder = SeqUtils.getRemainderSuffix(sourceSequence) result = "" for co in sourceCodons: result += self.getBestCodon(co) result += remainder return result
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
def getPossibleOneStepChanges(self, sourceSeq, optimizedSeq, codonsToConsider): ''' get all possible sequences resulting from substituting the codons to consider in the optimized Seq with the next best codons ''' sourceCodons = re.findall('...', sourceSeq) # list of codons optCodons = re.findall("...", optimizedSeq) remainder = SeqUtils.getRemainderSuffix(optimizedSeq) res = list() for i in range(len(optCodons)): if i in codonsToConsider: nextBestCodon = self.getNextBestCodon(sourceCodons[i], optCodons[i]) if nextBestCodon: tCodons = optCodons tCodons[i] = nextBestCodon tSeq = "".join(tCodons) tSeq += remainder res.append(tSeq) return res