Sha256: e6dd356979d62610f127c0bf9ebaded6b3016395b59d1c4fd2f62fc41b01506d

Contents?: true

Size: 801 Bytes

Versions: 105

Compression:

Stored size: 801 Bytes

Contents

CODONS = {'AUG': "Methionine", 'UUU': "Phenylalanine",
          'UUC': "Phenylalanine", 'UUA': "Leucine", 'UUG': "Leucine",
          'UCU': "Serine", 'UCC': "Serine", 'UCA': "Serine",
          'UCG': "Serine", 'UAU': "Tyrosine", 'UAC': "Tyrosine",
          'UGU': "Cysteine", 'UGC': "Cysteine", 'UGG': "Tryptophan",
          'UAA': "STOP", 'UAG': "STOP", 'UGA': "STOP"}


def of_codon(codon):
    if codon not in CODONS:
        raise ValueError('Invalid codon: {}'.format(codon))
    return CODONS[codon]


def proteins(strand):
    proteins = []
    for codon in map(of_codon, _chunkstring(strand, 3)):
        if codon == 'STOP':
            break
        proteins.append(codon)
    return proteins


def _chunkstring(string, n):
    return (string[i:n + i] for i in range(0, len(string), n))

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/python/exercises/protein-translation/example.py
trackler-2.2.1.77 tracks/python/exercises/protein-translation/example.py
trackler-2.2.1.76 tracks/python/exercises/protein-translation/example.py
trackler-2.2.1.75 tracks/python/exercises/protein-translation/example.py
trackler-2.2.1.74 tracks/python/exercises/protein-translation/example.py