in progress
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 12 Jan 2012 00:23:07 +0000 (00:23 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Thu, 12 Jan 2012 00:23:07 +0000 (00:23 +0000)
forester/java/src/org/forester/phylogeny/PhylogenyNode.java
forester/java/src/org/forester/phylogeny/data/Confidence.java
forester/java/src/org/forester/test/Test.java

index e344279..f0f2a53 100644 (file)
@@ -32,6 +32,7 @@ import java.util.List;
 
 import org.forester.io.parsers.nhx.NHXFormatException;
 import org.forester.io.parsers.nhx.NHXParser;
+import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
 import org.forester.phylogeny.data.BranchData;
 import org.forester.phylogeny.data.Confidence;
 import org.forester.phylogeny.data.NodeData;
@@ -931,7 +932,9 @@ public class PhylogenyNode implements PhylogenyNodeI, Comparable<PhylogenyNode>
         if ( ( svs == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ) && !isExternal() ) {
             if ( getBranchData().isHasConfidences()
                     && ( getBranchData().getConfidence( 0 ).getValue() != Confidence.CONFIDENCE_DEFAULT_VALUE ) ) {
-                data = String.valueOf( getBranchData().getConfidence( 0 ).getValue() );
+                data = Confidence.FORMATTER.format( ForesterUtil
+                        .round( getBranchData().getConfidence( 0 ).getValue(),
+                                PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) );
             }
         }
         else if ( !ForesterUtil.isEmpty( getName() ) ) {
@@ -978,7 +981,9 @@ public class PhylogenyNode implements PhylogenyNodeI, Comparable<PhylogenyNode>
                 && getBranchData().isHasConfidences()
                 && ( getBranchData().getConfidence( 0 ).getValue() != Confidence.CONFIDENCE_DEFAULT_VALUE ) ) {
             sb.append( "[" );
-            sb.append( getBranchData().getConfidence( 0 ).getValue() );
+            sb.append( Confidence.FORMATTER.format( ForesterUtil
+                    .round( getBranchData().getConfidence( 0 ).getValue(),
+                            PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ) );
             sb.append( "]" );
         }
         return sb.toString();
index fe99d12..e9e631a 100644 (file)
@@ -27,6 +27,9 @@ package org.forester.phylogeny.data;
 
 import java.io.IOException;
 import java.io.Writer;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
 
 import org.forester.io.parsers.nhx.NHXtags;
 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
@@ -35,10 +38,17 @@ import org.forester.util.ForesterUtil;
 
 public class Confidence implements PhylogenyData, Comparable<Confidence> {
 
-    public final static int CONFIDENCE_DEFAULT_VALUE = -9999;
-    private double          _value;
-    private double          _sd;
-    private String          _type;
+    public final static int          CONFIDENCE_DEFAULT_VALUE = -9999;
+    private double                   _value;
+    private double                   _sd;
+    private String                   _type;
+    public final static NumberFormat FORMATTER;
+    static {
+        final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
+        dfs.setDecimalSeparator( '.' );
+        FORMATTER = new DecimalFormat( "#.#########", dfs );
+        FORMATTER.setMaximumFractionDigits( PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT );
+    }
 
     public Confidence() {
         init();
@@ -143,7 +153,8 @@ public class Confidence implements PhylogenyData, Comparable<Confidence> {
     public StringBuffer toNHX() {
         final StringBuffer sb = new StringBuffer();
         sb.append( NHXtags.SUPPORT );
-        sb.append( getValue() );
+        sb.append( FORMATTER.format( ForesterUtil.round( getValue(),
+                                                         PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ) );
         return sb;
     }
 
@@ -158,7 +169,7 @@ public class Confidence implements PhylogenyData, Comparable<Confidence> {
             PhylogenyDataUtil
                     .appendElement( writer,
                                     PhyloXmlMapping.CONFIDENCE,
-                                    String.valueOf( ForesterUtil
+                                    FORMATTER.format( ForesterUtil
                                             .round( getValue(), PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ),
                                     PhyloXmlMapping.CONFIDENCE_TYPE_ATTR,
                                     ForesterUtil.isEmpty( getType() ) ? "unknown" : getType(),
@@ -171,7 +182,7 @@ public class Confidence implements PhylogenyData, Comparable<Confidence> {
             PhylogenyDataUtil
                     .appendElement( writer,
                                     PhyloXmlMapping.CONFIDENCE,
-                                    String.valueOf( ForesterUtil
+                                    FORMATTER.format( ForesterUtil
                                             .round( getValue(), PhyloXmlUtil.ROUNDING_DIGITS_FOR_PHYLOXML_DOUBLE_OUTPUT ) ),
                                     PhyloXmlMapping.CONFIDENCE_TYPE_ATTR,
                                     ForesterUtil.isEmpty( getType() ) ? "unknown" : getType() );
index 05d17ac..0fb8f1d 100644 (file)
@@ -4473,14 +4473,14 @@ public final class Test {
                 return false;
             }
             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
-                    .equals( "((A,B)ab:2.0[88.0],C);" ) ) {
+                    .equals( "((A,B)ab:2.0[88],C);" ) ) {
                 return false;
             }
             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE ).equals( "((A,B)ab:2.0,C);" ) ) {
                 return false;
             }
             if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES )
-                    .equals( "((A,B)88.0:2.0,C);" ) ) {
+                    .equals( "((A,B)88:2.0,C);" ) ) {
                 return false;
             }
             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];
@@ -4528,11 +4528,10 @@ public final class Test {
                 return false;
             }
             if ( !n5.toNewHampshireX()
-                    .equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:XN=S=tag1=value1=unit1:B=56.0:W=2.0:C=10.20.30]" ) ) {
+                    .equals( "n5:0.1[&&NHX:T=1:S=Ecoli:D=Y:XN=S=tag1=value1=unit1:B=56:W=2.0:C=10.20.30]" ) ) {
                 return false;
             }
-            if ( !n6.toNewHampshireX()
-                    .equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100.0:W=2.0:C=0.0.0]" ) ) {
+            if ( !n6.toNewHampshireX().equals( "n6:1.0E-6[&&NHX:T=1:S=Ecoli:D=N:XN=B=bool_tag=T:B=100:W=2.0:C=0.0.0]" ) ) {
                 return false;
             }
         }
@@ -4963,13 +4962,13 @@ public final class Test {
                 return false;
             }
             final Phylogeny p9 = factory.create( "((A:0.2,B:0.3):0.5[91],C:0.1)root:0.1[100]", new NHXParser() )[ 0 ];
-            if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91.0],C:0.1)root:0.1[&&NHX:B=100.0]" ) ) {
+            if ( !p9.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
                 return false;
             }
             final Phylogeny p10 = factory
                     .create( " [79]   ( (A [co mment] :0 .2[comment],B:0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],C: 0.1)[comment]root:0.1[100] [comment]",
                              new NHXParser() )[ 0 ];
-            if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91.0],C:0.1)root:0.1[&&NHX:B=100.0]" ) ) {
+            if ( !p10.toNewHampshireX().equals( "((A:0.2,B:0.3):0.5[&&NHX:B=91],C:0.1)root:0.1[&&NHX:B=100]" ) ) {
                 return false;
             }
         }
