[Biopython-dev] subprocess and calling application wrappers

Peter biopython at maubp.freeserve.co.uk
Mon May 31 14:50:36 UTC 2010


Hi all,

With the new command line wrappers and the tutorial pushing
users towards using subprocess we've had more queries
about how to use it. The subprocess module itself is rather
scary I guess, and things could be made a lot easier.

I think the most typical use cases are:

(1) Run the command, return the error code (integer)
(2) Run the command, return stdout, stderr and error code

In theory the function subprocess.call() would take care
of the first example, but there is a cross platform annoyance
here with the shell parameter. Also, if you want the output
too things get even more tricky. It hasn't helped that there
are a few platform specific quirks/bugs in subprocess itself
(the different behaviour of the shell option on Windows,
bug http://bugs.python.org/issue1124861 in old Pythons,
the risk of deadlocks with large output files, etc).

A while ago while doing the Bio.Motif application wrappers
Bartek suggested adding a run or execute method to the
application wrapper. I wasn't so receptive at the time, but
the utility of this has grown on me. However, adding methods
could potentially clash with arbitrary parameter names.

We could instead make the wrapper objects callable (define
the magic method __call__) to offer this kind of functionality.
This seems quite elegant to me. I've just posted a possible
such implementation for comment on this new branch,
http://github.com/peterjc/biopython/tree/app-exec

Thus far there is just one commit,
http://github.com/peterjc/biopython/commit/b53fb443e2153576509e159a1eac9da55124e41b

Is this a nice approach?

Assuming this is a well received idea, there are several
details to discuss. First of all, if we are going to return the
stdout and stderr would it be best as strings or wrapped as
handles (using StringIO) which can be passed to a parser?

Peter



More information about the Biopython-dev mailing list