From de8fbefc959f11af246340c4f903fb2983a95d4d Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Sun, 1 Jul 2012 22:09:04 +0000 Subject: [PATCH] inference --- .../org/forester/archaeopteryx/Configuration.java | 116 +++++++++++++------- .../src/org/forester/archaeopteryx/MainFrame.java | 11 ++ .../archaeopteryx/MainFrameApplication.java | 19 +++- .../archaeopteryx/tools/InferenceManager.java | 78 ++++++++++++- .../java/src/org/forester/util/ForesterUtil.java | 4 + 5 files changed, 180 insertions(+), 48 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index ea48459..d81100a 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -62,9 +62,6 @@ public final class Configuration { private boolean _use_tabbed_display = false; private boolean _hide_controls_and_menus = false; private CLADOGRAM_TYPE _cladogram_type = Constants.CLADOGRAM_TYPE_DEFAULT; - private File _mafft = null; - private File _clustalo = null; - private File _fastme = null; private SortedMap _weblinks = null; private SortedMap _display_colors = null; private boolean _antialias_screen = true; @@ -93,12 +90,17 @@ public final class Configuration { private boolean _show_domain_labels = true; private boolean _abbreviate_scientific_names = false; private boolean _color_labels_same_as_parent_branch = false; - private int _default_bootstrap_samples = -1; private boolean _show_default_node_shapes = false; private NodeShape _default_node_shape = NodeShape.CIRCLE; private NodeFill _default_node_fill = NodeFill.GRADIENT; private short _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT; private boolean _taxonomy_colorize_node_shapes = false; + private int _default_bootstrap_samples = -1; + private File _path_to_local_mafft = null; + private File _path_to_local_kalign = null; + private File _path_to_local_fastme = null; + private File _path_to_local_raxml = null; + private File _path_to_local_clustalo = null; final static int display_as_phylogram = 0; final static int show_node_names = 1; final static int show_tax_code = 2; @@ -434,6 +436,22 @@ public final class Configuration { return _default_bootstrap_samples; } + public File getpathToLocalMafft() { + return _path_to_local_mafft; + } + + public File getPathToLocalKalign() { + return _path_to_local_kalign; + } + + public File getPathToLocalFastme() { + return _path_to_local_fastme; + } + + public File getPathToLocalRaxml() { + return _path_to_local_raxml; + } + int getDefaultDisplayClicktoOption() { return default_clickto; } @@ -804,6 +822,30 @@ public final class Configuration { _default_bootstrap_samples = default_bootstrap_samples; } + private void setPathToLocalMafft( final File path_to_local_mafft ) { + _path_to_local_mafft = path_to_local_mafft; + } + + private void setPathToLocalKalign( final File path_to_local_kalign ) { + _path_to_local_kalign = path_to_local_kalign; + } + + private void setPathToLocalFastme( final File path_to_local_fastme ) { + _path_to_local_fastme = path_to_local_fastme; + } + + private void setPathToLocalRaxml( final File path_to_local_raxml ) { + _path_to_local_raxml = path_to_local_raxml; + } + + public File getPathToLocalClustalOmega() { + return _path_to_local_clustalo; + } + + public void setPathToLocalClustalOmega( final File path_to_local_clustalo ) { + _path_to_local_clustalo = path_to_local_clustalo; + } + public void setDefaultNodeFill( final NodeFill default_node_fill ) { _default_node_fill = default_node_fill; } @@ -930,18 +972,6 @@ public final class Configuration { _ui = UI.UNKNOWN; } } - else if ( key.equals( "path_to_mafft" ) ) { - setPathToMafft( new File( ( String ) st.nextElement() ) ); - } - else if ( key.equals( "path_to_clustalo" ) ) { - setPathToClustalOmega( new File( ( String ) st.nextElement() ) ); - } - else if ( key.equals( "path_to_fastme" ) ) { - setPathToFastME( new File( ( String ) st.nextElement() ) ); - } - else if ( key.equals( "path_to_mafft" ) ) { - setPathToMafft( new File( ( String ) st.nextElement() ) ); - } else if ( key.equals( VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA ) ) { setValidatePhyloXmlAgainstSchema( parseBoolean( ( String ) st.nextElement() ) ); } @@ -1026,6 +1056,36 @@ public final class Configuration { "value for [default_number_of_bootstrap_resamples] cannot be negative" ); } } + else if ( key.equals( "clustalo_local" ) ) { + final String str = ( ( String ) st.nextElement() ).trim(); + if ( !ForesterUtil.isEmpty( str ) ) { + setPathToLocalClustalOmega( new File( str ) ); + } + } + else if ( key.equals( "mafft_local" ) ) { + final String str = ( ( String ) st.nextElement() ).trim(); + if ( !ForesterUtil.isEmpty( str ) ) { + setPathToLocalMafft( new File( str ) ); + } + } + else if ( key.equals( "kalign_local" ) ) { + final String str = ( ( String ) st.nextElement() ).trim(); + if ( !ForesterUtil.isEmpty( str ) ) { + setPathToLocalKalign( new File( str ) ); + } + } + else if ( key.equals( "fastme_local" ) ) { + final String str = ( ( String ) st.nextElement() ).trim(); + if ( !ForesterUtil.isEmpty( str ) ) { + setPathToLocalFastme( new File( str ) ); + } + } + else if ( key.equals( "raxml_local" ) ) { + final String str = ( ( String ) st.nextElement() ).trim(); + if ( !ForesterUtil.isEmpty( str ) ) { + setPathToLocalRaxml( new File( str ) ); + } + } else if ( key.equals( "show_scale" ) ) { setShowScale( parseBoolean( ( String ) st.nextElement() ) ); } @@ -1517,30 +1577,6 @@ public final class Configuration { return DEFAULT_FONT_FAMILY; } - public File getPathToMafft() { - return _mafft; - } - - public File getPathToClustalOmega() { - return _clustalo; - } - - public File getPathToFastME() { - return _fastme; - } - - public void setPathToMafft( final File mafft ) { - _mafft = mafft; - } - - public void setPathToClustalOmega( final File clustalo ) { - _clustalo = clustalo; - } - - public void setPathToFastME( final File fastme ) { - _fastme = fastme; - } - static enum TRIPLET { TRUE, FALSE, UNKNOWN } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 26600d9..ff3f6a9 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -48,6 +48,7 @@ import javax.swing.SwingUtilities; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION; import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE; +import org.forester.archaeopteryx.tools.InferenceManager; import org.forester.archaeopteryx.tools.ProcessPool; import org.forester.archaeopteryx.tools.ProcessRunning; import org.forester.phylogeny.Phylogeny; @@ -215,6 +216,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { Configuration _configuration; JMenuItem _remove_branch_color_item; Options _options; + InferenceManager _inference_manager; final ProcessPool _process_pool; MainFrame() { @@ -901,6 +903,15 @@ public abstract class MainFrame extends JFrame implements ActionListener { _options = options; } + void setInferenceManager( final InferenceManager i ) { + _inference_manager = i; + } + + 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 655383c..efdc982 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -292,6 +292,7 @@ public final class MainFrameApplication extends MainFrame { // hide until everything is ready setVisible( false ); setOptions( Options.createInstance( _configuration ) ); + setInferenceManager( InferenceManager.createInstance( _configuration ) ); setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) ); _textframe = null; _species_tree = null; @@ -667,14 +668,22 @@ public final class MainFrameApplication extends MainFrame { } void buildPhylogeneticInferenceMenu() { - final InferenceManager inference_manager = InferenceManager.getInstance(); + final InferenceManager im = getInferenceManager(); _inference_menu = MainFrame.createMenu( "Inference", getConfiguration() ); _inference_menu.add( _inference_from_msa_item = new JMenuItem( "From Multiple Sequence Alignment..." ) ); customizeJMenuItem( _inference_from_msa_item ); _inference_from_msa_item.setToolTipText( "Basic phylogenetic inference from MSA" ); - _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) ); - customizeJMenuItem( _inference_from_seqs_item ); - _inference_from_seqs_item.setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" ); + if ( im.canDoMsa() ) { + _inference_menu.add( _inference_from_seqs_item = new JMenuItem( "From Unaligned Sequences..." ) ); + customizeJMenuItem( _inference_from_seqs_item ); + _inference_from_seqs_item + .setToolTipText( "Basic phylogenetic inference including multiple sequence alignment" ); + } + else { + _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 ); + } _jmenubar.add( _inference_menu ); } @@ -1360,7 +1369,7 @@ public final class MainFrameApplication extends MainFrame { private File getCurrentDir() { if ( ( _current_dir == null ) || !_current_dir.canRead() ) { - if ( ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1 ) { + if ( ForesterUtil.isWindowns() ) { try { _current_dir = new File( WindowsUtils.getCurrentUserDesktopPath() ); } diff --git a/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java b/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java index fc679aa..b648038 100644 --- a/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java +++ b/forester/java/src/org/forester/archaeopteryx/tools/InferenceManager.java @@ -1,10 +1,82 @@ package org.forester.archaeopteryx.tools; -public class InferenceManager { +import java.io.File; +import java.io.IOException; - public static InferenceManager getInstance() { - // TODO Auto-generated method stub +import org.forester.archaeopteryx.Configuration; +import org.forester.util.ForesterUtil; + +public final class InferenceManager { + + private final File _path_to_local_mafft; + private final File _path_to_local_kalign; + private final File _path_to_local_fastme; + private final File _path_to_local_raxml; + private final File _path_to_local_clustalo; + + public static InferenceManager createInstance( final Configuration c ) { + return new InferenceManager( c.getpathToLocalMafft(), + c.getPathToLocalKalign(), + c.getPathToLocalFastme(), + c.getPathToLocalRaxml(), + c.getPathToLocalClustalOmega() ); + } + + public boolean canDoMsa() { + return ( getPathToLocalMafft() != null ) || ( getPathToLocalKalign() != null ) + || ( getPathToLocalClustalo() != null ); + } + + public File getPathToLocalMafft() { + return _path_to_local_mafft; + } + + public File getPathToLocalKalign() { + return _path_to_local_kalign; + } + + public File getPathToLocalFastme() { + return _path_to_local_fastme; + } + + public File getPathToLocalRaxml() { + return _path_to_local_raxml; + } + + public File getPathToLocalClustalo() { + return _path_to_local_clustalo; + } + + private final static File createLocalPath( final File path ) { + if ( path == null ) { + return null; + } + try { + if ( path.getCanonicalFile().canExecute() && !path.getCanonicalFile().isDirectory() ) { + return new File( path.getCanonicalFile().toString() ); + } + } + catch ( final IOException e ) { + return null; + } return null; } + + private InferenceManager( final File path_to_local_mafft, + final File path_to_local_kalign, + final File path_to_local_fastme, + final File path_to_local_raxml, + final File path_to_local_clustalo ) { + _path_to_local_mafft = createLocalPath( path_to_local_mafft ) != null ? createLocalPath( path_to_local_mafft ) + : createLocalPath( new File( "mafft" ) ); + _path_to_local_kalign = createLocalPath( path_to_local_kalign ) != null ? createLocalPath( path_to_local_kalign ) + : createLocalPath( new File( "kalign" ) ); + _path_to_local_fastme = createLocalPath( path_to_local_fastme ) != null ? createLocalPath( path_to_local_fastme ) + : createLocalPath( new File( "fastme" ) ); + _path_to_local_raxml = createLocalPath( path_to_local_raxml ) != null ? createLocalPath( path_to_local_raxml ) + : createLocalPath( new File( "raxml" ) ); + _path_to_local_clustalo = createLocalPath( path_to_local_clustalo ) != null ? createLocalPath( path_to_local_clustalo ) + : createLocalPath( new File( ForesterUtil.isWindowns() ? "clustalo.exe" : "clustalo" ) ); + } } diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index c344a0d..7b9fefa 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -96,6 +96,10 @@ public final class ForesterUtil { } } + 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 + ")"; } -- 1.7.10.2