moved from itext 2.1.7 to itextpdf 5.1.0
[jalview.git] / forester / java / src / org / forester / archaeopteryx / Util.java
index 3f7a50e..408a3d7 100644 (file)
@@ -5,7 +5,7 @@
 // Copyright (C) 2008-2009 Christian M. Zmasek
 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
 // All rights reserved
-// 
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
@@ -15,7 +15,7 @@
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 // Lesser General Public License for more details.
-// 
+//
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
@@ -67,9 +67,10 @@ 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 {
+public final class Util {
 
     private final static String[] AVAILABLE_FONT_FAMILIES_SORTED = GraphicsEnvironment.getLocalGraphicsEnvironment()
                                                                          .getAvailableFontFamilyNames();
@@ -116,8 +117,8 @@ final class Util {
                         }
                         String suffix = "";
                         if ( my_name_for_file.indexOf( '.' ) > 0 ) {
-                            suffix = my_name_for_file.substring( my_name_for_file.lastIndexOf( '.' ), my_name_for_file
-                                    .length() );
+                            suffix = my_name_for_file.substring( my_name_for_file.lastIndexOf( '.' ),
+                                                                 my_name_for_file.length() );
                             my_name_for_file = my_name_for_file.substring( 0, my_name_for_file.lastIndexOf( '.' ) );
                         }
                         if ( !ForesterUtil.isEmpty( my_name_for_file ) ) {
@@ -300,45 +301,87 @@ final class Util {
                     n.getBranchData().setBranchColor( new BranchColor( tree_panel.calculateTaxonomyBasedColor( tax ) ) );
                     final List<PhylogenyNode> descs = PhylogenyMethods.getAllDescendants( n );
                     for( final PhylogenyNode desc : descs ) {
-                        desc.getBranchData().setBranchColor( new BranchColor( tree_panel
-                                .calculateTaxonomyBasedColor( tax ) ) );
+                        desc.getBranchData()
+                                .setBranchColor( new BranchColor( tree_panel.calculateTaxonomyBasedColor( tax ) ) );
                     }
                 }
             }
         }
     }
 
-    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();
@@ -571,7 +614,7 @@ final class Util {
         System.out.println( "[" + applet_name + "] > " + message );
     }
 
-    final static void printWarningMessage( final String name, final String message ) {
+    public final static void printWarningMessage( final String name, final String message ) {
         System.out.println( "[" + name + "] > " + message );
     }