0% found this document useful (0 votes)
319 views

BioInfo2 Assignment - Python

The document describes the process of translating DNA into proteins. It involves: 1. Transcribing DNA into RNA 2. Translating RNA into amino acids by reading the RNA codons in groups of three 3. Defining functions to translate the six reading frames of DNA and its complement to find all possible proteins

Uploaded by

Jin Yeow
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
319 views

BioInfo2 Assignment - Python

The document describes the process of translating DNA into proteins. It involves: 1. Transcribing DNA into RNA 2. Translating RNA into amino acids by reading the RNA codons in groups of three 3. Defining functions to translate the six reading frames of DNA and its complement to find all possible proteins

Uploaded by

Jin Yeow
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

#Task 1: Translating DNA into proteins.

#a. First transcribe DNA to RNA

#b. Translate RNA to amino acids

from string import * //Importing string library

seq = raw_input ("Enter a seqeunce : ") //Create sequence input

print ""

seq=seq.upper() //change input sequence to uppercase by ‘.upper()’.

table = { //initialize amino acid dictionary

'UUU': 'F', 'UUC': 'F', 'UUA': 'L', 'UUG': 'L', 'UCU': 'S',

'UCC': 'S', 'UCA': 'S', 'UCG': 'S', 'UAU': 'Y', 'UAC': 'Y',

'UGU': 'C', 'UGC': 'C', 'UGG': 'W', 'CUU': 'L', 'CUC': 'L',

'CUA': 'L', 'CUG': 'L', 'CCU': 'P', 'CCC': 'P', 'CCA': 'P',

'CCG': 'P', 'CAU': 'H', 'CAC': 'H', 'CAA': 'Q', 'CAG': 'Q',

'CGU': 'R', 'CGC': 'R', 'CGA': 'R', 'CGG': 'R', 'AUU': 'I',

'AUC': 'I', 'AUA': 'I', 'AUG': 'M', 'ACU': 'T', 'ACC': 'T',

'ACA': 'T', 'ACG': 'T', 'AAU': 'N', 'AAC': 'N', 'AAA': 'K',

'AAG': 'K', 'AGU': 'S', 'AGC': 'S', 'AGA': 'R', 'AGG': 'R',

'GUU': 'V', 'GUC': 'V', 'GUA': 'V', 'GUG': 'V', 'GCU': 'A',

'GCC': 'A', 'GCA': 'A', 'GCG': 'A', 'GAU': 'D', 'GAC': 'D',

'GAA': 'E', 'GAG': 'E', 'GGU': 'G', 'GGC': 'G', 'GGA': 'G',

'GGG': 'G', }
stop_codons = ['UAA', 'UAG', 'UGA'] //Initialize stop codon dictionary

for codon in stop_codons: //Loop to substitute stop codon with ‘*’.

table[codon] = "*"

protein = [] //List of array for proteins translated from every ORF

protein_complementary = []

protein_base1 = []

protein_complementary_base1 = []

protein_base2 = []

protein_complementary_base2 = []

protein_base3 = []

protein_complementary_base3 = []

for base in seq: //Checker for unknown bases

if base == "A":

number = 2

elif base == "G":

number = 2

elif base == "T":

number = 2

elif base == "C":

number = 2

else:

number = 1
if number == 1:

print "Error in the sequence, contain unknown bases"

exit(1)

c = maketrans("ATGC","UACG") //”maketrans()” function to convert sequence to RNA

t = maketrans("ATGC","TACG") //”maketrans()” function to convert sequence


//to complementary

complementary_DNA = seq.translate(t) // apply ‘t’ to create compliment dna

transcript_DNA = seq.translate(c) //apply ‘c’ to transcribe sequence

complementary_RNA = complementary_DNA.translate(c) //RNA of compliment DNA

transcript_complementary_DNA = complementary_RNA[::-1] //reverse compliment of RNA

def translate_dna(transcript_DNA): //function to translate sequence

for i in range(0, len(transcript_DNA)-len(transcript_DNA)%3, 3):

protein.append( table[transcript_DNA[i:i+3]] )

return "".join(protein)
def translate_dna_base1(transcript_DNA): //ORF1 translate with Stop codon include

for i in range(0, len(transcript_DNA)-len(transcript_DNA)%3, 3):

if transcript_DNA[i:i+3] == 'UAA':

protein_base1.append( table[transcript_DNA[i:i+3]] )

break

elif transcript_DNA[i:i+3] == 'UAG':

protein_base1.append( table[transcript_DNA[i:i+3]] )

break

elif transcript_DNA[i:i+3] == 'UGA':

protein_base1.append( table[transcript_DNA[i:i+3]] )

break

else:

protein_base1.append( table[transcript_DNA[i:i+3]] )

return " ".join(protein_base1)

def translate_complementary_base1(transcript_complementary_DNA):

//ORF4 translate with Stop codon include

for i in range(0, len(transcript_complementary_DNA)-len(transcript_complementary_DNA)


%3, 3):
if transcript_complementary_DNA[i:i+3] == 'UAA':

protein_complementary_base1.append( table[transcript_complementary_DNA[i:i+3]] )

