From 733f051a048f64b6850314a08880f1f77a633db8 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Tue, 12 Mar 2013 01:50:34 +0000 Subject: [PATCH] work on: add ability to perform GSDI in applets --- .../src/org/forester/archaeopteryx/AptxUtil.java | 10 ++- .../org/forester/archaeopteryx/ArchaeopteryxA.java | 36 ++------ .../org/forester/archaeopteryx/ArchaeopteryxE.java | 11 ++- .../org/forester/archaeopteryx/Configuration.java | 16 +++- .../src/org/forester/archaeopteryx/Constants.java | 4 +- .../src/org/forester/archaeopteryx/MainFrame.java | 18 ++-- .../forester/archaeopteryx/MainFrameApplet.java | 89 ++++++++++---------- .../archaeopteryx/MainFrameApplication.java | 2 +- 8 files changed, 95 insertions(+), 91 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java index bc7a693..a615cb9 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java @@ -1027,8 +1027,9 @@ public final class AptxUtil { final boolean phyloxml_validate_against_xsd, final boolean replace_underscores, final boolean internal_numbers_are_confidences, - final TAXONOMY_EXTRACTION taxonomy_extraction ) - throws FileNotFoundException, IOException { + final TAXONOMY_EXTRACTION taxonomy_extraction, + final boolean midpoint_reroot ) throws FileNotFoundException, + IOException { final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance(); final PhylogenyParser parser; boolean nhx_or_nexus = false; @@ -1057,6 +1058,11 @@ public final class AptxUtil { PhylogenyMethods.transferInternalNodeNamesToConfidence( phy ); } } + if ( midpoint_reroot ) { + for( final Phylogeny phy : phys ) { + PhylogenyMethods.midpointRoot( phy ); + } + } return phys; } diff --git a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxA.java b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxA.java index c508eda..a471f2f 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxA.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxA.java @@ -35,7 +35,6 @@ 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; @@ -97,7 +96,7 @@ public class ArchaeopteryxA extends JApplet { 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() + "\"" ); + AptxUtil.printAppletMessage( NAME, "URL of tree(s) to load: " + getTreeUrlStr() ); } else { ForesterUtil.printErrorMessage( NAME, "no URL for tree(s) to load!" ); @@ -108,7 +107,7 @@ public class ArchaeopteryxA extends JApplet { repaint(); } if ( !ForesterUtil.isEmpty( getSpeciesTreeUrlStr() ) ) { - AptxUtil.printAppletMessage( NAME, "URL of species tree to load: \"" + getSpeciesTreeUrlStr() + "\"" ); + AptxUtil.printAppletMessage( NAME, "URL of species tree to load: " + getSpeciesTreeUrlStr() ); } setBackground( background_color ); setForeground( font_color ); @@ -136,40 +135,19 @@ public class ArchaeopteryxA extends JApplet { UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() ); } setVisible( false ); - _mainframe_applet = new MainFrameApplet( this, configuration ); + _mainframe_applet = new MainFrameApplet( this, configuration, getSpeciesTreeUrlStr() ); final URL tree_url = new URL( getTreeUrlStr() ); final Phylogeny[] phys = AptxUtil.readPhylogeniesFromUrl( tree_url, configuration .isValidatePhyloXmlAgainstSchema(), configuration.isReplaceUnderscoresInNhParsing(), configuration - .isInternalNumberAreConfidenceForNhParsing(), configuration.getTaxonomyExtraction() ); + .isInternalNumberAreConfidenceForNhParsing(), configuration.getTaxonomyExtraction(), configuration + .isMidpointReroot() ); + AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "loaded " + phys.length + " phylogenies from: " + + tree_url ); AptxUtil.addPhylogeniesToTabs( phys, 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" ); - if ( species_trees[ 0 ].isEmpty() ) { - ForesterUtil.printErrorMessage( NAME, "species tree is empty" ); - } - else if ( !species_trees[ 0 ].isRooted() ) { - ForesterUtil.printErrorMessage( NAME, "species tree is not rooted" ); - } - else { - getMainFrameApplet().setSpeciesTree( species_trees[ 0 ] ); - } - } - else { - ForesterUtil.printErrorMessage( NAME, "failed to read species tree from " + getSpeciesTreeUrlStr() ); - } - } getMainFrameApplet().getMainPanel().getControlPanel().showWholeAll(); getMainFrameApplet().getMainPanel().getControlPanel().showWhole(); setVisible( true ); diff --git a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java index c33a34a..eaf7536 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java @@ -461,7 +461,8 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { getConfiguration().isValidatePhyloXmlAgainstSchema(), getConfiguration().isReplaceUnderscoresInNhParsing(), getConfiguration().isInternalNumberAreConfidenceForNhParsing(), - getConfiguration().getTaxonomyExtraction() ); + getConfiguration().getTaxonomyExtraction(), + getConfiguration().isMidpointReroot() ); } catch ( final Exception e ) { ForesterUtil.printErrorMessage( NAME, e.toString() ); @@ -494,7 +495,8 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { configuration.isValidatePhyloXmlAgainstSchema(), configuration.isReplaceUnderscoresInNhParsing(), false, - TAXONOMY_EXTRACTION.NO ); + TAXONOMY_EXTRACTION.NO, + false ); } catch ( final IOException e ) { ForesterUtil.printErrorMessage( NAME, "could not read species tree from [" + species_tree_url_str @@ -512,6 +514,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { } else { setSpeciesTree( species_trees[ 0 ] ); + AptxUtil.printAppletMessage( NAME, "species tree OK" ); } } } @@ -563,6 +566,10 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { } else { AptxUtil.printAppletMessage( NAME, "not using tabbed display" ); + if ( getSpeciesTree() != null ) { + AptxUtil.printAppletMessage( NAME, + "Warning: gsdi (gene duplication inference) only available tabbed display" ); + } AptxUtil.addPhylogenyToPanel( phys, getConfiguration(), getMainPanel() ); } validate(); diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index c578e05..8cb5414 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -217,6 +217,7 @@ public final class Configuration { private EXT_NODE_DATA_RETURN_ON _ext_node_data_return_on = EXT_NODE_DATA_RETURN_ON.WINODW; private int _frame_x_size; private int _frame_y_size; + private boolean _midpoint_root = false; private static String DEFAULT_FONT_FAMILY = ""; static { for( final String font_name : Constants.DEFAULT_FONT_CHOICES ) { @@ -869,10 +870,6 @@ public final class Configuration { else if ( name.equals( "color_subtree" ) ) { index = Configuration.color_subtree; } - else if ( name.equals( "go_to_swiss_prot" ) ) { - ForesterUtil.printWarningMessage( Constants.PRG_NAME, "configuration key [go_to_swiss_prot] is deprecated" ); - return DEPRECATED; - } return index; } @@ -1409,6 +1406,9 @@ public final class Configuration { else if ( key.equals( "taxonomy_colorize_node_shapes" ) ) { setTaxonomyColorizeNodeShapes( parseBoolean( ( String ) st.nextElement() ) ); } + else if ( key.equals( "midpoint_reroot" ) ) { + setMidpointReroot( parseBoolean( ( String ) st.nextElement() ) ); + } else if ( key.equals( "ext_descendents_data_to_return" ) ) { final String s = ( ( String ) st.nextElement() ).trim(); if ( s.equalsIgnoreCase( "node_name" ) ) { @@ -1706,4 +1706,12 @@ public final class Configuration { static enum TRIPLET { TRUE, FALSE, UNKNOWN } + + public boolean isMidpointReroot() { + return _midpoint_root; + } + + public void setMidpointReroot( final boolean midpoint_root ) { + _midpoint_root = midpoint_root; + } } diff --git a/forester/java/src/org/forester/archaeopteryx/Constants.java b/forester/java/src/org/forester/archaeopteryx/Constants.java index e539c54..4530066 100644 --- a/forester/java/src/org/forester/archaeopteryx/Constants.java +++ b/forester/java/src/org/forester/archaeopteryx/Constants.java @@ -42,8 +42,8 @@ public final class Constants { public final static boolean __SYNTH_LF = false; // TODO remove me public final static boolean ALLOW_DDBJ_BLAST = false; public final static String PRG_NAME = "Archaeopteryx"; - final static String VERSION = "0.9806 A1ST"; - final static String PRG_DATE = "130308"; + final static String VERSION = "0.9807 A1ST"; + final static String PRG_DATE = "130311"; final static String DEFAULT_CONFIGURATION_FILE_NAME = "_aptx_configuration_file"; final static String[] DEFAULT_FONT_CHOICES = { "Verdana", "Tahoma", "Arial", "Helvetica", "Dialog", "Lucida Sans", "SansSerif", "Sans-serif", "Sans" }; diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 8689bd4..3c319d3 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -239,7 +239,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { Configuration _configuration; JMenuItem _remove_branch_color_item; Options _options; - Phylogeny _species_tree; + private Phylogeny _species_tree; InferenceManager _inference_manager; final ProcessPool _process_pool; private String _previous_node_annotation_ref; @@ -797,7 +797,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { gene_tree.setAllNodesToNotCollapse(); gene_tree.recalculateNumberOfExternalDescendants( false ); GSDI gsdi = null; - final Phylogeny species_tree = _species_tree.copy(); + final Phylogeny species_tree = getSpeciesTree().copy(); try { gsdi = new GSDI( gene_tree, species_tree, false, true, true ); } @@ -870,7 +870,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { gene_tree.setAllNodesToNotCollapse(); gene_tree.recalculateNumberOfExternalDescendants( false ); GSDIR gsdir = null; - final Phylogeny species_tree = _species_tree.copy(); + final Phylogeny species_tree = getSpeciesTree().copy(); try { gsdir = new GSDIR( gene_tree, species_tree, true, true ); } @@ -959,6 +959,10 @@ public abstract class MainFrame extends JFrame implements ActionListener { return _jmenubar; } + final Phylogeny getSpeciesTree() { + return _species_tree; + } + void help() { final StringBuilder sb = new StringBuilder(); sb.append( "Display options\n" ); @@ -1083,14 +1087,14 @@ public abstract class MainFrame extends JFrame implements ActionListener { if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) { return false; } - else if ( ( _species_tree == null ) || _species_tree.isEmpty() ) { + else if ( ( getSpeciesTree() == null ) || getSpeciesTree().isEmpty() ) { JOptionPane.showMessageDialog( this, "No species tree loaded", "Cannot execute GSDI", JOptionPane.ERROR_MESSAGE ); return false; } - else if ( species_tree_has_to_binary && !_species_tree.isCompletelyBinary() ) { + else if ( species_tree_has_to_binary && !getSpeciesTree().isCompletelyBinary() ) { JOptionPane.showMessageDialog( this, "Species tree is not completely binary", "Cannot execute GSDI", @@ -1189,6 +1193,10 @@ public abstract class MainFrame extends JFrame implements ActionListener { } } + final void setSpeciesTree( final Phylogeny species_tree ) { + _species_tree = species_tree; + } + void setTypeMenuToAllUnselected() { _convex_type_cbmi.setSelected( false ); _curved_type_cbmi.setSelected( false ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java index b6f99ea..11bbba5 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java @@ -33,6 +33,9 @@ import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; import javax.swing.ButtonGroup; @@ -40,13 +43,13 @@ import javax.swing.JApplet; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenuBar; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; import javax.swing.JRadioButtonMenuItem; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION; +import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; import org.forester.phylogeny.Phylogeny; import org.forester.util.ForesterUtil; @@ -58,62 +61,30 @@ public final class MainFrameApplet extends MainFrame { private final ArchaeopteryxA _applet; private ButtonGroup _radio_group_1; - MainFrameApplet( final ArchaeopteryxA parent_applet, final Configuration configuration ) { + MainFrameApplet( final ArchaeopteryxA parent_applet, + final Configuration configuration, + final String species_tree_url_str ) { setTitle( ArchaeopteryxA.NAME ); _applet = parent_applet; setConfiguration( configuration ); setOptions( Options.createInstance( configuration ) ); - //_textframes = null; //~~~~ - URL url = null; - Phylogeny[] phys = null; - // Get URL to tree file - if ( _applet.getTreeUrlStr() != null ) { - try { - 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.getTreeUrlStr() + "\"\nError: " + e, - "Failed to create URL", - JOptionPane.ERROR_MESSAGE ); - close(); - } - } - // Load the tree from URL - if ( url != null ) { + _mainpanel = new MainPanelApplets( _configuration, this ); + if ( !ForesterUtil.isEmpty( species_tree_url_str ) ) { try { - phys = AptxUtil.readPhylogeniesFromUrl( url, - configuration.isValidatePhyloXmlAgainstSchema(), - configuration.isReplaceUnderscoresInNhParsing(), - configuration.isInternalNumberAreConfidenceForNhParsing(), - configuration.getTaxonomyExtraction() ); + readSpeciesTree( configuration, species_tree_url_str ); } catch ( final Exception e ) { + ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "failed to read species tree from " + + species_tree_url_str ); ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, e.toString() ); - e.printStackTrace(); - JOptionPane.showMessageDialog( this, ArchaeopteryxA.NAME + ": Failed to read phylogenies: " - + "\nError: " + e, "Failed to read phylogenies", JOptionPane.ERROR_MESSAGE ); - close(); } } - if ( ( phys == null ) || ( phys.length < 1 ) ) { - ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "phylogenies from [" + url + "] are null or empty" ); - JOptionPane.showMessageDialog( this, ArchaeopteryxA.NAME + ": phylogenies from [" + url - + "] are null or empty", "Failed to read phylogenies", JOptionPane.ERROR_MESSAGE ); - } - else { - AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "loaded " + phys.length + " phylogenies from: " + url ); - } - _mainpanel = new MainPanelApplets( _configuration, this ); // build the menu bar _jmenubar = new JMenuBar(); if ( !_configuration.isUseNativeUI() ) { _jmenubar.setBackground( _configuration.getGuiMenuBackgroundColor() ); } - if ( _species_tree != null ) { + if ( getSpeciesTree() != null ) { buildAnalysisMenu(); } buildToolsMenu(); @@ -155,6 +126,36 @@ public final class MainFrameApplet extends MainFrame { System.gc(); } + private void readSpeciesTree( final Configuration configuration, final String species_tree_url_str ) + throws MalformedURLException, FileNotFoundException, IOException { + final URL species_tree_url = new URL( species_tree_url_str ); + final Phylogeny[] species_trees = AptxUtil.readPhylogeniesFromUrl( species_tree_url, + configuration + .isValidatePhyloXmlAgainstSchema(), + configuration + .isReplaceUnderscoresInNhParsing(), + false, + TAXONOMY_EXTRACTION.NO, + false ); + if ( ( species_trees != null ) && ( species_trees.length > 0 ) ) { + AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "successfully read species tree" ); + if ( species_trees[ 0 ].isEmpty() ) { + ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "species tree is empty" ); + } + else if ( !species_trees[ 0 ].isRooted() ) { + ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "species tree is not rooted" ); + } + else { + setSpeciesTree( species_trees[ 0 ] ); + AptxUtil.printAppletMessage( ArchaeopteryxA.NAME, "species tree OK" ); + } + } + else { + ForesterUtil.printErrorMessage( ArchaeopteryxA.NAME, "failed to read species tree from " + + species_tree_url_str ); + } + } + @Override public MainPanel getMainPanel() { return _mainpanel; @@ -303,8 +304,4 @@ public final class MainFrameApplet extends MainFrame { void readPhylogeniesFromURL() { throw new NoSuchMethodError( "not implemented" ); } - - void setSpeciesTree( final Phylogeny species_tree ) { - _species_tree = species_tree; - } } diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 822c4d4..f414cd7 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -2300,7 +2300,7 @@ public final class MainFrameApplication extends MainFrame { } } if ( !exception && ( t != null ) ) { - _species_tree = t; + setSpeciesTree( t ); JOptionPane.showMessageDialog( this, "Species tree successfully loaded", "Species tree loaded", -- 1.7.10.2