##############################################
#  Program reads in RNA codon dictionary and
#  DNA sequence. Then converts DNA sequence to RNA 
#  and translates an RNA sequence into 
#  a sequence of amino acids
##############################################

def build_codon_dict():
    """
    Function creates RNA codon to amino acid 
    map (dictionary) from txt file
    """
    f_in = open('RNA_codons.txt')
    RNA_dict = {}
    for line in f_in:
        codon,abv,letter,name = line.strip().split()
        RNA_dict[codon] = [abv,letter,name]
    return RNA_dict
#
# Create RNA codon dictionary
RNA_codon_dict = build_codon_dict()
#
#  Read in DNA sequence
DNA_in = 'ATAGATGAAGCCCCACGCCTAGGAG'
###################################################
#  Add statement HERE to print out DNA in sequence
#  See print RNA sequence below for example 
####################################################
#
# Convert DNA sequence to RNA sequence
RNA_in = DNA_in.replace('T','U')
#
#  Find start codon ('AUG') in RNA sequence
#
str_pos = -1
for pos in range(len(RNA_in)-3):
    seq3 = RNA_in[pos:pos+3]
#    print 'seq3 =', seq3
################################################
#  Your code goes HERE
################################################
#
#  Lookup and print sequence of amino acids
#
print 'RNA sequence is:', RNA_in,'\n'
if str_pos == -1:
    print 'No starting codon found for this sequence'
else:
    print 'Amino acid sequence for this RNA sequence is:'
#    print 'str_pos=', str_pos
    RNA_seq = RNA_in[str_pos:]
    for pos in range(0,len(RNA_seq)-3,3):
        codon = RNA_seq[pos:pos+3]
        if codon in RNA_codon_dict:
            abv,letter,name = RNA_codon_dict[codon]
        else:
            abv = 'XXX'
        print abv + '-',
        if abv == 'Stop':
            print '\n\n'
            break
 
           
        
        

