protein = input ('Enter Fasta Sequence')

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 basesnn' % len(s))

return (sequence_title,s)

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'}

basepairs = {'A' : 'T', 'C' : 'G', 'T' : 'A', 'G' : 'C'}

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

def rev_translate ( seq ):

rev_translate = (seq[::-1])

rt=""join([basepairs.get(rev_translate[i],'x') for i in range(len(seq))])

return rt

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



Source link