Python program for DNA transcription problem
Let’s discuss the DNA transcription problem in Python. First, let’s understand about the basics of DNA and RNA that are going to be used in this problem.
- The four nucleotides found in DNA: Adenine (A), Cytosine (C), Guanine (G), and Thymine (T).
- The four nucleotides found in RNA: Adenine (A), Cytosine (C), Guanine (G), and Uracil (U).
Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement nucleotide:
- G –> C
- C –> G
- T –> A
- A –> U
Example :
Input: GCTAA Output: CGAUU Input: GC Output: CG
Approach:
Take input as a string and then convert it into the list of characters. Then traverse each character present in the list. check if the character is ‘G’ or ‘C’ or ‘T’ or ‘A’ then convert it into ‘C’,’G’, ‘A’ and ‘U’ respectively. Else print ‘Invalid Input’.
Below is the implementation:
Python3
# define a function # for transcription def transcript(x) : # convert string into list l = list (x) for i in range ( len (x)): if (l[i] = = 'G' ): l[i] = 'C' elif (l[i] = = 'C' ): l[i] = 'G' elif (l[i] = = 'T' ): l[i] = 'A' elif (l[i] = = 'A' ): l[i] = 'U' else : print ( 'Invalid Input' ) print ( "Translated DNA : " ,end = "") for char in l: print (char,end = "") # Driver code if __name__ = = "__main__" : x = "GCTAA" # function calling transcript(x) |
Output:
Translated DNA : CGAUU