Python script error
2
0
Entering edit mode
6.3 years ago
> 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
python biopython • 1.6k views
ADD COMMENT
0
Entering edit mode

I did my best to properly format the code...

ADD REPLY
0
Entering edit mode

And does entry.seq look as expected?

ADD REPLY
3
Entering edit mode
6.3 years ago

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())
ADD COMMENT
0
Entering edit mode
6.3 years ago
Thibault D. ▴ 700

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.

ADD COMMENT
1
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 2773 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6