def __repr__(self): content = Seq.__str__(self) if len(content) > 15: content = (content[:5].lower() + ("(%d)" % len(content)) + content[-5:].lower()) return "(%s-%s-%s)" % (repr( self.left_end), content, repr(self.right_end))
def createAmbiguousProteinList(nucRecord, firstNucPosition): print "%s"%(nucRecord[firstNucPosition]+nucRecord[firstNucPosition + 1] +nucRecord[firstNucPosition + 2]) nucleotideSequence = Seq("%s"%(nucRecord[firstNucPosition]+nucRecord[firstNucPosition + 1] +nucRecord[firstNucPosition + 2])) nucleotideSequence = Seq("AAK") altNucleotideSeqs = [] altNucleotideString = "" for nucleotide in nucleotideSequence: if nucleotide.lower() in NUCLEOTIDE_AMBIGUITY_MAPPING.keys(): print "ambiguous nucleotide:", nucleotide #if there are no alternate nucleotide sequences yet, make them if altNucleotideSeqs == []: for ambiguousNucleotide in NUCLEOTIDE_AMBIGUITY_MAPPING.get(nucleotide.lower()): altNucleotideString = nucleotideSequence.__str__() altNucleotideString = altNucleotideString.replace(nucleotide, ambiguousNucleotide.upper()) altNucleotideSeqs.append(Seq(altNucleotideString)) print altNucleotideString else: #this is not hte first ambiguous nucleotide tempAltNucleotideSeqs = [] for altNucleotideSeq in altNucleotideSeqs: print "Existing seq:" + altNucleotideSeq.__str__() for ambiguousNucleotide in NUCLEOTIDE_AMBIGUITY_MAPPING.get(nucleotide.lower()): altNucleotideString = altNucleotideSeq.__str__() altNucleotideString = altNucleotideString.replace(nucleotide, ambiguousNucleotide.upper()) tempAltNucleotideSeqs.append(Seq(altNucleotideString)) print altNucleotideString #remove the original altNucleotideSeq which has been replaced now #replace the existing list with the new list altNucleotideSeqs = tempAltNucleotideSeqs for altNucleotideSeq in altNucleotideSeqs: print altNucleotideSeq.translate() + "/",
def __repr__(self): return "%s(%s)" % (Seq.__str__(self), {1: "+", -1: "-"}[self.strand])
from Bio.Seq import Seq import re f = open('file9.txt', 'r') seq = Seq(f.read()) rev = seq.reverse_complement() str = seq.__str__() + " " + rev.__str__() l = [[0], [-3]] for i in range(0, len(str) + 1): a = str[(i):(i + 3)] if (a == 'TGA' or a == 'TAG' or a == 'TAA' or i == (len(str))): for j in range(i - 3, -1, -3): if (str[j:(j + 3)] == 'ATG'): l[0].append(j) l[1].append(i) if (str[j:(j + 3)] == 'TGA' or str[j:(j + 3)] == 'TAG' or str[j:(j + 3)] == 'TAA' or str[j:(j + 3)] == ' '): break m = [b - a for a, b in zip(l[0], l[1])] m.__delitem__(0) idx = m.index(max(m)) print(Seq(str[(l[0][idx + 1]):l[1][idx + 1]]).translate())