break

elif transcript_complementary_DNA[i:i+3] == 'UAG':

protein_complementary_base1.append( table[transcript_complementary_DNA[i:i+3]] )

break

elif transcript_complementary_DNA[i:i+3] == 'UGA':

protein_complementary_base1.append( table[transcript_complementary_DNA[i:i+3]] )

break

else:

protein_complementary_base1.append( table[transcript_complementary_DNA[i:i+3]] )

return " ".join(protein_complementary_base1)

def translate_dna_base2(transcript_DNA): //ORF2 translate with Stop codon include

for i in range(1, ((len(transcript_DNA)-1)-(len(transcript_DNA)-1)%3), 3):

if transcript_DNA[i:i+3] == 'UAA':

protein_base2.append( table[transcript_DNA[i:i+3]] )

break
elif transcript_DNA[i:i+3] == 'UAG':

protein_base2.append( table[transcript_DNA[i:i+3]] )

break

elif transcript_DNA[i:i+3] == 'UGA':

protein_base2.append( table[transcript_DNA[i:i+3]] )

break

else:

protein_base2.append( table[transcript_DNA[i:i+3]] )

return " ".join(protein_base2)

def translate_complementary_base2(transcript_complementary_DNA):

//ORF5 translate with Stop codon include

for i in range(1, ((len(transcript_complementary_DNA)-1)-


(len(transcript_complementary_DNA)-1)%3), 3):

if transcript_complementary_DNA[i:i+3] == 'UAA':

protein_complementary_base2.append( table[transcript_complementary_DNA[i:i+3]] )

break

elif transcript_complementary_DNA[i:i+3] == 'UAG':

protein_complementary_base2.append( table[transcript_complementary_DNA[i:i+3]] )
break

elif transcript_complementary_DNA[i:i+3] == 'UGA':

protein_complementary_base2.append( table[transcript_complementary_DNA[i:i+3]] )

break

else:

protein_complementary_base2.append( table[transcript_complementary_DNA[i:i+3]] )

return " ".join(protein_complementary_base2)

def translate_dna_base3(transcript_DNA): //ORF3 translate with Stop codon include

for i in range(2, ((len(transcript_DNA)-2)-(len(transcript_DNA)-2)%3), 3):

if transcript_DNA[i:i+3] == 'UAA':

protein_base3.append( table[transcript_DNA[i:i+3]] )

break

elif transcript_DNA[i:i+3] == 'UAG':

protein_base3.append( table[transcript_DNA[i:i+3]] )

break

elif transcript_DNA[i:i+3] == 'UGA':

protein_base3.append( table[transcript_DNA[i:i+3]] )
break

else:

protein_base3.append( table[transcript_DNA[i:i+3]] )

return " ".join(protein_base3)

def translate_complementary_base3(transcript_complementary_DNA):

//OR6 translate with Stop codon include

for i in range(2, ((len(transcript_complementary_DNA)-2)-


(len(transcript_complementary_DNA)-2)%3), 3):

if transcript_complementary_DNA[i:i+3] == 'UAA':

protein_complementary_base3.append( table[transcript_complementary_DNA[i:i+3]] )

break

elif transcript_complementary_DNA[i:i+3] == 'UAG':

protein_complementary_base3.append( table[transcript_complementary_DNA[i:i+3]] )

break

elif transcript_complementary_DNA[i:i+3] == 'UGA':

protein_complementary_base3.append( table[transcript_complementary_DNA[i:i+3]] )

break
else:

protein_complementary_base3.append( table[transcript_complementary_DNA[i:i+3]] )

return " ".join(protein_complementary_base3)

//Calling of function and interface output

print "Transcription of the DNA sequence: ", transcript_DNA

print "The complementary of the DNA sequence is: ", complementary_DNA

print "The transcription of complementary DNA sequence is: ", transcript_complementary_DNA

print ""

print "* stand for the stop codon"

print ""

translate_dna(transcript_DNA)

pro = " "

pro = pro.join(protein) // ’.join()’ is to create strings of output

print "The translation of the DNA is: ",pro

print ""

translate_dna_base1(transcript_DNA)

translate_complementary_base1(transcript_complementary_DNA)

pro = " "


pro = pro.join(protein_base1)

print "Translation start from the 1st base is : ", pro

pro = " "

pro = pro.join(protein_complementary_base1)

print "The translation start from the 1st base of complementary RNA is: ",pro

print ""

translate_dna_base2(transcript_DNA)

translate_complementary_base2(transcript_complementary_DNA)

pro = " "

pro = pro.join(protein_base2)

print "Translation start from the 2nd base is : ", pro

pro = " "

pro = pro.join(protein_complementary_base2)

print "The translation start from the 2nd base of complementary RNA is: ",pro

print ""

translate_dna_base3(transcript_DNA)

translate_complementary_base3(transcript_complementary_DNA)

pro = " "

pro = pro.join(protein_base3)
print "Translation start from the 3rd base is : ", pro

pro = " "

pro = pro.join(protein_complementary_base3)

print "The translation start from the 3rd base of complementary RNA is: ",pro

You might also like