from Bio import SeqIO
for record in SeqIO.parse("rna_1.fasta", "fasta"):
printrecord.id)
print(record.seq.translate())
print(record.seq[1:].translate())
print(record.seq[2:].translate())
Dear all,
This is my first time working with Biopython. I tried to translate unambigous rna sequences from a multi-fasta format file (containing 5 different random sequences) with 3 frame shifts (= meaning getting all possible translation of the RNA sequence). I got this part with the help of Biopython Tutorial and Cook book pdf . “onlinehttp://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc35”
Then I tried to write all the possible translation into a new file. And here I am, stuck.
What I already tried:
1) Using Bio.SeqRecord I get only 5 translations of the 5 different RNA sequences. So I don’t get the other 2 frame shifted translation sequences under the original one.
2) And I even tried it with records but then I get 3 sequences only translated. But these are from the last sequence (= means 5th sequence from fasta file) of the random RNA with all 3 possible translation of RNA.
I did not find any other method that could write my translated sequences into a new fasta file. Please help I have tried everything. That means that I have even tried to write all the sequences with hand (see site: writing sequence files) even this attempt was not successful because every translated frame was written in one single line. So I got 5 lines, with 1 line containing all possible translations. What I am trying to achieve is to put all the translated sequences into a fasta file. This means there should be in total 15 sequences.
2 answers
Assuming
[/scratch/tmp/biostars/biopython_translate_allframes]$ cat test.fa
>a
agctagctagc
>b
gctagctgctag
>c
gatcgatcgatcga
>d
gctgctagctagct
>e
gctagctagctag
Something along this should work fine.
with open('test.translated.fa', 'w') as fout:
for rec in SeqIO.parse('test.fa', 'fasta'):
for frame in range(0,3):
SeqIO.write(SeqRecord(seq=rec[frame:].seq.translate(), id=rec.id, description=str(frame)), fout, 'fasta')
BioPython’s SeqUtils offers a six_frame_translations method, I’d advise using this. Eric’s solution, while neat, probably isn’t really the ‘pythonic’ way - you’d be getting your hands unnecessarily dirty ;)
Nice! I knew there must be a way to translate 6-way within the module.
Log in to answer this question.
It'd be helpful to post some code snippets to illustrate what you'd tried. Without checking into biopython's ability to translate 3 frames directly from the interface, one approach can be
rec.seq.translate(),rec.seq[1:].translate(), andrec.seq[2:].translate().I already tried that but then also I would only get 5 translated sequences that are in the frame. The other 2 translations are not there.
This code will give:
TypeError: __init__() got an unexpected keyword argument 'seq1'Please use the formatting bar (especially the

codeoption) to present your post better. I've done it for you this time.Thank you!
Sorry, Thanks :)