##############################################
#  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 read_DNA(filename):
    """
    Function reads multiple DNA sequences to decode 
    from filename and returns sequences in DNA_list
    """
    f_in = open(filename, 'r')
    DNA_list = []
    for line in f_in:
        DNA_list.append(line.strip().upper())
    return DNA_list

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 sequences from file into list
# Assign first DNA sequence to DNA_in and print
#
DNA_list = read_DNA( 'DNA_seq_random.txt') 
DNA_in  = DNA_list[0]   # Assign first line in DNA file 
print ('\n\nDNA sequence is:', DNA_in)
#
# Convert DNA sequence to RNA sequence
RNA_in = DNA_in.replace('T','U')
#
##############################################################
#
# YOUR CODE GOES HERE:
#  For the converted RNA sequence (RNA_in)  print out 
#  the sequence of amino acids using the RNA dictionary,
#  using pseudo-code steps below:
#  0. Print out DNA and RNA seqeuence you are de-coding.
#  1. Find the start codon sequence. If no starting codon 
#     found, print 'No starting codon found for this sequence'
#  2. From there, decode each 3 following letter codon to find 
#      corresponding amino acid abreviation fom dictionary.
#  3  Print amino acid (on same line) and continue to next codon.
#  3. Stop when you reach stop codon.
#
#  Output should look something like this:
#
#  DNA sequence is: ATGGAGCGTGCTGGTCCCCTAGGTAATGCCGCCTCCCGAATTTAA
#  RNA sequence is: AUGGAGCGUGCUGGUCCCCUAGGUAAUGCCGCCUCCCGAAUUUAA 
#  Amino acid sequence for this RNA sequence is:
#      Met-Glu-Arg-Ala-Gly-Pro-Leu-Gly-Asp-Ala-Ala-Ser-Arg-Ile-
#
#   
################################################################ 

           
        
        

