In genetics a reading frame is a way to divide a sequence of nucleotides (DNA bases) into a set of consecutive non-overlapping triplets (also called codon). Each of this triplets is translated into an amino-acid during a translation process to create proteins.

Input
---
In a single strand of DNA you find 3 Reading frames, take for example the following input sequence:

    AGGTGACACCGCAAGCCTTATATTAGC
    
Output
---
For the output we are going to take the combinations and show them in the following manner:

````
Frame 1: AGG TGA CAC CGC AAG CCT TAT ATT AGC
Frame 2: A GGT GAC ACC GCA AGC CTT ATA TTA GC
Frame 3: AG GTG ACA CCG CAA GCC TTA TAT TAG C
````

For frame 1 split all of them in groups of three starting by the first base (letter).

For frame 2 split all of them in groups of three starting by the second base (letter) but having the first base (letter) at the beggining.

For frame 3 split all of them in groups of three starting by the third letter, but having the first and second bases (letters) at the beginning in the same order.

Series
---

1. [Decompose single strand DNA into 3 reading frames](http://www.codewars.com/kata/57507369b0b6d1b5a60001b3)

2. [Decompose double strand DNA into 6 reading frames](http://www.codewars.com/kata/57519060f2dac7ec95000c8e/)

3.  [Translate DNA to protein in 6 frames](http://www.codewars.com/kata/5708ef48fe2d018413000776)

Difficulty: introductory

Starter code:

def decompose_single_strand(single_strand):
	

Solutions:
def decompose_single_strand(dna):        
    return '\n'.join('Frame {}: {}'.format(k+1, frame(dna, k)) for k in range(3))
    
def frame(s, k):
    return ' '.join(([s[:k]] if k else []) + [s[i:i+3] for i in range(k, len(s), 3)])    

def decompose_single_strand(single_strand):
    f1 = 'Frame 1: {}'.format(decompose(single_strand))
    f2 = 'Frame 2: {} {}'.format(single_strand[:1], decompose(single_strand[1:]))
    f3 = 'Frame 3: {} {}'.format(single_strand[:2], decompose(single_strand[2:]))
    return '\n'.join([f1, f2, f3])
    
def decompose(strand):
    return ' '.join([strand[i: i + 3] for i in range(0, len(strand), 3)])

def decompose_single_strand(s):
    F1 = []
    F2 = [s[0]]
    F3 = [s[:2]]
    for i in range(0,len(s), 3):
       F1.append(s[i:i + 3])
    F1 = ' '.join(F1)
    for i in range(1,len(s), 3):
       F2.append(s[i:i + 3])
    F2 = ' '.join(F2)
    for i in range(2,len(s), 3):
       F3.append(s[i:i + 3])
    F3 = ' '.join(F3)
    return 'Frame 1: ' + F1 + '\n' + 'Frame 2: ' + F2 + '\n' + 'Frame 3: ' + F3

def decompose_single_strand(ar):
    i = []
    t= []
    th= []
    for x,y,z in zip(ar[0::3], ar[1::3], ar[2::3]):
      i.append(x+y+z)
    #print( "Frame 1: " +" ".join(i))
    for x,y,z in zip(ar[1::3], ar[2::3], ar[3::3]):
      t.append(x+y+z)
    #print( "Frame 2: " +" ".join(t))
    for x,y,z in zip(ar[2::3], ar[3::3], ar[4::3]):
      th.append(x+y+z)
    #print( "Frame 3: " +" ".join(th))
    if len(ar)==3:
      return  ("Frame 1: " +" ".join(i) + "\n" +  "Frame 2: " + str(ar[0])+" "+str(ar[-2:])+ "\nFrame 3: "+ str(ar[0:2]) + " " + str(ar[-1]))
    else:
      return ("Frame 1: " +" ".join(i) + "\n" +  "Frame 2: " + str(ar[0])+" "+" ".join(t)+" "+str(ar[-2:])+ "\nFrame 3: "+ str(ar[0:2]) +" " +" ".join(th)+ " " + str(ar[-1]))
    
      


def decompose_single_strand(single_strand):
    frame1= "Frame 1:"
    frame2= "Frame 2:"
    frame3= "Frame 3:"
    i=0
    while i in range(len(single_strand)):
        frame1+= " "+(single_strand[i:i+3])
        i+=3
    i=1
    frame2+= " " +(single_strand[0])
    while i in range(len(single_strand)):
        frame2+= " "+(single_strand[i:i+3])
        i+=3
    i=2
    frame3+= " "+(single_strand[0:2])
    while i in range(len(single_strand)):
        frame3+= " "+ (single_strand[i:i+3])
        i+=3
    frames = (frame1+'\n'+frame2+'\n'+frame3)
    return frames

decompose_single_strand=lambda d:'\n'.join('Frame %d: %s'%(4-i,' '.join(map(''.join,zip(*[iter(' '*i+d+'  ')]*3))).strip())for i in(3,2,1))

def decompose_single_strand(single_strand):
  string1=[single_strand[i:(i+3)] for i in range(0,len(single_strand),3)]
  string2=[single_strand[i:(i+3)] if i!=0 else single_strand[i] for i in [0]+list(range(1,len(single_strand),3))]
  string3=[single_strand[i:(i+3)] if i>1 else single_strand[:(i+1)] for i in [1]+list(range(2,len(single_strand),3))]
  Frame='Frame 1: '+' '.join(string1)+'\nFrame 2: '+' '.join(string2)+'\nFrame 3: '+' '.join(string3)
  return Frame

import re

def decompose_single_strand(single_strand):
    return '\n'.join(
        'Frame {}: {}'.format(i, ' '.join(m.group() for m in re.finditer(r, single_strand)))
        for i, r in enumerate(['...', '^.|...|..$', '^..|...|.$'], 1))

decompose_single_strand=lambda s: "\n".join("Frame %s: %s" %(i+1," ".join(([s[:i]] if i else [])+[s[q:q+3] for q in range(i,len(s),3)])) for i in range(3))

def decompose_single_strand(single_strand):
    frame1 = []
    frame2 = [single_strand[0]]
    frame3 = [single_strand[0:2]]
    
    for i in range(0, len(single_strand)-2, 3):
        frame1.append(single_strand[i:i+3])
        frame2.append(single_strand[i+1:i+4])
        frame3.append(single_strand[i+2:i+5])
    
    return "Frame 1: {}\nFrame 2: {}\nFrame 3: {}".format(' '.join(frame1), ' '.join(frame2), ' '.join(frame3))