@@ -5044,7 +5043,7 @@ public final class Test {
             final Phylogeny p10 = factory
                     .create( " [79]   ( (\"A \n\tB \" [co mment] :0 .2[comment],'B':0.3[com])[com ment]: 0. 5 \t[ 9 1 ][ comment],'C (or D?\\//;,))': 0.1)[comment]'\nroot is here (cool,  was! ) ':0.1[100] [comment]",
                              new NHXParser() )[ 0 ];
-            final String p10_clean_str = "(('A B':0.2,B:0.3):0.5[&&NHX:B=91.0],'C (or D?\\//;,))':0.1)'root is here (cool,  was! )':0.1[&&NHX:B=100.0]";
+            final String p10_clean_str = "(('A B':0.2,B:0.3):0.5[&&NHX:B=91],'C (or D?\\//;,))':0.1)'root is here (cool,  was! )':0.1[&&NHX:B=100]";
             if ( !p10.toNewHampshireX().equals( p10_clean_str ) ) {
                 return false;
             }
@@ -5056,7 +5055,7 @@ public final class Test {
             final Phylogeny p12 = factory
                     .create( " [79]   ( (\"A \n\tB \" [[][] :0 .2[comment][\t&\t&\n N\tH\tX:S=mo\tnkey !],'\tB\t\b\t\n\f\rB B ':0.0\b3[])\t[com ment]: 0. 5 \t[ 9 1 ][ \ncomment],'C\t (or D?\\//;,))': 0.\b1)[comment]'\nroot \tis here (cool, \b\t\n\f\r was! ) ':0.1[100] [comment]",
                              new NHXParser() )[ 0 ];
-            final String p12_clean_str = "(('A B':0.2[&&NHX:S=monkey!],'BB B':0.03):0.5[&&NHX:B=91.0],'C (or D?\\//;,))':0.1)'root is here (cool,  was! )':0.1[&&NHX:B=100.0]";
+            final String p12_clean_str = "(('A B':0.2[&&NHX:S=monkey!],'BB B':0.03):0.5[&&NHX:B=91],'C (or D?\\//;,))':0.1)'root is here (cool,  was! )':0.1[&&NHX:B=100]";
             if ( !p12.toNewHampshireX().equals( p12_clean_str ) ) {
                 return false;
             }