work on: add ability to perform GSDI in applets
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Wed, 27 Feb 2013 00:09:07 +0000 (00:09 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Wed, 27 Feb 2013 00:09:07 +0000 (00:09 +0000)
forester/java/src/org/forester/archaeopteryx/ArchaeopteryxA.java
forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java
forester/java/src/org/forester/archaeopteryx/Constants.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java

index b209dbc..b1cd27c 100644 (file)
@@ -35,22 +35,24 @@ import java.net.URL;
 import javax.swing.JApplet;
 import javax.swing.UIManager;
 
+import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.util.ForesterUtil;
 
 public class ArchaeopteryxA extends JApplet {
 
-    private static final long  serialVersionUID    = 2314899014580484146L;
-    private final static Color background_color    = new Color( 0, 0, 0 );
-    private final static Color font_color          = new Color( 0, 255, 0 );
-    private final static Color ex_background_color = new Color( 0, 0, 0 );
-    private final static Color ex_font_color       = new Color( 255, 0, 0 );
-    private final static Font  font                = new Font( Configuration.getDefaultFontFamilyName(), Font.BOLD, 9 );
+    private static final long  serialVersionUID      = 2314899014580484146L;
+    private final static Color background_color      = new Color( 0, 0, 0 );
+    private final static Color font_color            = new Color( 0, 255, 0 );
+    private final static Color ex_background_color   = new Color( 0, 0, 0 );
+    private final static Color ex_font_color         = new Color( 255, 0, 0 );
+    private final static Font  font                  = new Font( Configuration.getDefaultFontFamilyName(), Font.BOLD, 9 );
     private MainFrameApplet    _mainframe_applet;
-    private String             _url_string         = "";
-    private String             _message_1          = "";
-    private String             _message_2          = "";
-    public final static String NAME                = "ArchaeopteryxA";
+    private String             _tree_url_str         = "";
+    private String             _species_tree_url_str = "";
+    private String             _message_1            = "";
+    private String             _message_2            = "";
+    public final static String NAME                  = "ArchaeopteryxA";
 
     @Override
     public void destroy() {
@@ -80,16 +82,34 @@ public class ArchaeopteryxA extends JApplet {
         return getMainFrameApplet().getCurrentTreePanel().getCurrentExternalNodesDataBufferAsString().length();
     }
 
-    public String getUrlString() {
-        return _url_string;
+    public String getTreeUrlStr() {
+        return _tree_url_str;
+    }
+
+    public String getSpeciesTreeUrlStr() {
+        return _species_tree_url_str;
     }
 
     @Override
     public void init() {
         boolean has_exception = false;
         setName( NAME );
-        setUrlString( getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD ) );
-        AptxUtil.printAppletMessage( NAME, "URL of phylogenies to load: \"" + getUrlString() + "\"" );
+        setTreeUrlStr( getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD ) );
+        setSpeciesTreeUrlStr( getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD ) );
+        if ( !ForesterUtil.isEmpty( getTreeUrlStr() ) ) {
+            AptxUtil.printAppletMessage( NAME, "URL of tree(s) to load: \"" + getTreeUrlStr() + "\"" );
+        }
+        else {
+            ForesterUtil.printErrorMessage( NAME, "no URL for tree(s) to load!" );
+            setBackground( ex_background_color );
+            setForeground( ex_font_color );
+            has_exception = true;
+            setMessage1( "no URL for tree(s) to load" );
+            repaint();
+        }
+        if ( !ForesterUtil.isEmpty( getSpeciesTreeUrlStr() ) ) {
+            AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + getSpeciesTreeUrlStr() + "\"" );
+        }
         setBackground( background_color );
         setForeground( font_color );
         setFont( font );
@@ -117,16 +137,28 @@ public class ArchaeopteryxA extends JApplet {
             }
             setVisible( false );
             _mainframe_applet = new MainFrameApplet( this, configuration );
-            URL url = null;
-            url = new URL( getUrlString() );
-            final Phylogeny[] phys = AptxUtil.readPhylogeniesFromUrl( url, configuration
+            final URL tree_url = new URL( getTreeUrlStr() );
+            final Phylogeny[] phys = AptxUtil.readPhylogeniesFromUrl( tree_url, configuration
                     .isValidatePhyloXmlAgainstSchema(), configuration.isReplaceUnderscoresInNhParsing(), configuration
                     .isInternalNumberAreConfidenceForNhParsing(), configuration.getTaxonomyExtraction() );
             AptxUtil.addPhylogeniesToTabs( phys,
-                                           new File( url.getFile() ).getName(),
-                                           getUrlString(),
+                                           new File( tree_url.getFile() ).getName(),
+                                           getTreeUrlStr(),
                                            getMainFrameApplet().getConfiguration(),
                                            getMainFrameApplet().getMainPanel() );
+            if ( !ForesterUtil.isEmpty( getSpeciesTreeUrlStr() ) ) {
+                final URL species_tree_url = new URL( getSpeciesTreeUrlStr() );
+                final Phylogeny[] species_trees = AptxUtil
+                        .readPhylogeniesFromUrl( species_tree_url,
+                                                 configuration.isValidatePhyloXmlAgainstSchema(),
+                                                 configuration.isReplaceUnderscoresInNhParsing(),
+                                                 false,
+                                                 TAXONOMY_EXTRACTION.NO );
+                if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) {
+                    AptxUtil.printAppletMessage( NAME, "successfully read species tree" );
+                    getMainFrameApplet().setSpeciesTree( species_trees[ 0 ] );
+                }
+            }
             getMainFrameApplet().getMainPanel().getControlPanel().showWholeAll();
             getMainFrameApplet().getMainPanel().getControlPanel().showWhole();
             setVisible( true );
@@ -207,7 +239,11 @@ public class ArchaeopteryxA extends JApplet {
         _message_2 = message_2;
     }
 
-    private void setUrlString( final String url_string ) {
-        _url_string = url_string;
+    private void setTreeUrlStr( final String url_string ) {
+        _tree_url_str = url_string;
+    }
+
+    private void setSpeciesTreeUrlStr( final String url_string ) {
+        _species_tree_url_str = url_string;
     }
 }
index c6a4849..ba52ded 100644 (file)
@@ -422,17 +422,17 @@ public class ArchaeopteryxE extends JApplet implements ActionListener {
         setupUI();
         URL phys_url = null;
         Phylogeny[] phys = null;
-        final String phys_url_string = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
-        AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + phys_url_string );
+        final String tree_url_str = getParameter( Constants.APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD );
+        AptxUtil.printAppletMessage( NAME, "URL for phylogenies is " + tree_url_str );
         // Get URL to tree file
-        if ( phys_url_string != null ) {
+        if ( tree_url_str != null ) {
             try {
-                phys_url = new URL( phys_url_string );
+                phys_url = new URL( tree_url_str );
             }
             catch ( final Exception e ) {
                 ForesterUtil.printErrorMessage( NAME, "error: " + e );
                 e.printStackTrace();
-                JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + phys_url_string
+                JOptionPane.showMessageDialog( this, NAME + ": Could not create URL from: \"" + tree_url_str
                         + "\"\nException: " + e, "Failed to create URL", JOptionPane.ERROR_MESSAGE );
             }
         }
index 55ebfb2..988daf4 100644 (file)
@@ -65,6 +65,7 @@ public final class Constants {
     static final Dimension      NODE_PANEL_SIZE                                               = new Dimension( 500, 600 );
     static final Dimension      NODE_FRAME_SIZE                                               = new Dimension( 520, 640 );
     static final String         APPLET_PARAM_NAME_FOR_URL_OF_TREE_TO_LOAD                     = "url_of_tree_to_load";
+    static final String         APPLET_PARAM_NAME_FOR_URL_OF_SPECIES_TREE_TO_LOAD             = "url_of_species_tree_to_load";
     static final String         APPLET_PARAM_NAME_FOR_CONFIG_FILE_URL                         = "config_file";
     static final String         APPLET_PARAM_NAME_FOR_DEFAULT_QUERY_SEQUENCE                  = "homology_type_analysis_query_sequence";
     static final String         APPLET_PARAM_NAME_FOR_DEFAULT_SEQUENCE_RELATION_TYPE          = "homology_type_analysis_initial_relation_type";
index 8079b12..d4598b1 100644 (file)
@@ -124,6 +124,13 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JMenu                       _font_size_menu;
     JMenu                       _help_jmenu;
     JMenuItem[]                 _load_phylogeny_from_webservice_menu_items;
+    // Analysis menu
+    JMenu                       _analysis_menu;
+    JMenuItem                   _load_species_tree_item;
+    JMenuItem                   _gsdi_item;
+    JMenuItem                   _gsdir_item;
+    JMenuItem                   _lineage_inference;
+    JMenuItem                   _function_analysis;
     // file menu:
     JMenuItem                   _open_item;
     JMenuItem                   _open_url_item;
@@ -229,6 +236,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     Configuration               _configuration;
     JMenuItem                   _remove_branch_color_item;
     Options                     _options;
+    Phylogeny                   _species_tree;
     InferenceManager            _inference_manager;
     final ProcessPool           _process_pool;
     private String              _previous_node_annotation_ref;
index 35cba7b..4a5c932 100644 (file)
@@ -67,16 +67,16 @@ public final class MainFrameApplet extends MainFrame {
         URL url = null;
         Phylogeny[] phys = null;
         // Get URL to tree file
-        if ( _applet.getUrlString() != null ) {
+        if ( _applet.getTreeUrlStr() != null ) {
             try {
-                url = new URL( _applet.getUrlString() );
+                url = new URL( _applet.getTreeUrlStr() );
             }
             catch ( final Exception e ) {
                 ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, e.toString() );
                 e.printStackTrace();
                 JOptionPane.showMessageDialog( this,
                                                ArchaeopteryxA.NAME + ": Could not create URL from: \""
-                                                       + _applet.getUrlString() + "\"\nError: " + e,
+                                                       + _applet.getTreeUrlStr() + "\"\nError: " + e,
                                                "Failed to create URL",
                                                JOptionPane.ERROR_MESSAGE );
                 close();
@@ -113,6 +113,8 @@ public final class MainFrameApplet extends MainFrame {
         if ( !_configuration.isUseNativeUI() ) {
             _jmenubar.setBackground( _configuration.getGuiMenuBackgroundColor() );
         }
+        //TODO if species tree...
+        buildAnalysisMenu();
         buildToolsMenu();
         buildViewMenu();
         buildFontSizeMenu();
@@ -152,6 +154,19 @@ public final class MainFrameApplet extends MainFrame {
         System.gc();
     }
 
+    void buildAnalysisMenu() {
+        _analysis_menu = MainFrame.createMenu( "Analysis", getConfiguration() );
+        _analysis_menu.add( _gsdi_item = new JMenuItem( "GSDI (Generalized Speciation Duplication Inference)" ) );
+        _analysis_menu.add( _gsdir_item = new JMenuItem( "GSDIR (GSDI with re-rooting)" ) );
+        customizeJMenuItem( _gsdi_item );
+        customizeJMenuItem( _gsdir_item );
+        //  _analysis_menu.addSeparator();
+        //  _analysis_menu.add( _lineage_inference = new JMenuItem( INFER_ANCESTOR_TAXONOMIES ) );
+        //  customizeJMenuItem( _lineage_inference );
+        //  _lineage_inference.setToolTipText( "Inference of ancestor taxonomies/lineages" );
+        _jmenubar.add( _analysis_menu );
+    }
+
     void buildOptionsMenu() {
         _options_jmenu = MainFrame.createMenu( MainFrame.OPTIONS_HEADER, getConfiguration() );
         _options_jmenu.addChangeListener( new ChangeListener() {
@@ -287,4 +302,8 @@ public final class MainFrameApplet extends MainFrame {
     void readPhylogeniesFromURL() {
         throw new NoSuchMethodError( "not implemented" );
     }
+
+    void setSpeciesTree( final Phylogeny species_tree ) {
+        _species_tree = species_tree;
+    }
 }
index b8e4a1a..5954fe3 100644 (file)
@@ -151,7 +151,6 @@ public final class MainFrameApplication extends MainFrame {
     private JMenuItem                        _write_to_tif_item;
     private JMenuItem                        _write_to_png_item;
     private JMenuItem                        _write_to_bmp_item;
-    private Phylogeny                        _species_tree;
     private File                             _current_dir;
     private ButtonGroup                      _radio_group_1;
     private ButtonGroup                      _radio_group_2;
@@ -276,7 +275,6 @@ public final class MainFrameApplication extends MainFrame {
         setInferenceManager( InferenceManager.createInstance( _configuration ) );
         setPhylogeneticInferenceOptions( PhylogeneticInferenceOptions.createInstance( _configuration ) );
         //     _textframe = null; #~~~~
-        _species_tree = null;
         // set title
         setTitle( Constants.PRG_NAME + " " + Constants.VERSION + " (" + Constants.PRG_DATE + ")" );
         _mainpanel = new MainPanel( _configuration, this );