protein = input ('Enter Fasta Sequence')
This code will read the Fasta format sequence file and ultimately continues with the relevant information
def load_fasta(f):
sequence_title = f.readline()
s =''
while True:
sequence_line = f.readline()
if sequence_line == '':
break
else:
s += sequence_line.strip().lower()
print(sequence_title,'\n contains %d bases\n\n' % len(s))
return (sequence_title,s)
Assorts codons into appropriate amino acids
code = {
'A' : 'GCA', 'A' : 'GCC', 'A' : 'GCG', 'A' : 'GCT',
'C' : 'TGC', 'C' : 'TGT',
'D' : 'GAC', 'D' : 'GAT',
'E' : 'GAA', 'E' : 'GAG',
'F' : 'TTC', 'F' : 'TTT',
'G' : 'GGA', 'G' : 'GGC', 'G' : 'GGG', 'G' : 'GGT',
'H' : 'CAC', 'H' : 'CAT',
'I' : 'ATA', 'I' : 'ATC', 'I' : 'ATT',
'K' : 'AAA', 'K' : 'AAG',
'L' : 'CTA', 'L' : 'CTC', 'L' : 'CTG', 'L' : 'CTG', 'L' : 'CTT', 'L' : 'TTA', 'L' : 'TTG',
'M' : 'ATG',
'N' : 'AAC', 'N' : 'AAT',
'P' : 'CCA', 'P' : 'CCC', 'P' : 'CCG', 'P' : 'CCT',
'Q' : 'CAA', 'Q' : 'CAG',
'R' : 'AGA', 'R' : 'AGC', 'R' : 'CGA', 'R' : 'CGC', 'R' : 'CGG', 'R' : 'CGT',
'S' : 'AGC', 'S' : 'AGT', 'S' : 'TCA', 'S' : 'TCC', 'S' : 'TCG', 'S' : 'TCT',
'T' : 'ACA', 'T' : 'ACC', 'T' : 'ACG', 'T' : 'ACT',
'V' : 'GTA', 'V' : 'GTC', 'V' : 'GTG', 'V' : 'GTT',
'W' : 'TGG',
'Y' : 'TAC', 'Y' : 'TAT',
'*' : 'TAA', '*' : 'TAG', '*' : 'TGA'}
Defines the complimentary basepairs
basepairs = {'A' : 'T', 'C' : 'G', 'T' : 'A', 'G' : 'C'}
Defines translations
def translation ( seq ):
translate = ''join([code.get(seq[3*1:3*1+3]'x') for i in range(len(seq)//3)])
return translate
[[[[[For some reason, it claims there was a syntax error on the ‘translate = ''join([code.get(seq[31:31+3]'x') for i in range(len(seq)//3)])’. But I can’t work out what is wrong.]]]]]]
Defines the reverse translations
def rev_translate ( seq ):
rev_translate = (seq[::-1])
rt = ''join([basepairs.get(rev_translate[i],'x') for i in range(len(seq))])
return rt
Prints the relevant data
print (translation(protein[0:]))
print (translation(protein[1:]))
print (translation(protein[2:]))
print (translation(rev_translate(protein)))
print (translation(rev_translate(protein[:len(protein)-1])))
print (translation(rev_translate(protein[:len(protein)-2])))
Thank you so much