in progress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 26 Sep 2014 00:01:45 +0000 (00:01 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 26 Sep 2014 00:01:45 +0000 (00:01 +0000)
forester/java/src/org/forester/archaeopteryx/Configuration.java
forester/java/src/org/forester/archaeopteryx/Constants.java
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java

index 8629845..c4978d9 100644 (file)
@@ -251,8 +251,8 @@ public final class Configuration {
     private Color                           _vector_data_mean_color                                = Color.WHITE;
     private double                          _vector_data_height                                    = 12;
     private int                             _vector_data_width                                     = 120;
-    private boolean                         _line_up_renderable_node_data;
-    private boolean                         _right_align_domains;
+    private boolean                         _line_up_renderable_node_data                          = true;
+    private boolean                         _right_align_domains                                   = false;
     static {
         for( final String font_name : Constants.DEFAULT_FONT_CHOICES ) {
             if ( Arrays.binarySearch( AptxUtil.getAvailableFontFamiliesSorted(), font_name ) >= 0 ) {
index 6ab35c7..b9c91cd 100644 (file)
@@ -43,7 +43,7 @@ public final class Constants {
     public final static boolean ALLOW_DDBJ_BLAST                                              = false;
     public final static String  PRG_NAME                                                      = "Archaeopteryx";
     final static String         VERSION                                                       = "0.9899 beta";
-    final static String         PRG_DATE                                                      = "140923";
+    final static String         PRG_DATE                                                      = "140925";
     final static String         DEFAULT_CONFIGURATION_FILE_NAME                               = "_aptx_configuration_file";
     final static String[]       DEFAULT_FONT_CHOICES                                          = { "Arial", "Helvetica",
             "Verdana", "Tahoma", "Dialog", "Lucida Sans", "SansSerif", "Sans-serif", "Sans"  };
index 2cc0189..2411d9d 100644 (file)
@@ -154,7 +154,6 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JMenuItem                   _confcolor_item;\r
     JMenuItem                   _color_rank_jmi;\r
     JMenuItem                   _collapse_species_specific_subtrees;\r
-    JMenuItem                   _collapse_below_threshold;                                                                                                                                                                                    //TODO implememt me\r
     JMenuItem                   _obtain_detailed_taxonomic_information_jmi;\r
     JMenuItem                   _obtain_detailed_taxonomic_information_deleting_jmi;\r
     JMenuItem                   _obtain_seq_information_jmi;\r
index 3b1c0aa..125471d 100644 (file)
@@ -93,6 +93,7 @@ import org.forester.phylogeny.PhylogenyMethods;
 import org.forester.phylogeny.PhylogenyNode;\r
 import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE;\r
 import org.forester.phylogeny.data.Confidence;\r
+import org.forester.phylogeny.data.PhylogenyDataUtil;\r
 import org.forester.phylogeny.data.Sequence;\r
 import org.forester.phylogeny.data.Taxonomy;\r
 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;\r
@@ -142,11 +143,14 @@ public final class MainFrameApplication extends MainFrame {
     private JMenuItem                        _write_to_tif_item;\r
     private JMenuItem                        _write_to_png_item;\r
     private JMenuItem                        _write_to_bmp_item;\r
+    private JMenuItem                        _collapse_below_threshold;\r
+    private JMenuItem                        _collapse_below_branch_length;\r
     private File                             _current_dir;\r
     private ButtonGroup                      _radio_group_1;\r
     private ButtonGroup                      _radio_group_2;\r
     // Others:\r
     double                                   _min_not_collapse                     = Constants.MIN_NOT_COLLAPSE_DEFAULT;\r
+    double                                   _min_not_collapse_bl                  = 0.001;\r
     // Phylogeny Inference menu\r
     private JMenu                            _inference_menu;\r
     private JMenuItem                        _inference_from_msa_item;\r
@@ -545,6 +549,12 @@ public final class MainFrameApplication extends MainFrame {
                 }\r
                 collapseBelowThreshold();\r
             }\r
+            else if ( o == _collapse_below_branch_length ) {\r
+                if ( isSubtreeDisplayed() ) {\r
+                    return;\r
+                }\r
+                collapseBelowBranchLengthThreshold();\r
+            }\r
             else if ( ( o == _extract_taxonomy_pfam_strict_rbmi ) || ( o == _extract_taxonomy_pfam_relaxed_rbmi )\r
                     || ( o == _extract_taxonomy_agressive_rbmi ) ) {\r
                 if ( _replace_underscores_cbmi != null ) {\r
@@ -1089,11 +1099,19 @@ public final class MainFrameApplication extends MainFrame {
         _tools_menu.addSeparator();\r
         _tools_menu.add( _collapse_species_specific_subtrees = new JMenuItem( "Collapse Species-Specific Subtrees" ) );\r
         customizeJMenuItem( _collapse_species_specific_subtrees );\r
+        _collapse_species_specific_subtrees.setToolTipText( "To (reversibly) collapse species-specific subtrees" );\r
         _tools_menu\r
                 .add( _collapse_below_threshold = new JMenuItem( "Collapse Branches with Confidence Below Threshold into Multifurcations" ) );\r
         customizeJMenuItem( _collapse_below_threshold );\r
         _collapse_below_threshold\r
-                .setToolTipText( "To collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" );\r
+                .setToolTipText( "To (permanently) collapse branches with confidence values below a threshold into multifurcations (in the case of multiple confidences per branch: without at least one confidence value above a threshold)" );\r
+        //\r
+        _tools_menu\r
+                .add( _collapse_below_branch_length = new JMenuItem( "Collapse Branches with Branch Lengths Below Threshold into Multifurcations" ) );\r
+        customizeJMenuItem( _collapse_below_branch_length );\r
+        _collapse_below_branch_length\r
+                .setToolTipText( "To (permanently) collapse branches with branches with branch lengths below a threshold into multifurcations" );\r
+        //\r
         _tools_menu.addSeparator();\r
         _tools_menu\r
                 .add( _extract_tax_code_from_node_names_jmi = new JMenuItem( "Extract Taxonomic Data from Node Names" ) );\r
@@ -1672,7 +1690,65 @@ public final class MainFrameApplication extends MainFrame {
         }\r
     }\r
 \r
-    private void collapse( final Phylogeny phy, final double m ) {\r
+    private void collapseBl( final Phylogeny phy ) {\r
+        final PhylogenyNodeIterator it = phy.iteratorPostorder();\r
+        final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();\r
+        double min_bl = Double.MAX_VALUE;\r
+        boolean bl_present = false;\r
+        while ( it.hasNext() ) {\r
+            final PhylogenyNode n = it.next();\r
+            if ( !n.isExternal() && !n.isRoot() ) {\r
+                final double bl = n.getDistanceToParent();\r
+                if ( bl != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {\r
+                    bl_present = true;\r
+                    if ( bl < getMinNotCollapseBlValue() ) {\r
+                        to_be_removed.add( n );\r
+                    }\r
+                    if ( bl < min_bl ) {\r
+                        min_bl = bl;\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        if ( bl_present ) {\r
+            for( final PhylogenyNode node : to_be_removed ) {\r
+                PhylogenyMethods.removeNode( node, phy );\r
+            }\r
+            if ( to_be_removed.size() > 0 ) {\r
+                phy.externalNodesHaveChanged();\r
+                phy.clearHashIdToNodeMap();\r
+                phy.recalculateNumberOfExternalDescendants( true );\r
+                getCurrentTreePanel().resetNodeIdToDistToLeafMap();\r
+                getCurrentTreePanel().updateSetOfCollapsedExternalNodes();\r
+                getCurrentTreePanel().calculateLongestExtNodeInfo();\r
+                getCurrentTreePanel().setNodeInPreorderToNull();\r
+                getCurrentTreePanel().recalculateMaxDistanceToRoot();\r
+                getCurrentTreePanel().resetPreferredSize();\r
+                getCurrentTreePanel().setEdited( true );\r
+                getCurrentTreePanel().repaint();\r
+                repaint();\r
+            }\r
+            if ( to_be_removed.size() > 0 ) {\r
+                JOptionPane.showMessageDialog( this, "Collapsed " + to_be_removed.size()\r
+                        + " branches with\nbranch length values below " + getMinNotCollapseBlValue(), "Collapsed "\r
+                        + to_be_removed.size() + " branches", JOptionPane.INFORMATION_MESSAGE );\r
+            }\r
+            else {\r
+                JOptionPane.showMessageDialog( this,\r
+                                               "No branch collapsed,\nminimum branch length is " + min_bl,\r
+                                               "No branch collapsed",\r
+                                               JOptionPane.INFORMATION_MESSAGE );\r
+            }\r
+        }\r
+        else {\r
+            JOptionPane.showMessageDialog( this,\r
+                                           "No branch collapsed because no branch length values present",\r
+                                           "No branch length values present",\r
+                                           JOptionPane.INFORMATION_MESSAGE );\r
+        }\r
+    }\r
+\r
+    private void collapse( final Phylogeny phy ) {\r
         final PhylogenyNodeIterator it = phy.iteratorPostorder();\r
         final List<PhylogenyNode> to_be_removed = new ArrayList<PhylogenyNode>();\r
         double min_support = Double.MAX_VALUE;\r
@@ -1762,7 +1838,43 @@ public final class MainFrameApplication extends MainFrame {
                     }\r
                     if ( success && ( m >= 0.0 ) ) {\r
                         setMinNotCollapseConfidenceValue( m );\r
-                        collapse( phy, m );\r
+                        collapse( phy );\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    private void collapseBelowBranchLengthThreshold() {\r
+        if ( getCurrentTreePanel() != null ) {\r
+            final Phylogeny phy = getCurrentTreePanel().getPhylogeny();\r
+            if ( ( phy != null ) && !phy.isEmpty() ) {\r
+                final String s = ( String ) JOptionPane\r
+                        .showInputDialog( this,\r
+                                          "Please enter the minimum branch length value\n",\r
+                                          "Minimal Branch Length Value",\r
+                                          JOptionPane.QUESTION_MESSAGE,\r
+                                          null,\r
+                                          null,\r
+                                          getMinNotCollapseBlValue() );\r
+                if ( !ForesterUtil.isEmpty( s ) ) {\r
+                    boolean success = true;\r
+                    double m = 0.0;\r
+                    final String m_str = s.trim();\r
+                    if ( !ForesterUtil.isEmpty( m_str ) ) {\r
+                        try {\r
+                            m = Double.parseDouble( m_str );\r
+                        }\r
+                        catch ( final Exception ex ) {\r
+                            success = false;\r
+                        }\r
+                    }\r
+                    else {\r
+                        success = false;\r
+                    }\r
+                    if ( success && ( m >= 0.0 ) ) {\r
+                        setMinNotCollapseBlValue( m );\r
+                        collapseBl( phy );\r
                     }\r
                 }\r
             }\r
@@ -1918,6 +2030,10 @@ public final class MainFrameApplication extends MainFrame {
         return _min_not_collapse;\r
     }\r
 \r
+    private double getMinNotCollapseBlValue() {\r
+        return _min_not_collapse_bl;\r
+    }\r
+\r
     private PhylogeneticInferenceOptions getPhylogeneticInferenceOptions() {\r
         if ( _phylogenetic_inference_options == null ) {\r
             _phylogenetic_inference_options = new PhylogeneticInferenceOptions();\r
@@ -2376,6 +2492,10 @@ public final class MainFrameApplication extends MainFrame {
         _min_not_collapse = min_not_collapse;\r
     }\r
 \r
+    private void setMinNotCollapseBlValue( final double min_not_collapse_bl ) {\r
+        _min_not_collapse_bl = min_not_collapse_bl;\r
+    }\r
+\r
     private void setPhylogeneticInferenceOptions( final PhylogeneticInferenceOptions phylogenetic_inference_options ) {\r
         _phylogenetic_inference_options = phylogenetic_inference_options;\r
     }\r