Calling muscle as a Java process
1
0
Entering edit mode
9.1 years ago
Bioaln ▴ 360

Hello. I'm developing a Java application, which at some point calls a MSA algorithm. Currently, I'm using muscle. I'm trying to call this process from within java app, there are no errors, yet there is no output! Is there a syntax problem I am not aware of?

try {
            System.out.println("Opening muscle analysis..");
            Runtime runTime = Runtime.getRuntime();
            Process process = runTime.exec(new String[]{
                            "muscle",
                            "-in","test1.fasta",
                            "-out","out12.afa"}
                        );            
            System.out.println("Closing..");
            process.destroy();
        } catch (IOException e) {
            e.printStackTrace();
        }

Thank you very much

muscle external-process java • 2.4k views
ADD COMMENT
0
Entering edit mode

Following code works defintely:

public void execute(String[] command)
{
    try {
        ProcessBuilder pb = new ProcessBuilder(command);
        pb.redirectErrorStream(true);
        Process p = pb.start();
        BufferedReader br = new BufferedReader(new InputStreamReader(
                p.getInputStream()));
        String out = "";
        while ((out = br.readLine()) != null)
            System.out.println(out);


    } catch (Exception e) {
        e.printStackTrace();

    }
}

How to call it: execute(new String[]{"muscle","-in", "input.fa" , "-out" , "output.fa"});

ADD REPLY
0
Entering edit mode
9.1 years ago

check muscle is in the PATH, you may need to consumme the stdout and the stderr and wait for the end of the process ( don't use destroy but waitFor). A shorter way to do this is:

Runtime.getRuntime().exec("/path/to/muscle -in "+"test1.fasta"+" -out "+"out12.fa");
ADD COMMENT
0
Entering edit mode

Thanks, I actually experimented a bit with destroy(), and it was the main problem, but thanks again :)

ADD REPLY

Login before adding your answer.

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