(no commit message)
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 16 Dec 2011 23:56:58 +0000 (23:56 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Fri, 16 Dec 2011 23:56:58 +0000 (23:56 +0000)
forester/java/src/org/forester/io/writers/PhylogenyWriter.java
forester/java/src/org/forester/phylogeny/Phylogeny.java
forester/java/src/org/forester/phylogeny/PhylogenyNode.java
forester/java/src/org/forester/phylogeny/PhylogenyNodeI.java
forester/java/src/org/forester/surfacing/SurfacingUtil.java
forester/java/src/org/forester/test/Test.java

index 616ed5c..b41d8d7 100644 (file)
@@ -41,6 +41,7 @@ import org.forester.io.parsers.nexus.NexusConstants;
 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyNode;
+import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
 import org.forester.phylogeny.data.PhylogenyDataUtil;
 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
 import org.forester.phylogeny.iterators.PostOrderStackObject;
@@ -73,7 +74,7 @@ public final class PhylogenyWriter {
     private Stack<PostOrderStackObject> _stack;
     private boolean                     _simple_nh;
     private boolean                     _nh_write_distance_to_parent;
-    private boolean                     _write_conf_values_in_branckets_in_nh;
+    NH_CONVERSION_SUPPORT_VALUE_STYLE   _nh_conversion_support_style;
     private boolean                     _indent_phyloxml;
     private int                         _node_level;
     private int                         _phyloxml_level;
@@ -81,7 +82,7 @@ public final class PhylogenyWriter {
 
     public PhylogenyWriter() {
         setIndentPhyloxml( INDENT_PHYLOXML_DEAFULT );
-        setWriteConfidenceValuesInBracketsInNH( false );
+        setNhConversionSupportStyle( NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
     }
 
     private void appendPhylogenyLevelPhyloXml( final Writer writer, final Phylogeny tree ) throws IOException {
@@ -339,9 +340,9 @@ public final class PhylogenyWriter {
     public StringBuffer toNewHampshire( final Phylogeny tree,
                                         final boolean simple_nh,
                                         final boolean nh_write_distance_to_parent,
-                                        final boolean write_conf_values_in_branckets_in_nh ) throws IOException {
+                                        final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) throws IOException {
         setOutputFormt( FORMAT.NH );
-        setWriteConfidenceValuesInBracketsInNH( write_conf_values_in_branckets_in_nh );
+        setNhConversionSupportStyle( svs );
         setSimpleNH( simple_nh );
         setWriteDistanceToParentInNH( nh_write_distance_to_parent );
         return getOutput( tree );
@@ -366,9 +367,9 @@ public final class PhylogenyWriter {
     public void toNewHampshire( final Phylogeny tree,
                                 final boolean simple_nh,
                                 final boolean write_distance_to_parent,
-                                final boolean use_brackets_for_confidence,
+                                final NH_CONVERSION_SUPPORT_VALUE_STYLE svs,
                                 final File out_file ) throws IOException {
-        writeToFile( toNewHampshire( tree, simple_nh, write_distance_to_parent, use_brackets_for_confidence ), out_file );
+        writeToFile( toNewHampshire( tree, simple_nh, write_distance_to_parent, svs ), out_file );
     }
 
     public void toNewHampshire( final Phylogeny[] trees,
@@ -414,27 +415,26 @@ public final class PhylogenyWriter {
         writeToFile( sb, out_file );
     }
 
-    public void toNexus( final File out_file, final Phylogeny tree, final boolean write_conf_values_in_branckets_in_nh )
+    public void toNexus( final File out_file, final Phylogeny tree, final NH_CONVERSION_SUPPORT_VALUE_STYLE svs )
             throws IOException {
         final Writer writer = new BufferedWriter( new PrintWriter( out_file ) );
         final List<Phylogeny> trees = new ArrayList<Phylogeny>( 1 );
         trees.add( tree );
         writeNexusStart( writer );
         writeNexusTaxaBlock( writer, tree );
-        writeNexusTreesBlock( writer, trees, write_conf_values_in_branckets_in_nh );
+        writeNexusTreesBlock( writer, trees, svs );
         writer.flush();
         writer.close();
     }
 
-    public StringBuffer toNexus( final Phylogeny tree, final boolean write_conf_values_in_branckets_in_nh )
-            throws IOException {
+    public StringBuffer toNexus( final Phylogeny tree, final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) throws IOException {
         final StringWriter string_writer = new StringWriter();
         final Writer writer = new BufferedWriter( string_writer );
         final List<Phylogeny> trees = new ArrayList<Phylogeny>( 1 );
         trees.add( tree );
         writeNexusStart( writer );
         writeNexusTaxaBlock( writer, tree );
-        writeNexusTreesBlock( writer, trees, write_conf_values_in_branckets_in_nh );
+        writeNexusTreesBlock( writer, trees, svs );
         writer.flush();
         writer.close();
         return string_writer.getBuffer();
@@ -572,16 +572,16 @@ public final class PhylogenyWriter {
         else if ( getOutputFormt() == FORMAT.NH ) {
             getBuffer().append( node.toNewHampshire( isSimpleNH(),
                                                      isWriteDistanceToParentInNH(),
-                                                     isWriteConfidenceValuesInBracketsInNH() ) );
+                                                     getNhConversionSupportStyle() ) );
         }
     }
 
-    private boolean isWriteConfidenceValuesInBracketsInNH() {
-        return _write_conf_values_in_branckets_in_nh;
+    private NH_CONVERSION_SUPPORT_VALUE_STYLE getNhConversionSupportStyle() {
+        return _nh_conversion_support_style;
     }
 
-    private void setWriteConfidenceValuesInBracketsInNH( final boolean write_conf_values_in_branckets_in_nh ) {
-        _write_conf_values_in_branckets_in_nh = write_conf_values_in_branckets_in_nh;
+    private void setNhConversionSupportStyle( final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_style ) {
+        _nh_conversion_support_style = nh_conversion_support_style;
     }
 
     private void writeOpenClade( final PhylogenyNode node ) throws IOException {
@@ -737,7 +737,7 @@ public final class PhylogenyWriter {
 
     public static void writeNexusTreesBlock( final Writer writer,
                                              final List<Phylogeny> trees,
-                                             final boolean write_conf_values_in_branckets_in_nh ) throws IOException {
+                                             final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) throws IOException {
         writer.write( NexusConstants.BEGIN_TREES );
         writer.write( ForesterUtil.LINE_SEPARATOR );
         int i = 1;
@@ -761,7 +761,7 @@ public final class PhylogenyWriter {
             else {
                 writer.write( "[&U]" );
             }
-            writer.write( phylogeny.toNewHampshire( false, write_conf_values_in_branckets_in_nh ) );
+            writer.write( phylogeny.toNewHampshire( false, svs ) );
             writer.write( ForesterUtil.LINE_SEPARATOR );
             i++;
         }
index 772c860..91f714d 100644 (file)
@@ -39,6 +39,7 @@ import java.util.NoSuchElementException;
 import java.util.Vector;
 
 import org.forester.io.writers.PhylogenyWriter;
+import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
 import org.forester.phylogeny.data.BranchData;
 import org.forester.phylogeny.data.Confidence;
 import org.forester.phylogeny.data.Identifier;
@@ -1278,12 +1279,13 @@ public class Phylogeny {
     } // swapChildren( PhylogenyNode )
 
     public String toNewHampshire() {
-        return toNewHampshire( false, false );
+        return toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
     }
 
-    public String toNewHampshire( final boolean simple_nh, final boolean write_conf_values_in_branckets_in_nh ) {
+    public String toNewHampshire( final boolean simple_nh,
+                                  final NH_CONVERSION_SUPPORT_VALUE_STYLE nh_conversion_support_style ) {
         try {
-            return new PhylogenyWriter().toNewHampshire( this, simple_nh, true, write_conf_values_in_branckets_in_nh )
+            return new PhylogenyWriter().toNewHampshire( this, simple_nh, true, nh_conversion_support_style )
                     .toString();
         }
         catch ( final IOException e ) {
@@ -1300,9 +1302,9 @@ public class Phylogeny {
         }
     }
 
-    public String toNexus( final boolean write_conf_values_in_branckets_in_nh ) {
+    public String toNexus( final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) {
         try {
-            return new PhylogenyWriter().toNexus( this, write_conf_values_in_branckets_in_nh ).toString();
+            return new PhylogenyWriter().toNexus( this, svs ).toString();
         }
         catch ( final IOException e ) {
             throw new Error( "this should not have happend: " + e.getMessage() );
index a11fbd0..e344279 100644 (file)
@@ -925,10 +925,16 @@ public class PhylogenyNode implements PhylogenyNodeI, Comparable<PhylogenyNode>
     // ---------------------------------------------------------
     final public String toNewHampshire( final boolean simple_nh,
                                         final boolean write_distance_to_parent,
-                                        final boolean write_support_values_in_brackets ) {
+                                        final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) {
         final StringBuilder sb = new StringBuilder();
         String data = "";
-        if ( !ForesterUtil.isEmpty( getName() ) ) {
+        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() );
+            }
+        }
+        else if ( !ForesterUtil.isEmpty( getName() ) ) {
             data = getName();
         }
         else if ( getNodeData().isHasTaxonomy() ) {
@@ -968,7 +974,8 @@ public class PhylogenyNode implements PhylogenyNodeI, Comparable<PhylogenyNode>
             sb.append( ":" );
             sb.append( getDistanceToParent() );
         }
-        if ( write_support_values_in_brackets && !isExternal() && getBranchData().isHasConfidences()
+        if ( ( svs == NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS ) && !isExternal()
+                && getBranchData().isHasConfidences()
                 && ( getBranchData().getConfidence( 0 ).getValue() != Confidence.CONFIDENCE_DEFAULT_VALUE ) ) {
             sb.append( "[" );
             sb.append( getBranchData().getConfidence( 0 ).getValue() );
index ca81328..86863b0 100644 (file)
@@ -29,6 +29,10 @@ package org.forester.phylogeny;
 
 public interface PhylogenyNodeI {
 
+    public enum NH_CONVERSION_SUPPORT_VALUE_STYLE {
+        NONE, IN_SQUARE_BRACKETS, AS_INTERNAL_NODE_NAMES;
+    }
+
     public void addAsChild( PhylogenyNodeI node );
 
     public PhylogenyNode getChildNode( int i );
index f7efb8f..2a607cd 100644 (file)
@@ -67,6 +67,7 @@ import org.forester.io.writers.PhylogenyWriter;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
 import org.forester.phylogeny.PhylogenyNode;
+import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
 import org.forester.phylogeny.data.BinaryCharacters;
 import org.forester.phylogeny.data.Confidence;
 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
@@ -2363,7 +2364,7 @@ public final class SurfacingUtil {
             w.write( ForesterUtil.LINE_SEPARATOR );
             my_matrix.writeNexusTaxaBlock( w );
             my_matrix.writeNexusBinaryChractersBlock( w );
-            PhylogenyWriter.writeNexusTreesBlock( w, phylogenies, false );
+            PhylogenyWriter.writeNexusTreesBlock( w, phylogenies, NH_CONVERSION_SUPPORT_VALUE_STYLE.NONE );
             w.flush();
             w.close();
             ForesterUtil.programMessage( surfacing.PRG_NAME, "Wrote Nexus file: \"" + outfile_name + "\"" );
index a508c87..05d17ac 100644 (file)
@@ -62,6 +62,7 @@ import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyBranch;
 import org.forester.phylogeny.PhylogenyMethods;
 import org.forester.phylogeny.PhylogenyNode;
+import org.forester.phylogeny.PhylogenyNodeI.NH_CONVERSION_SUPPORT_VALUE_STYLE;
 import org.forester.phylogeny.data.BinaryCharacters;
 import org.forester.phylogeny.data.BranchWidth;
 import org.forester.phylogeny.data.Confidence;
@@ -4471,10 +4472,15 @@ public final class Test {
             if ( p50.getNode( "A" ) == null ) {
                 return false;
             }
-            if ( !p50.toNewHampshire( false, true ).equals( "((A,B)ab:2.0[88.0],C);" ) ) {
+            if ( !p50.toNewHampshire( false, NH_CONVERSION_SUPPORT_VALUE_STYLE.IN_SQUARE_BRACKETS )
+                    .equals( "((A,B)ab:2.0[88.0],C);" ) ) {
                 return false;
             }
-            if ( !p50.toNewHampshire( false, false ).equals( "((A,B)ab:2.0,C);" ) ) {
+            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);" ) ) {
                 return false;
             }
             final Phylogeny p51 = factory.create( new StringBuffer( "((\"A(A\",B)ab:2[88],C)" ), new NHXParser() )[ 0 ];