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.

72 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 find_stop(mrna):
  7. if "UAA" in mrna:
  8. print("UAA STOP codon found")
  9. stop_index = mrna.index("UAA")
  10. elif "UAG" in mrna:
  11. print("UAG STOP codon found")
  12. stop_index = mrna.index("UAG")
  13. elif "UGA" in mrna:
  14. print("UGA STOP codon found")
  15. stop_index = mrna.index("UGA")
  16. else:
  17. print("No STOP codon found. Exiting...")
  18. quit()
  19. return stop_index
  20. def transcription(dna):
  21. res = []
  22. newlist = []
  23. res[:] = dna
  24. for i in res:
  25. if i == "G":
  26. newlist.append("C")
  27. elif i == "C":
  28. newlist.append("G")
  29. elif i == "A":
  30. newlist.append("U")
  31. elif i == "T":
  32. newlist.append("A")
  33. mrna_strand = ''.join(newlist)
  34. return mrna_strand
  35. def start_to_stop(mrna):
  36. global stop_index
  37. try:
  38. start_index = mrna.index("AUG")
  39. inter_rna = mrna[start_index:]
  40. stop_index = find_stop(inter_rna)
  41. final_rna = inter_rna[0:stop_index+3]
  42. return(final_rna)
  43. except:
  44. print("Please enter a valid DNA strand with a start and stop codon")
  45. quit()
  46. def translation(final_rna):
  47. print("The mRNA strand is:", final_rna)
  48. n = 3
  49. res = [final_rna[i:i+n] for i in range(0, len(final_rna), n)]
  50. print("The codons are:", res)
  51. list_of_amino_acids = codons_to_acids(res)
  52. print("There are", len(list_of_amino_acids), "amino acids translated from this mRNA strand.")
  53. return list_of_amino_acids
  54. strand = input("Enter the DNA strand to be transcribed and translated: ")
  55. strand = strand.upper()
  56. messenger_rna = transcription(strand)
  57. truncated = start_to_stop(messenger_rna)
  58. if len(truncated) % 3 != 0:
  59. print("The mRNA strand isn't divisible by 3.")
  60. quit()
  61. print("Here are the amino acids:")
  62. print(translation(truncated))