added display of some basic data
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Sat, 16 Apr 2011 20:48:35 +0000 (20:48 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Sat, 16 Apr 2011 20:48:35 +0000 (20:48 +0000)
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/MainPanel.java
forester/java/src/org/forester/archaeopteryx/TreePanel.java
forester/java/src/org/forester/archaeopteryx/Util.java
forester/java/src/org/forester/phylogeny/PhylogenyMethods.java

index 4ade5da..4127698 100644 (file)
@@ -173,6 +173,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     JMenuItem                 _view_as_NHX_item;
     JMenuItem                 _view_as_XML_item;
     JMenuItem                 _view_as_nexus_item;
+    JMenuItem                 _display_basic_information_item;
     // help menu:
     JMenuItem                 _about_item;
     JMenuItem                 _help_item;
@@ -248,6 +249,9 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         else if ( o == _switch_colors_mi ) {
             switchColors();
         }
+        else if ( o == _display_basic_information_item ) {
+            displayBasicInformation();
+        }
         else if ( o == _view_as_NH_item ) {
             viewAsNH();
         }
@@ -503,11 +507,13 @@ public abstract class MainFrame extends JFrame implements ActionListener {
     }
 
     void buildViewMenu() {
-        _view_jmenu = createMenu( "View as Text", getConfiguration() );
+        _view_jmenu = createMenu( "View", getConfiguration() );
         _view_jmenu.add( _view_as_XML_item = new JMenuItem( "View as phyloXML" ) );
         _view_jmenu.add( _view_as_NH_item = new JMenuItem( "View as Newick" ) );
         _view_jmenu.add( _view_as_NHX_item = new JMenuItem( "View as NHX" ) );
         _view_jmenu.add( _view_as_nexus_item = new JMenuItem( "View as Nexus" ) );
+        _view_jmenu.add( _display_basic_information_item = new JMenuItem( "Display Basic Information" ) );
+        customizeJMenuItem( _display_basic_information_item );
         customizeJMenuItem( _view_as_NH_item );
         customizeJMenuItem( _view_as_NHX_item );
         customizeJMenuItem( _view_as_XML_item );
@@ -925,6 +931,13 @@ public abstract class MainFrame extends JFrame implements ActionListener {
         ( ( JCheckBoxMenuItem ) o ).setSelected( true );
     }
 
+    void displayBasicInformation() {
+        if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty() ) {
+            return;
+        }
+        _textframe = TextFrame.instantiate( Util.crateBasicInformation( _mainpanel.getCurrentPhylogeny() ) );
+    }
+
     void viewAsNexus() {
         removeTextFrame();
         if ( ( _mainpanel.getCurrentPhylogeny() == null ) || _mainpanel.getCurrentPhylogeny().isEmpty()
index 7e20578..8062491 100644 (file)
@@ -136,10 +136,7 @@ public class MainPanel extends JPanel implements ComponentListener {
         treegraphic_scroll_pane_panel.add( treegraphic_scroll_pane, BorderLayout.CENTER );
         _treegraphic_scroll_pane_panels.add( treegraphic_scroll_pane_panel );
         _treegraphic_scroll_panes.add( treegraphic_scroll_pane );
-        getTabbedPane().addTab( name,
-                                null,
-                                treegraphic_scroll_pane_panel,
-                                Util.createDescriptionForTab( phy, full_path ) );
+        getTabbedPane().addTab( name, null, treegraphic_scroll_pane_panel, "" );
         getTabbedPane().setSelectedIndex( getTabbedPane().getTabCount() - 1 );
         getControlPanel().showWhole();
     }
index 4c4c178..c91616a 100644 (file)
@@ -3476,7 +3476,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             }
             if ( _nodes_in_preorder == null ) {
                 _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
-                System.out.println( "total nodes: " + _nodes_in_preorder.length );
                 int i = 0;
                 for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
                     _nodes_in_preorder[ i++ ] = it.next();
index d347ab1..91e36b1 100644 (file)
@@ -67,6 +67,7 @@ import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
 import org.forester.phylogeny.factories.PhylogenyFactory;
 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
 import org.forester.phylogeny.iterators.PreorderTreeIterator;
+import org.forester.util.DescriptiveStatistics;
 import org.forester.util.ForesterUtil;
 
 final class Util {
@@ -308,37 +309,79 @@ final class Util {
         }
     }
 
-    final static String createDescriptionForTab( final Phylogeny phy, final String full_path ) {
+    final static String crateBasicInformation( final Phylogeny phy ) {
         final StringBuilder desc = new StringBuilder();
         if ( ( phy != null ) && !phy.isEmpty() ) {
             if ( !ForesterUtil.isEmpty( phy.getName() ) ) {
-                desc.append( "name: " );
+                desc.append( "Name: " );
                 desc.append( phy.getName() );
-                desc.append( "; " );
+                desc.append( "\n" );
             }
             if ( phy.getIdentifier() != null ) {
-                desc.append( "id: " );
+                desc.append( "Id: " );
                 desc.append( phy.getIdentifier() );
-                desc.append( "; " );
+                desc.append( "\n" );
             }
-            desc.append( "rooted: " );
+            desc.append( "Rooted: " );
             desc.append( phy.isRooted() );
-            desc.append( "; " );
-            desc.append( "rerootable: " );
+            desc.append( "\n" );
+            desc.append( "Rerootable: " );
             desc.append( phy.isRerootable() );
-            desc.append( "; " );
-            desc.append( "external nodes: " );
+            desc.append( "\n" );
+            desc.append( "Node sum: " );
+            desc.append( phy.getNodeCount() );
+            desc.append( "\n" );
+            desc.append( "External node sum: " );
             desc.append( phy.getNumberOfExternalNodes() );
-            desc.append( "; " );
-            desc.append( "branches: " );
+            desc.append( "\n" );
+            desc.append( "Internal node sum: " );
+            desc.append( phy.getNodeCount() - phy.getNumberOfExternalNodes() );
+            desc.append( "\n" );
+            desc.append( "Branche sum: " );
             desc.append( phy.getNumberOfBranches() );
-            desc.append( "; " );
-            desc.append( "maximum descendants: " );
-            desc.append( PhylogenyMethods.calculateMaximumNumberOfDescendantsPerNode( phy ) );
-            if ( !ForesterUtil.isEmpty( full_path ) && ( full_path.length() <= 50 ) ) {
-                desc.append( "; " );
-                desc.append( "path: " );
-                desc.append( full_path );
+            desc.append( "\n" );
+            desc.append( "Depth: " );
+            desc.append( PhylogenyMethods.calculateMaxDepth( phy ) );
+            desc.append( "\n" );
+            desc.append( "Maximum distance to root: " );
+            desc.append( ForesterUtil.round( PhylogenyMethods.calculateMaxDistanceToRoot( phy ), 6 ) );
+            desc.append( "\n" );
+            desc.append( "Descendants per node statistics: " );
+            final DescriptiveStatistics ds = PhylogenyMethods.calculatNumberOfDescendantsPerNodeStatistics( phy );
+            desc.append( "\n" );
+            desc.append( "    Median: " + ForesterUtil.round( ds.median(), 2 ) );
+            desc.append( "\n" );
+            desc.append( "    Mean: " + ForesterUtil.round( ds.arithmeticMean(), 2 ) );
+            desc.append( "\n" );
+            desc.append( "    SD: " + ForesterUtil.round( ds.sampleStandardDeviation(), 2 ) );
+            desc.append( "\n" );
+            desc.append( "    Minimum: " + ForesterUtil.roundToInt( ds.getMin() ) );
+            desc.append( "\n" );
+            desc.append( "    Maximum: " + ForesterUtil.roundToInt( ds.getMax() ) );
+            desc.append( "\n" );
+            final DescriptiveStatistics cs = PhylogenyMethods.calculatConfidenceStatistics( phy );
+            if ( cs.getN() > 1 ) {
+                desc.append( "Support statistics: " );
+                desc.append( "\n" );
+                desc.append( "    Branches with support: " + cs.getN() );
+                desc.append( "\n" );
+                desc.append( "    Median: " + ForesterUtil.round( cs.median(), 6 ) );
+                desc.append( "\n" );
+                desc.append( "    Mean: " + ForesterUtil.round( cs.arithmeticMean(), 6 ) );
+                desc.append( "\n" );
+                if ( cs.getN() > 2 ) {
+                    desc.append( "    SD: " + ForesterUtil.round( cs.sampleStandardDeviation(), 6 ) );
+                    desc.append( "\n" );
+                }
+                desc.append( "    Minimum: " + ForesterUtil.roundToInt( cs.getMin() ) );
+                desc.append( "\n" );
+                desc.append( "    Maximum: " + ForesterUtil.roundToInt( cs.getMax() ) );
+                desc.append( "\n" );
+            }
+            final Set<Taxonomy> taxs = PhylogenyMethods.obtainDistinctTaxonomies( phy.getRoot() );
+            if ( taxs != null ) {
+                desc.append( "Distinct external taxonomies: " );
+                desc.append( taxs.size() );
             }
         }
         return desc.toString();
index f53e41a..5b936d5 100644 (file)
@@ -41,6 +41,8 @@ import org.forester.phylogeny.data.Confidence;
 import org.forester.phylogeny.data.DomainArchitecture;
 import org.forester.phylogeny.data.Taxonomy;
 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
+import org.forester.util.BasicDescriptiveStatistics;
+import org.forester.util.DescriptiveStatistics;
 import org.forester.util.FailedConditionCheckException;
 import org.forester.util.ForesterUtil;
 
@@ -271,15 +273,28 @@ public class PhylogenyMethods {
         return max;
     }
 
-    public static int calculateMaximumNumberOfDescendantsPerNode( final Phylogeny phy ) {
-        int max = 0;
+    public static DescriptiveStatistics calculatNumberOfDescendantsPerNodeStatistics( final Phylogeny phy ) {
+        final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
         for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
-            final PhylogenyNode node = iter.next();
-            if ( node.getNumberOfDescendants() > max ) {
-                max = node.getNumberOfDescendants();
+            final PhylogenyNode n = iter.next();
+            if ( !n.isExternal() ) {
+                stats.addValue( n.getNumberOfDescendants() );
             }
         }
-        return max;
+        return stats;
+    }
+
+    public static DescriptiveStatistics calculatConfidenceStatistics( final Phylogeny phy ) {
+        final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
+        for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
+            final PhylogenyNode n = iter.next();
+            if ( !n.isExternal() ) {
+                if ( n.getBranchData().isHasConfidences() ) {
+                    stats.addValue( n.getBranchData().getConfidence( 0 ).getValue() );
+                }
+            }
+        }
+        return stats;
     }
 
     /**