Skip to content

Instantly share code, notes, and snippets.

@chapmanb
Created February 19, 2010 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapmanb/308708 to your computer and use it in GitHub Desktop.
Save chapmanb/308708 to your computer and use it in GitHub Desktop.
import os
import subprocess
import tempfile
from Bio import SeqIO
from Bio.Emboss.Applications import NeedleCommandline
# read in file from somewhere
in_file = os.path.join("Tests", "NeuralNetwork", "enolase.fasta")
in_handle = open(in_file)
gen = SeqIO.parse(in_handle, "fasta")
a = gen.next()
a.id = "1"
b = gen.next()
b.id = "2"
# create temporary file
(_, tmp_file) = tempfile.mkstemp()
tmp_handle = open(tmp_file, "w")
SeqIO.write([a, b], tmp_handle, 'fasta')
tmp_handle.close()
# run needle
cline = NeedleCommandline( gapopen=10, gapextend=.5, outfile='stdout',
asequence='%s:%s' % (tmp_file, a.id),
bsequence='%s:%s' % (tmp_file, b.id))
child = subprocess.Popen(str(cline), shell=True, stdout=subprocess.PIPE,)
child.wait()
os.remove(tmp_file)
print child.returncode
print child.stdout.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment