I'm stuck in a exercice in python where I need to convert a DNA sequence into its corresponding amino acids. So far, I have:
seq1 = "AATAGGCATAACTTCCTGTTCTGAACAGTTTGA" for i in range(0, len(seq), 3): print seq[i:i+3]
I need to do this without using dictionaries, and I was going for replace, but it seems it's not advisable either. How can I achieve this? And it's supposed to give something like this, for exemple:
>seq1_1_+ TQSLIVHLIY >seq1_2_+ LNRSFTDSST >seq1_3_+ SIADRSLTHLL
Update 2: OK, so i had to resort to functions, and as suggested, i have gotten the output i wanted. Now, i have a series of functions, which return a series of aminoacid sequences, and i want to get an output file that looks like this, for exemple:
>seq1_1_+ iyyslrs-las-smrlssiv-m >seq1_2_+ fiirydrs-ladrcgshrssk >seq1_3_+ llfativas-lidaalidrl >seq1_1_- frrsmraasis-lativannkm >seq1_2_- lddr-ephrsas-lrs-riin >seq1_3_- -tidesridqlasydrse--m
For that, i'm using this:
for x in f1: x = x.strip() if x.count("seq"): f2.write((x)+("_1_+\n")) f2.write((x)+("_2_+\n")) f2.write((x)+("_3_+\n")) f2.write((x)+("_1_-\n")) f2.write((x)+("_2_-\n")) f2.write((x)+("_3_-\n")) else: f2.write((translate1(x))+("\n")) f2.write((translate2(x))+("\n")) f2.write((translate3(x))+("\n")) f2.write((translate1neg(x))+("\n")) f2.write((translate2neg(x))+("\n")) f2.write((translate3neg(x))+("\n"))
But unlike the expected output file suggested, i get this:
>seq1_1_+ >seq1_2_+ >seq1_3_+ >seq1_1_- >seq1_2_- >seq1_3_- iyyslrs-las-smrlssiv-m fiirydrs-ladrcgshrssk llfativas-lidaalidrl frrsmraasis-lativannkm lddr-ephrsas-lrs-riin -tidesridqlasydrse--m
So he's pretty much doing all the seq's first, and all the functions afterwards, so i need to intercalate them, problem is how.