A simple, fast program which transcribes a DNA strand into messenger RNA (mRNA), which it then translates into amino acids.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.0 KiB

  1. #This program turns a strand of DNA into mRNA, which is then converted into amino acids using a codon chart
  2. #MIT License as usual
  3. #Ravi Shah 2020
  4. from amino_acids import codons_to_acids
  5. stop_index = "NaN"
  6. def transcription(dna):
  7. res = []
  8. newlist = []
  9. res[:] = dna
  10. for i in res:
  11. if i == "G":
  12. newlist.append("C")
  13. elif i == "C":
  14. newlist.append("G")
  15. elif i == "A":
  16. newlist.append("U")
  17. elif i == "T":
  18. newlist.append("A")
  19. mrna_strand = ''.join(newlist)
  20. return mrna_strand
  21. def find_start(mrna):
  22. try:
  23. start_index = mrna.index("AUG")
  24. inter_rna = mrna[start_index:]
  25. return inter_rna
  26. except:
  27. print("Please enter a valid DNA strand with a start codon.")
  28. quit()
  29. def find_stop(mrna):
  30. if "UAA" in mrna:
  31. print("UAA STOP codon found")
  32. stop_index = mrna.index("UAA")
  33. elif "UAG" in mrna:
  34. print("UAG STOP codon found")
  35. stop_index = mrna.index("UAG")
  36. elif "UGA" in mrna:
  37. print("UGA STOP codon found")
  38. stop_index = mrna.index("UGA")
  39. else:
  40. print("No STOP codon found. Exiting...")
  41. quit()
  42. return stop_index
  43. def break_into_codons(mrna):
  44. n = 3
  45. res = [mrna[i:i+n] for i in range(0, len(mrna), n)]
  46. return res
  47. def truncate(codons, stop_index):
  48. codons = codons[0:stop_index+1]
  49. return codons
  50. def translation(final_codons):
  51. print("The codons are:", final_codons)
  52. list_of_amino_acids = codons_to_acids(final_codons)
  53. print("There are", len(list_of_amino_acids), "amino acids translated from this mRNA strand.")
  54. return list_of_amino_acids
  55. strand = input("Enter the DNA strand to be transcribed and translated: ")
  56. strand = strand.upper()
  57. messenger_rna = transcription(strand)
  58. with_start = find_start(messenger_rna)
  59. into_codons = break_into_codons(with_start)
  60. stop_index = find_stop(into_codons)
  61. final_codons = truncate(into_codons, stop_index)
  62. amino_acids_list = translation(final_codons)
  63. print(amino_acids_list)