Commit ab31e37f by Bertrand NÉRON

### fix translate code

```in translate use // intead of / due to python3
in translate2 use translate DRY```
parent e0f44684
Pipeline #10453 passed with stages
in 22 seconds
 genetic_code = { 'ttt': 'F', 'tct': 'S', 'tat': 'Y', 'tgt': 'C', genetic_code = { 'ttt': 'F', 'tct': 'S', 'tat': 'Y', 'tgt': 'C', 'ttc': 'F', 'tcc': 'S', 'tac': 'Y', 'tgc': 'C', 'tta': 'L', 'tca': 'S', 'taa': '*', 'tga': '*', 'ttg': 'L', 'tcg': 'S', 'tag': '*', 'tgg': 'W', ... ... @@ -23,7 +23,11 @@ def translate(nuc_seq, code): # to avoid to compute len(seq)/3 at each loop # I compute it once and use a reference # it could be expensive if the sequence is very long. cycle = len(nuc_seq)/3 # another way to determine the end of looping # stop_iteration = len(nuc_seq) # while (start + 2) < stop_iteration: cycle = len(nuc_seq)//3 while n < cycle: start = n * 3 end = start + 3 ... ... @@ -34,23 +38,18 @@ def translate(nuc_seq, code): else: raise RuntimeError("unknow codon: " + codon) n += 1 # if use the other looping solution # n += 3 return prot_seq def translate2(nuc_seq, code, phase = 1): prot_seq = '' if 0 < phase < 4 : start = phase - 1 nuc_seq = nuc_seq[start:] elif -4 < phase < 0: start = -phase - 1 nuc_seq = nuc_seq[::-1] # an other way to determine the end of looping stop_iteration = len(nuc_seq) while (start + 2) < stop_iteration: end = start + 3 codon = nuc_seq[start:end].lower() if codon in code: prot_seq += code[codon] else: raise RuntimeError("unknow codon") start += 3 nuc_seq = nuc_seq[start:] prot_seq = translate(nuc_seq, code) return prot_seq
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!