# For Python 3.
ProtSeq = input("Protein sequence: ").upper()
ProtDeg = {"A":4,"C":2,"D":2,"E":2,"F":2,"G":4,"H":2,
           "I":3,"K":2,"L":6,"M":1,"N":2,"P":4,"Q":2,
           "R":6,"S":6,"T":4,"V":4,"W":1,"Y":2}
degen_tmp = max(ProtDeg.values())*15
for n in range(len(ProtSeq)-15):
    degen = 0
    for x in ProtSeq[n:n+15]:
        degen += ProtDeg.get(x,3.05)
    if degen <= degen_tmp:
        degen_tmp = degen
        seq = ProtSeq[n:n+15]
print(seq)

This code is part of the book "Python for Bioinformatics", by Sebastian Bassi (sbassi@genesdigitales.com). Return to home page.