From bc282cbd857f4fb9decdc00b278640bcf146a645 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Mon, 10 Dec 2012 19:00:52 +0000 Subject: [PATCH] work on data buffer for aLeaves MAFFT suite + clean up --- .../org/forester/archaeopteryx/Configuration.java | 5 +- .../src/org/forester/archaeopteryx/MainFrame.java | 38 ++++++++-- .../archaeopteryx/MainFrameApplication.java | 16 ++-- .../src/org/forester/archaeopteryx/TreePanel.java | 78 ++++++++++++++------ forester/java/src/org/forester/rio/RIO.java | 2 +- forester/java/src/org/forester/sdi/GSDI.java | 9 +-- forester/java/src/org/forester/sdi/GSDIR.java | 11 +-- .../forester/util/BasicDescriptiveStatistics.java | 2 - 8 files changed, 104 insertions(+), 57 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index 03af1c1..deaaec8 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -57,7 +57,7 @@ import org.forester.util.ForesterUtil; public final class Configuration { public enum EXT_NODE_DATA_RETURN_ON { - CONSOLE, WINODW; + CONSOLE, WINODW, BUFFER_ONLY; } static final String VALIDATE_AGAINST_PHYLOXML_XSD_SCHEMA = "validate_against_phyloxml_xsd_schema"; private static final String WEB_LINK_KEY = "web_link"; @@ -1356,6 +1356,9 @@ public final class Configuration { else if ( s.equals( "window" ) ) { setExtNodeDataReturnOn( EXT_NODE_DATA_RETURN_ON.WINODW ); } + else if ( s.equals( "buffer_only" ) ) { + setExtNodeDataReturnOn( EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ); + } else { ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + s + "] for [ext_descendents_data_to_return_on]" ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index e9c0405..12710c0 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -231,6 +231,7 @@ public abstract class MainFrame extends JFrame implements ActionListener { InferenceManager _inference_manager; final ProcessPool _process_pool; private String _previous_node_annotation_ref; + private String _ext_node_data_buffer = ""; MainFrame() { _process_pool = ProcessPool.createInstance(); @@ -489,6 +490,18 @@ public abstract class MainFrame extends JFrame implements ActionListener { return _configuration; } + /** + * This method returns the current external node data which + * has been selected by the user by clicking the "Return ..." + * menu item. This method is expected to be called from Javascript or + * something like it. + * + * @return current external node data as String + */ + public String getCurrentExternalNodesDataBuffer() { + return _ext_node_data_buffer; + } + public InferenceManager getInferenceManager() { return _inference_manager; } @@ -944,6 +957,15 @@ public abstract class MainFrame extends JFrame implements ActionListener { _configuration = configuration; } + void setCurrentExternalNodesDataBuffer( final String s ) { + if ( !ForesterUtil.isEmpty( s ) ) { + _ext_node_data_buffer = s.trim(); + } + else { + _ext_node_data_buffer = ""; + } + } + void setInferenceManager( final InferenceManager i ) { _inference_manager = i; } @@ -1266,14 +1288,6 @@ public abstract class MainFrame extends JFrame implements ActionListener { } } - private String getPreviousNodeAnnotationReference() { - return _previous_node_annotation_ref; - } - - private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) { - _previous_node_annotation_ref = previous_node_annotation_ref; - } - private void chooseFont() { final FontChooser fc = new FontChooser(); fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() ); @@ -1338,12 +1352,20 @@ public abstract class MainFrame extends JFrame implements ActionListener { repaint(); } + private String getPreviousNodeAnnotationReference() { + return _previous_node_annotation_ref; + } + private void removeBranchColors() { if ( getMainPanel().getCurrentPhylogeny() != null ) { AptxUtil.removeBranchColors( getMainPanel().getCurrentPhylogeny() ); } } + private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) { + _previous_node_annotation_ref = previous_node_annotation_ref; + } + /** * Display the about box. */ diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 0ff8a49..77f0364 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -663,7 +663,6 @@ public final class MainFrameApplication extends MainFrame { _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 (re-rooting)" ) ); - _analysis_menu.addSeparator(); _analysis_menu.add( _root_min_dups_item = new JMenuItem( "Root by Minimizing Duplications | Height (SDI)" ) ); _analysis_menu.add( _root_min_cost_l_item = new JMenuItem( "Root by Minimizing Cost L | Height (SDI)" ) ); @@ -1242,7 +1241,7 @@ public final class MainFrameApplication extends MainFrame { } catch ( final Exception e ) { JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDI", JOptionPane.ERROR_MESSAGE ); - return; + return; } gene_tree.setRerootable( false ); _mainpanel.getCurrentTreePanel().setTree( gene_tree ); @@ -1267,13 +1266,12 @@ public final class MainFrameApplication extends MainFrame { if ( !isOKforSDI( false, true ) ) { return; } - final Phylogeny gene_tree = _mainpanel.getCurrentPhylogeny().copy(); gene_tree.setAllNodesToNotCollapse(); gene_tree.recalculateNumberOfExternalDescendants( false ); GSDIR gsdir = null; try { - gsdir = new GSDIR( gene_tree, _species_tree.copy(), true, 1 ); + gsdir = new GSDIR( gene_tree, _species_tree.copy(), true, 1 ); } catch ( final Exception e ) { JOptionPane.showMessageDialog( this, e.toString(), "Error during GSDIR", JOptionPane.ERROR_MESSAGE ); @@ -1283,13 +1281,9 @@ public final class MainFrameApplication extends MainFrame { result_gene_tree.setRerootable( false ); result_gene_tree.clearHashIdToNodeMap(); result_gene_tree.recalculateNumberOfExternalDescendants( true ); - - - _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree" , null ); - + _mainpanel.addPhylogenyInNewTab( result_gene_tree, getConfiguration(), "gene tree", null ); //_mainpanel.getCurrentTreePanel().setTree( gene_tree ); - - // _mainpanel.getCurrentTreePanel().setEdited( true ); + // _mainpanel.getCurrentTreePanel().setEdited( true ); getControlPanel().setShowEvents( true ); showWhole(); final int selected = _mainpanel.getTabbedPane().getSelectedIndex(); @@ -1302,7 +1296,7 @@ public final class MainFrameApplication extends MainFrame { + "Potential duplications: " + gsdir.getSpeciationOrDuplicationEventsSum() + "\n" + "Speciations: " + gsdir.getSpeciationsSum(), "GSDI successfully completed", JOptionPane.INFORMATION_MESSAGE ); } - + void executeFunctionAnalysis() { if ( ( _mainpanel.getCurrentPhylogeny() == null ) || ( _mainpanel.getCurrentPhylogeny().isEmpty() ) ) { return; diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index 907a20f..fcb1580 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -2339,6 +2339,22 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee repaint(); } + private String createAnnotationString( final SortedSet ann ) { + final StringBuilder sb = new StringBuilder(); + boolean first = true; + for( final Annotation a : ann ) { + if ( !first ) { + sb.append( "|" ); + } + else { + first = false; + } + sb.append( a.asSimpleText() ); + } + final String ann_str = sb.toString(); + return ann_str; + } + final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) { final String tax = PhylogenyMethods.getSpecies( node ); String label = node.getName(); @@ -4035,22 +4051,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } - private String createAnnotationString( final SortedSet ann ) { - final StringBuilder sb = new StringBuilder(); - boolean first = true; - for( final Annotation a : ann ) { - if ( !first ) { - sb.append( "|" ); - } - else { - first = false; - } - sb.append( a.asSimpleText() ); - } - final String ann_str = sb.toString(); - return ann_str; - } - final private void paintNodeDataUnrootedCirc( final Graphics2D g, final PhylogenyNode node, final boolean to_pdf, @@ -4991,10 +4991,37 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee + getOptions().getExtDescNodeDataToReturn() ); } } // for loop - if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) { + if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) + || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) { + final StringBuilder sb = new StringBuilder(); for( final String d : data ) { if ( !ForesterUtil.isEmpty( d ) ) { - System.out.println( d ); + if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) { + System.out.println( d ); + } + sb.append( d ); + sb.append( ForesterUtil.LINE_SEPARATOR ); + } + } + if ( sb.length() < 1 ) { + if ( getMainPanel().getMainFrame() == null ) { + // Must be "E" applet version. + ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() ) + .setCurrentExternalNodesDataBuffer( "" ); + } + else { + getMainPanel().getMainFrame().setCurrentExternalNodesDataBuffer( "" ); + } + } + else { + final String s = sb.toString().trim(); + if ( getMainPanel().getMainFrame() == null ) { + // Must be "E" applet version. + ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() ) + .setCurrentExternalNodesDataBuffer( s ); + } + else { + getMainPanel().getMainFrame().setCurrentExternalNodesDataBuffer( s ); } } } @@ -5003,28 +5030,37 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee for( final String d : data ) { if ( !ForesterUtil.isEmpty( d ) ) { sb.append( d ); - sb.append( "\n" ); + sb.append( ForesterUtil.LINE_SEPARATOR ); } } if ( sb.length() < 1 ) { AptxUtil.showInformationMessage( this, "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")", "Descendants of selected node do not contain selected data" ); + if ( getMainPanel().getMainFrame() == null ) { + // Must be "E" applet version. + ( ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet() ) + .setCurrentExternalNodesDataBuffer( "" ); + } + else { + getMainPanel().getMainFrame().setCurrentExternalNodesDataBuffer( "" ); + } } else { final String title = "External Descendants " + ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data" : obtainTitleForExtDescNodeData() ) + " (" + data.size() + "/" + node.getNumberOfExternalNodes() + ") For Node " + node; + final String s = sb.toString().trim(); if ( getMainPanel().getMainFrame() == null ) { // Must be "E" applet version. final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet(); - final String s = sb.toString().trim(); ae.showTextFrame( s, title ); ae.setCurrentExternalNodesDataBuffer( s ); } else { - getMainPanel().getMainFrame().showTextFrame( sb.toString(), title ); + getMainPanel().getMainFrame().showTextFrame( s, title ); + getMainPanel().getMainFrame().setCurrentExternalNodesDataBuffer( s ); } } } diff --git a/forester/java/src/org/forester/rio/RIO.java b/forester/java/src/org/forester/rio/RIO.java index c2cea38..5a9be41 100644 --- a/forester/java/src/org/forester/rio/RIO.java +++ b/forester/java/src/org/forester/rio/RIO.java @@ -395,7 +395,7 @@ public final class RIO { } final Phylogeny[] gene_trees = factory.create( gene_trees_file, p ); // Removes from species_tree all species not found in gene_tree. - List _removed_gene_tree_nodes = PhylogenyMethods + final List _removed_gene_tree_nodes = PhylogenyMethods .taxonomyBasedDeletionOfExternalNodes( gene_trees[ 0 ], species_tree ); if ( species_tree.isEmpty() ) { throw new RIOException( "failed to establish species based mapping between gene and species trees" ); diff --git a/forester/java/src/org/forester/sdi/GSDI.java b/forester/java/src/org/forester/sdi/GSDI.java index 71f4e45..bfdd14f 100644 --- a/forester/java/src/org/forester/sdi/GSDI.java +++ b/forester/java/src/org/forester/sdi/GSDI.java @@ -69,8 +69,8 @@ public class GSDI extends SDI { private final boolean _most_parsimonious_duplication_model; private final boolean _strip_gene_tree; private final boolean _strip_species_tree; - protected int _speciation_or_duplication_events_sum; - protected int _speciations_sum; + protected int _speciation_or_duplication_events_sum; + protected int _speciations_sum; private final List _stripped_gene_tree_nodes; private final List _stripped_species_tree_nodes; private final Set _mapped_species_tree_nodes; @@ -102,13 +102,13 @@ public class GSDI extends SDI { throws SDIException { this( gene_tree, species_tree, most_parsimonious_duplication_model, false, false ); } - + public GSDI( final Phylogeny gene_tree, final Phylogeny species_tree, final boolean most_parsimonious_duplication_model, final boolean strip_gene_tree, final boolean strip_species_tree, - int x ) throws SDIException { + final int x ) throws SDIException { super( gene_tree, species_tree ); _speciation_or_duplication_events_sum = 0; _speciations_sum = 0; @@ -120,7 +120,6 @@ public class GSDI extends SDI { _stripped_species_tree_nodes = new ArrayList(); _mapped_species_tree_nodes = new HashSet(); _scientific_names_mapped_to_reduced_specificity = new TreeSet(); - } // s is the node on the species tree g maps to. diff --git a/forester/java/src/org/forester/sdi/GSDIR.java b/forester/java/src/org/forester/sdi/GSDIR.java index 34efda2..dc3fcae 100644 --- a/forester/java/src/org/forester/sdi/GSDIR.java +++ b/forester/java/src/org/forester/sdi/GSDIR.java @@ -54,7 +54,6 @@ public class GSDIR extends GSDI { _duplications_sum = 0; _speciation_or_duplication_events_sum = 0; _speciations_sum = 0; - _gene_tree.reRoot( root.getId() ); //TODO reRoot( root ) PhylogenyMethods.preOrderReId( getSpeciesTree() ); //TEST, remove later @@ -65,23 +64,19 @@ public class GSDIR extends GSDI { } } geneTreePostOrderTraversal(); - - if ( _duplications_sum < _min_duplications_sum ) { + if ( _duplications_sum < _min_duplications_sum ) { _min_duplications_sum = _duplications_sum; _min_duplications_sum_gene_trees.clear(); _min_duplications_sum_gene_trees.add( getGeneTree().copy() ); } - else if ( _duplications_sum == _min_duplications_sum ) { + else if ( _duplications_sum == _min_duplications_sum ) { _min_duplications_sum_gene_trees.add( getGeneTree().copy() ); } System.out.println( getDuplicationsSum() ); - _duplications_sum_stats.addValue( _duplications_sum ); + _duplications_sum_stats.addValue( _duplications_sum ); } } - - - public int getMinDuplicationsSum() { return _min_duplications_sum; } diff --git a/forester/java/src/org/forester/util/BasicDescriptiveStatistics.java b/forester/java/src/org/forester/util/BasicDescriptiveStatistics.java index 538f6a1..0818951 100644 --- a/forester/java/src/org/forester/util/BasicDescriptiveStatistics.java +++ b/forester/java/src/org/forester/util/BasicDescriptiveStatistics.java @@ -146,7 +146,6 @@ public class BasicDescriptiveStatistics implements DescriptiveStatistics { return _sum; } - @Override public String getSummaryAsString() { validate(); @@ -155,7 +154,6 @@ public class BasicDescriptiveStatistics implements DescriptiveStatistics { return "" + mean + ( ( char ) 177 ) + sd + " [" + getMin() + "..." + getMax() + "]"; } - @Override public double getValue( final int index ) { validate(); -- 1.7.10.2