OPs code was actually correct (I mean, no lonely parenthesis), but not rendered correctly by the biostars code engine. I have adapted the post to fix it.
• 0 views
•
link
> File "dna2prot2-working-test-Copy.py", line 29, in <module> print
> (entry.seq).translate()#This will translate nucleotide sequence to
> amino acid sequence AttributeError: 'NoneType' object has no attribute
> 'translate'
Code:
import sys
from Bio import SeqIO
from Bio.SeqIO.FastaIO import *
def fasta_reader(filename): with open(filename) as handle:
for record in FastaIterator(handle):
yield record
for entry in fasta_reader("test.txt"):
print entry.id) #This is header of fasta entry
print
print (entry.seq) #This is sequence of specific fasta entry
print
dna=str (entry.seq)
print ( entry.id)
from Bio.Tools import Translate
print (entry.seq).translate()#This will translate nucleotide sequence to amino acid sequence
I think that the issue is that you are trying to translate outside from the for loop, and also that you are trying to translate the output of print instead of the seq item.
Try this:
import sys
from Bio import SeqIO
from Bio.Tools import Translate
from Bio.SeqIO.FastaIO import *
def fasta_reader(filename):
with open(filename) as handle:
for record in FastaIterator(handle):
yield record
for entry in fasta_reader("test.txt"):
print entry.id) #This is header of fasta entry
print (entry.seq) #This is sequence of specific fasta entry
dna = str (entry.seq)
print entry.id)
print (entry.seq.translate())
Hi,
The python error is clear: the syntax is not correct. Let's see your line. You have a lonely parenthesis on your print. Try this:
print str( entry.id )
Instead of:
print strentry.id)
This is a syntax error.
OPs code was actually correct (I mean, no lonely parenthesis), but not rendered correctly by the biostars code engine. I have adapted the post to fix it.
Log in to answer this question.
I did my best to properly format the code...
And does entry.seq look as expected?