From: cmzmasek@gmail.com Date: Thu, 5 Jul 2012 23:23:33 +0000 (+0000) Subject: in progress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a1f96e88c8d5c06bc64a7b614dd883d696b0fefe;p=jalview.git in progress --- diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 0912f9a..ac08d25 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -216,7 +216,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { Configuration _configuration; JMenuItem _remove_branch_color_item; Options _options; - InferenceManager _inference_manager; + InferenceManager _inference_manager; final ProcessPool _process_pool; MainFrame() { @@ -906,12 +906,11 @@ public abstract class MainFrame extends JFrame implements ActionListener { void setInferenceManager( final InferenceManager i ) { _inference_manager = i; } - + public InferenceManager getInferenceManager() { return _inference_manager; } - - + void setSelectedTypeInTypeMenu( final PHYLOGENY_GRAPHICS_TYPE type ) { setTypeMenuToAllUnselected(); switch ( type ) { diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index efdc982..f4dc785 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -680,7 +680,8 @@ public final class MainFrameApplication extends MainFrame { .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" ); } else { - _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) ); + _inference_menu + .add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences (no program found)" ) ); customizeJMenuItem( _inference_from_seqs_item ); _inference_from_seqs_item.setEnabled( false ); } diff --git a/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java b/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java index 6886243..f472ff0 100644 --- a/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java +++ b/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java @@ -52,7 +52,7 @@ public final class InferenceManager { if ( ( path != null ) && path.canExecute() && !path.isDirectory() ) { return path; } - File p1 = new File( name ); + final File p1 = new File( name ); if ( p1.canExecute() && !p1.isDirectory() ) { return p1; } diff --git a/forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java b/forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java index 4cac659..bf78f01 100644 --- a/forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java +++ b/forester/java/src/org/forester/archaeopteryx/tools/PhylogeneticInferrer.java @@ -265,7 +265,8 @@ public class PhylogeneticInferrer extends RunnableProcess { private Msa runMAFFT( final File input_seqs, final List opts ) throws IOException, InterruptedException { Msa msa = null; - final MsaInferrer mafft = Mafft.createInstance( _mf.getInferenceManager().getPathToLocalMafft().getCanonicalPath()); + final MsaInferrer mafft = Mafft.createInstance( _mf.getInferenceManager().getPathToLocalMafft() + .getCanonicalPath() ); try { msa = mafft.infer( input_seqs, opts ); } @@ -274,10 +275,12 @@ public class PhylogeneticInferrer extends RunnableProcess { } return msa; } - - private Msa runClustalOmega( final File input_seqs, final List opts ) throws IOException, InterruptedException { + + private Msa runClustalOmega( final File input_seqs, final List opts ) throws IOException, + InterruptedException { Msa msa = null; - final MsaInferrer clustalo = ClustalOmega.createInstance(_mf.getInferenceManager().getPathToLocalClustalo().getCanonicalPath()); + final MsaInferrer clustalo = ClustalOmega.createInstance( _mf.getInferenceManager().getPathToLocalClustalo() + .getCanonicalPath() ); try { msa = clustalo.infer( input_seqs, opts ); } diff --git a/forester/java/src/org/forester/msa/ClustalOmega.java b/forester/java/src/org/forester/msa/ClustalOmega.java index 80e73b7..627eb64 100644 --- a/forester/java/src/org/forester/msa/ClustalOmega.java +++ b/forester/java/src/org/forester/msa/ClustalOmega.java @@ -33,24 +33,20 @@ import java.util.List; import org.forester.io.parsers.FastaParser; import org.forester.util.SystemCommandExecutor; -public final class ClustalOmega implements MsaInferrer { +public final class ClustalOmega extends MsaInferrer { private final static String DEFAULT_PARAMETERS = ""; private String _error; private int _exit_code; private final String _path_to_prg; - - public static MsaInferrer createInstance( final String path_to_prg ) throws IOException { return new ClustalOmega( path_to_prg ); } - - private ClustalOmega( final String path_to_prg ) throws IOException { - if ( !SystemCommandExecutor.isExecuteableFile( new File( path_to_prg ) ) ) { - throw new IOException( "cannot execute MAFFT with \"" + path_to_prg + "\"" ); + if ( !isInstalled( path_to_prg ) ) { + throw new IOException( "cannot execute Clustal Omega with \"" + path_to_prg + "\"" ); } _path_to_prg = new String( path_to_prg ); init(); @@ -61,11 +57,6 @@ public final class ClustalOmega implements MsaInferrer { } @Override - public Object clone() { - throw new NoSuchMethodError(); - } - - @Override public String getErrorDescription() { return _error; } @@ -94,8 +85,8 @@ public final class ClustalOmega implements MsaInferrer { } final StringBuilder stdout = command_executor.getStandardOutputFromCommand(); if ( ( stdout == null ) || ( stdout.length() < 2 ) ) { - throw new IOException( "Clustal Omega program did not produce any output\nCommand:\n" + my_opts + "\nError:\n" - + stderr ); + throw new IOException( "Clustal Omega program did not produce any output\nCommand:\n" + my_opts + + "\nError:\n" + stderr ); } final Msa msa = FastaParser.parseMsa( stdout.toString() ); return msa; diff --git a/forester/java/src/org/forester/msa/Mafft.java b/forester/java/src/org/forester/msa/Mafft.java index 7e4e4c0..e175f0d 100644 --- a/forester/java/src/org/forester/msa/Mafft.java +++ b/forester/java/src/org/forester/msa/Mafft.java @@ -31,26 +31,21 @@ import java.util.ArrayList; import java.util.List; import org.forester.io.parsers.FastaParser; -import org.forester.util.ForesterUtil; import org.forester.util.SystemCommandExecutor; -public final class Mafft implements MsaInferrer { +public final class Mafft extends MsaInferrer { private final static String DEFAULT_PARAMETERS = "--maxiterate 1000 --localpair"; private String _error; private int _exit_code; private final String _path_to_prg; - - public static MsaInferrer createInstance( final String path_to_prg ) throws IOException { return new Mafft( path_to_prg ); } - - private Mafft( final String path_to_prg ) throws IOException { - if ( !SystemCommandExecutor.isExecuteableFile( new File( path_to_prg ) ) ) { + if ( !isInstalled( path_to_prg ) ) { throw new IOException( "cannot execute MAFFT with \"" + path_to_prg + "\"" ); } _path_to_prg = new String( path_to_prg ); @@ -62,11 +57,6 @@ public final class Mafft implements MsaInferrer { } @Override - public Object clone() { - throw new NoSuchMethodError(); - } - - @Override public String getErrorDescription() { return _error; } diff --git a/forester/java/src/org/forester/msa/MafftOLD.java b/forester/java/src/org/forester/msa/MafftOLD.java deleted file mode 100644 index 7301cc1..0000000 --- a/forester/java/src/org/forester/msa/MafftOLD.java +++ /dev/null @@ -1,81 +0,0 @@ - -package org.forester.msa; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.List; - -import org.forester.io.parsers.FastaParser; -import org.forester.util.ExternalProgram; -import org.forester.util.ForesterUtil; - -public final class MafftOLD implements MsaInferrer { - - private String _error; - private int _exit_code; - private final String _path_to_prg; - - public static MsaInferrer createInstance( final String path_to_prg ) { - return new MafftOLD( path_to_prg ); - } - - private MafftOLD( final String path_to_prg ) { - _path_to_prg = new String( path_to_prg ); - init(); - } - - @Override - public Object clone() { - 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 String[] my_opts = new String[ opts.size() + 1 ]; - for( int i = 0; i < opts.size(); i++ ) { - my_opts[ i ] = opts.get( i ); - } - my_opts[ opts.size() ] = path_to_input_seqs.getAbsolutePath(); - final ExternalProgram mafft_prg = new ExternalProgram( _path_to_prg ); - mafft_prg.launch( my_opts ); - // _exit_code = mafft_prg.waitFor(); - // if ( _exit_code != 0 ) { - // throw new IOException( "MAFFT failed, exit code: " + _exit_code ); - // } - final BufferedReader r = new BufferedReader( new InputStreamReader( mafft_prg.getErrorStream() ) ); - final StringBuffer error_sb = new StringBuffer(); - String line = null; - while ( ( line = r.readLine() ) != null ) { - error_sb.append( line ); - error_sb.append( ForesterUtil.LINE_SEPARATOR ); - } - r.close(); - if ( error_sb.length() > 0 ) { - _error = error_sb.toString(); - throw new IOException( "MAFFT failed" ); - } - final InputStream is = mafft_prg.getInputStream(); - final Msa msa = FastaParser.parseMsa( is ); - is.close(); - return msa; - } - - private void init() { - _error = null; - _exit_code = -100; - } -} diff --git a/forester/java/src/org/forester/msa/MsaInferrer.java b/forester/java/src/org/forester/msa/MsaInferrer.java index 593dd1f..8266648 100644 --- a/forester/java/src/org/forester/msa/MsaInferrer.java +++ b/forester/java/src/org/forester/msa/MsaInferrer.java @@ -29,11 +29,22 @@ import java.io.File; import java.io.IOException; import java.util.List; -public interface MsaInferrer { +import org.forester.util.SystemCommandExecutor; - public String getErrorDescription(); +public abstract class MsaInferrer { - public int getExitCode(); + public abstract String getErrorDescription(); - public Msa infer( File path_to_input_seqs, List opts ) throws IOException, InterruptedException; + public abstract int getExitCode(); + + public static boolean isInstalled( final String path_to_prg ) { + return SystemCommandExecutor.isExecuteableFile( new File( path_to_prg ) ); + } + + @Override + public Object clone() { + throw new NoSuchMethodError(); + } + + public abstract Msa infer( File path_to_input_seqs, List opts ) throws IOException, InterruptedException; } diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 55030a2..7983cae 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -687,7 +687,19 @@ public final class Test { System.out.println( "failed." ); failed++; } - if ( Mafft.isInstalled() ) { + //---- + String path = ""; + final String os = ForesterUtil.OS_NAME.toLowerCase(); + if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) { + path = "/usr/local/bin/mafft"; + } + else if ( os.indexOf( "win" ) >= 0 ) { + path = "C:\\Program Files\\mafft-win\\mafft.bat"; + } + else { + path = "/home/czmasek/bin/mafft"; + } + if ( Mafft.isInstalled( path ) ) { System.out.print( "MAFFT (external program): " ); if ( Test.testMafft() ) { System.out.println( "OK." ); @@ -697,6 +709,7 @@ public final class Test { System.out.println( "failed [will not count towards failed tests]" ); } } + //---- System.out.print( "Next nodes with collapsed: " ); if ( Test.testNextNodeWithCollapsing() ) { System.out.println( "OK." ); @@ -7951,20 +7964,17 @@ public final class Test { opts.add( "1000" ); opts.add( "--localpair" ); opts.add( "--quiet" ); - - - String path = ""; - final String os = ForesterUtil.OS_NAME.toLowerCase(); - if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) { - path = "/usr/local/bin/mafft"; - } - else if ( os.indexOf( "win" ) >= 0 ) { - path = "C:\\Program Files\\mafft-win\\mafft.bat"; - } - else { - path = "/home/czmasek/bin/mafft"; - } - + String path = ""; + final String os = ForesterUtil.OS_NAME.toLowerCase(); + if ( ( os.indexOf( "mac" ) >= 0 ) && ( os.indexOf( "os" ) > 0 ) ) { + path = "/usr/local/bin/mafft"; + } + else if ( os.indexOf( "win" ) >= 0 ) { + path = "C:\\Program Files\\mafft-win\\mafft.bat"; + } + else { + path = "/home/czmasek/bin/mafft"; + } Msa msa = null; final MsaInferrer mafft = Mafft.createInstance( path ); msa = mafft.infer( new File( PATH_TO_TEST_DATA + "ncbi_sn.fasta" ), opts ); diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index 7b9fefa..eab885d 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -96,10 +96,10 @@ public final class ForesterUtil { } } - public static boolean isWindowns () { - return ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1; + public static boolean isWindowns() { + return ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1; } - + final public static String getForesterLibraryInformation() { return "forester " + ForesterConstants.FORESTER_VERSION + " (" + ForesterConstants.FORESTER_DATE + ")"; }