Syntax error in 6 frame translation python code. What is wrong?
1
0
Entering edit mode
6 weeks ago
Jager1750 • 0

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])))

Syntax Translations Error Python • 212 views
ADD COMMENT
0
Entering edit mode
6 weeks ago
gb ★ 1.9k

With barely looking at your post, you miss a point before join see https://www.w3schools.com/python/ref_string_join.asp

Without testing or knowing if you code is right it should be this: translate = ''.join([code.get(seq[3*1:3*1+3]'x') for i in range(len(seq)//3)])

ADD COMMENT
0
Entering edit mode

Thank you so much

ADD REPLY

Login before adding your answer.

Traffic: 1668 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6