X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fmsa%2FMafft.java;h=6fc1675fb4ad34304079b80f09552d246986102b;hb=885253f33f05af39d0d529659d534f5a3365159e;hp=644b5b52a469b00c5e1dce56c6ef1b297127594c;hpb=48f7a89be9d34f1930a1f863e608235cc27184c5;p=jalview.git diff --git a/forester/java/src/org/forester/msa/Mafft.java b/forester/java/src/org/forester/msa/Mafft.java index 644b5b5..6fc1675 100644 --- a/forester/java/src/org/forester/msa/Mafft.java +++ b/forester/java/src/org/forester/msa/Mafft.java @@ -5,7 +5,7 @@ // Copyright (C) 2010 Christian M Zmasek // Copyright (C) 2010 Sanford-Burnham Medical Research Institute // All rights reserved -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -15,7 +15,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA @@ -41,12 +41,18 @@ public final class Mafft implements MsaInferrer { private int _exit_code; private final String _path_to_prg; - public static MsaInferrer createInstance( final String path_to_prg ) { + public static MsaInferrer createInstance() throws IOException { + return createInstance( getPathToCmd() ); + } + + public static MsaInferrer createInstance( final String path_to_prg ) throws IOException { return new Mafft( path_to_prg ); } private static String getPathToCmd() { - //TODO this needs to come from env variable, etc. + //TODO this needs to come from config file!! + //FIXME .. + //should not be in this class! String path = ""; final String os = ForesterUtil.OS_NAME.toLowerCase(); if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) { @@ -56,7 +62,7 @@ public final class Mafft implements MsaInferrer { path = "C:\\Program Files\\mafft-win\\mafft.bat"; } else { - path = "/home/czmasek/SOFTWARE/MSA/MAFFT/mafft-6.832-without-extensions/scripts/mafft"; + path = "/home/czmasek/bin/mafft"; } return path; } @@ -65,13 +71,9 @@ public final class Mafft implements MsaInferrer { return SystemCommandExecutor.isExecuteableFile( new File( getPathToCmd() ) ); } - public static MsaInferrer createInstance() { - return createInstance( getPathToCmd() ); - } - - private Mafft( final String path_to_prg ) { + private Mafft( final String path_to_prg ) throws IOException { if ( !SystemCommandExecutor.isExecuteableFile( new File( path_to_prg ) ) ) { - throw new IllegalArgumentException( "cannot execute MAFFT via [" + path_to_prg + "]" ); + throw new IOException( "cannot execute MAFFT with \"" + path_to_prg + "\"" ); } _path_to_prg = new String( path_to_prg ); init(); @@ -86,14 +88,17 @@ public final class Mafft implements MsaInferrer { throw new NoSuchMethodError(); } + @Override public String getErrorDescription() { return _error; } + @Override public int getExitCode() { return _exit_code; } + @Override public Msa infer( final File path_to_input_seqs, final List opts ) throws IOException, InterruptedException { init(); final List my_opts = new ArrayList(); @@ -102,17 +107,19 @@ public final class Mafft implements MsaInferrer { my_opts.add( opts.get( i ) ); } my_opts.add( path_to_input_seqs.getAbsolutePath() ); - final SystemCommandExecutor commandExecutor = new SystemCommandExecutor( my_opts ); - final int _exit_code = commandExecutor.executeCommand(); + final SystemCommandExecutor command_executor = new SystemCommandExecutor( my_opts ); + final int _exit_code = command_executor.executeCommand(); + final StringBuilder stderr = command_executor.getStandardErrorFromCommand(); + _error = stderr.toString(); if ( _exit_code != 0 ) { - throw new IOException( "MAFFT failed, exit code: " + _exit_code ); + throw new IOException( "MAFFT program failed, exit code: " + _exit_code + "\nCommand:\n" + my_opts + + "\nError:\n" + stderr ); + } + final StringBuilder stdout = command_executor.getStandardOutputFromCommand(); + if ( ( stdout == null ) || ( stdout.length() < 2 ) ) { + throw new IOException( "MAFFT program did not produce any output\nCommand:\n" + my_opts + "\nError:\n" + + stderr ); } - final StringBuilder stdout = commandExecutor.getStandardOutputFromCommand(); - final StringBuilder stderr = commandExecutor.getStandardErrorFromCommand(); - System.out.println( stdout ); - System.out.println(); - System.out.println( stderr ); - _error = stderr.toString(); final Msa msa = FastaParser.parseMsa( stdout.toString() ); return msa; }