Biopython Primer Design
1
1
Entering edit mode
12.2 years ago
Zach Powers ▴ 340

Hi Biostar,

I want to use Primer3 via BioPython to automate primer design for a series of sequences in a fasta file. The best examples that I can find on the web (for example this and this) use modules (Bio.Application.generic_run, Bio.Fasta) that are deprecated.

Although I have the basics of parsing/iterating I do not know how to replace the generic_run function from Bio.Application and would appreciate any suggestions on how to pass fasta sequences to eprimer3.

thanks, zach cp

biopython primer • 9.4k views
ADD COMMENT
3
Entering edit mode
12.2 years ago
Peter 6.0k

The generic_run function was present up to and including Biopython 1.57. Given a Bio.Application style wrapper object, say primer_cl based on the primer_pick.py example you linked to, the application was run like this:

from Bio.Application import generic_run
result, messages, errors = generic_run(primer_cl)

Here there are three return values. First an ApplicationResult object holding the return code, then stdout and stderr output (in memory as StringIO handles).

As of Biopython 1.55, you can execute the command directly using the command line wrapper object itself:

stdout, stderr = primer_cl()

This time you just get the stdout and stderr from the command (in memory as strings), but the return code was checked and if non-zero an exception would be raised (which would tell you the return code).

This is what the DEPRECATED file supplied with Biopython is trying to tell you:

Bio.Application.generic_run and ApplicationResult

Declared obsolete in Release 1.51, deprecated in Release 1.53, and removed in Release 1.57. Please use the Python subprocess module instead, or as of Release 1.55 the application wrappers can be used directly to execute the command.

So, to summarize, to update the primer_pick.py example, probably all you need to do is delete this line:

from Bio.Application import generic_run

and replace this:

result, messages, errors = generic_run(primer_cl)
print result

with this:

stdout, stderr = primer_cl()

The script doesn't actually use these return values at all as far as I can see.

P.S. You didn't ask about it directly, but the functionality of Bio.Fasta is now in Bio.SeqIO along with many other file formats. Please see the Biopython Tutorial for details.

ADD COMMENT
0
Entering edit mode

thank you Peter - great answer. This is the sort of answer that helps the transition from newbie to not-so-newbie.

ADD REPLY
0
Entering edit mode

Hi Peter,

I just came across this thread since I was looking for ideas of how to approach primer design using Biophyton and Primer3.

My understanding is that Biopython Bio.Emboss.Primer3 module is designed to work with Emboss eprimer as a proxy to Primer3. So after introducing the suggested above changes into the primer_pick.py example, I'm getting the following error -

File "C:\Python27\lib\site-packages\Bio\Application\__init__.py", line 515, in __call__    stdout_str, stderr_str) Bio.Application.ApplicationError: Non-zero return code 1 from 'eprimer3 -auto -outfile=out.pr3 -sequence=in.fas -numreturn=3 -osi... 

etc

My OS is win7. The Primer3 is in the PATH, Python 2.7, Biopython is 1.65.

I'm not clear about whether or not the eprimer wrapper needs to be additionally installed? But also do you know of any more direct approach to Primer3 from Python?

Thanks

ADD REPLY
0
Entering edit mode

Not sure, but you'd be best off asking this as a new question on BioStars.

ADD REPLY

Login before adding your answer.

Traffic: 2194 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