Python program for DNA transcription problem
Last Updated :
28 Jul, 2020
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
def transcript(x) :
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 = "")
if __name__ = = "__main__" :
x = "GCTAA"
transcript(x)
|
Output:
Translated DNA : CGAUU
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...