[Biojava-l] Running apps with Java

Patrick McConnell MCCon012 at mc.duke.edu
Mon Aug 11 11:28:14 EDT 2003

We do something similar, and I have not ran into any problems.  The biggest
problem is when stdout and stderr are not handled in separate threads.

Personally, I would like to see API's developed for specific applications.
Something ilke:

    public static int execNCBIBlast(
        String executable,
        String inputFile,
        String outputFile
        String program,
        String database,
        String input,
        StringBuffer stdout,
        StringBuffer stderr

Or, even better would be some sort of Parameters class to encapsulate all
those parameters, providing optional parameters.  Then, you could do
something like this:

   NCBIBlastParameters params = new NCBIBlastParameters();
   params.addParameter("p", "blastn");
   params.addParameter("d", "nt");
   params.addParameter("m", "7");
   StringBuffer outputXML = new StringBuffer();
   int success = NCBIBlast.exec(

I think this would be more convenient to people for developing
applications.  If you wanted to get fancy, you could have the exec method
throw an exception for missing or invalid parameters.  Perhaps a method to
turn off this parameter checking would also be necessary.


Thomas Down <td2 at sanger.ac.uk>@biojava.org on 08/11/2003 04:11:08 AM

Sent by:    biojava-l-bounces at biojava.org

To:    "Schreiber, Mark" <mark.schreiber at agresearch.co.nz>
cc:    biojava-l at biojava.org

Subject:    Re: [Biojava-l] Running apps with Java

On Mon, Aug 11, 2003 at 11:59:46AM +1200, Schreiber, Mark wrote:
> What is the best way to invoke a native bioinformatics program in Java.
> People have reported that controlling processes directly has been patchy
> in Java, is this still the case or have JVMs evolved? If not then what
> is the alternative? Wrapping the program in a perl or python webservice?
> If this was the prefered method then we could borrow quite a bit from
> the Bio::Pipeline::Runnable package.

I think it *is* possible to write good-quality wrappers to
external tools in Java: it's just that the Runtime.exec
APIs are substantially more complicated than the equivalents
in $PREFERRED_SCRIPTING_LANGUAGE.  If you're using stdin/stdout/stderr
on the external program, you need to make heavy use of Threads
in Java.  I think that's the main barrier to entry.

A lot of these issues could probably be addressed by something

public class ExecTools {
     * Execute an external program and wait for it to complete.
     * @param args the command line to run.
     * @param input some data to feed to the program's standard input,
     *              or null if no data.
     * @param stdout a StringBuffer to receive the program's output,
     *               or null to ignore them.
     * @param stderr a StringBuffer to receive the program's error
     *               stream, or null to ignore this.
     * @returns the program's return code.

    public static int exec(
        String[] args,
        String input,
        StringBuffer stdout,
        StringBuffer stderr

All the necessary thread code for most practical uses of exec could
be hidden in there.  I might code this up this afternoon if nobody
objects -- it's code I write reasonably regularly, and the API above
would certainly save me time.  Anyone else?

As for the web service approach, AppLap might be relevant:


Biojava-l mailing list  -  Biojava-l at biojava.org

More information about the Biojava-l mailing list