in progress (special coloring is still true)
[jalview.git] / forester / java / src / org / forester / phylogeny / PhylogenyNode.java
index 6b180ca..e7ef81b 100644 (file)
@@ -86,7 +86,7 @@ public final class PhylogenyNode implements Comparable<PhylogenyNode> {
     private PhylogenyNode( final String nhx,
                            final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction,
                            final boolean replace_underscores ) throws NHXFormatException, PhyloXmlDataFormatException {
-        NHXParser.parseNHX( nhx, this, taxonomy_extraction, replace_underscores );
+        NHXParser.parseNHX( nhx, this, taxonomy_extraction, replace_underscores, false, false );
         setId( PhylogenyNode.getNodeCount() );
         PhylogenyNode.increaseNodeCount();
         setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!).
@@ -887,10 +887,8 @@ public final class PhylogenyNode implements Comparable<PhylogenyNode> {
     // ---------------------------------------------------------
     // Writing of Nodes to Strings
     // ---------------------------------------------------------
-    final public String toNewHampshire( final boolean simple_nh,
-                                        final boolean write_distance_to_parent,
+    final public String toNewHampshire( final boolean write_distance_to_parent,
                                         final NH_CONVERSION_SUPPORT_VALUE_STYLE svs ) {
-        final StringBuilder sb = new StringBuilder();
         String data = "";
         if ( ( svs == NH_CONVERSION_SUPPORT_VALUE_STYLE.AS_INTERNAL_NODE_NAMES ) && !isExternal() ) {
             if ( getBranchData().isHasConfidences()
@@ -913,29 +911,19 @@ public final class PhylogenyNode implements Comparable<PhylogenyNode> {
             else if ( !ForesterUtil.isEmpty( getNodeData().getTaxonomy().getCommonName() ) ) {
                 data = getNodeData().getTaxonomy().getCommonName();
             }
-            else if ( getNodeData().getTaxonomy().getTaxonomyCode() != null ) {
-                data = getNodeData().getTaxonomy().getTaxonomyCode();
-            }
         }
         else if ( getNodeData().isHasSequence() ) {
             if ( !ForesterUtil.isEmpty( getNodeData().getSequence().getName() ) ) {
                 data = getNodeData().getSequence().getName();
             }
-        }
-        if ( data.length() > 0 ) {
-            data = ForesterUtil.replaceIllegalNhCharacters( data );
-            if ( simple_nh && ( data.length() > 10 ) ) {
-                data = data.substring( 0, 11 );
+            else if ( !ForesterUtil.isEmpty( getNodeData().getSequence().getSymbol() ) ) {
+                data = getNodeData().getSequence().getSymbol();
             }
-            if ( ForesterUtil.isContainsParanthesesableNhCharacter( data ) ) {
-                sb.append( '\'' );
-                sb.append( data );
-                sb.append( '\'' );
-            }
-            else {
-                sb.append( data );
+            else if ( !ForesterUtil.isEmpty( getNodeData().getSequence().getGeneName() ) ) {
+                data = getNodeData().getSequence().getGeneName();
             }
         }
+        final StringBuilder sb = ForesterUtil.santitizeStringForNH( data );
         if ( write_distance_to_parent && ( getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) ) {
             sb.append( ":" );
             sb.append( getDistanceToParent() );
@@ -957,18 +945,10 @@ public final class PhylogenyNode implements Comparable<PhylogenyNode> {
      * representation.
      */
     final public String toNewHampshireX() {
-        final StringBuffer sb = new StringBuffer();
+        final StringBuilder sb = new StringBuilder();
         final StringBuffer s_nhx = new StringBuffer();
         if ( !ForesterUtil.isEmpty( getName() ) ) {
-            final String name = ForesterUtil.replaceIllegalNhCharacters( getName() );
-            if ( ForesterUtil.isContainsParanthesesableNhCharacter( name ) ) {
-                sb.append( '\'' );
-                sb.append( name );
-                sb.append( '\'' );
-            }
-            else {
-                sb.append( name );
-            }
+            sb.append( ForesterUtil.santitizeStringForNH( getName() ) );
         }
         if ( getDistanceToParent() != PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT ) {
             sb.append( ":" );
@@ -991,6 +971,10 @@ public final class PhylogenyNode implements Comparable<PhylogenyNode> {
     @Override
     final public String toString() {
         final StringBuilder sb = new StringBuilder();
+        if ( !ForesterUtil.isEmpty( getName() ) ) {
+            sb.append( getName() );
+            sb.append( " " );
+        }
         if ( getNodeData().isHasTaxonomy() ) {
             if ( !ForesterUtil.isEmpty( getNodeData().getTaxonomy().getScientificName() ) ) {
                 sb.append( getNodeData().getTaxonomy().getScientificName() );
@@ -1023,10 +1007,6 @@ public final class PhylogenyNode implements Comparable<PhylogenyNode> {
                 sb.append( " " );
             }
         }
-        if ( ( sb.length() <= 1 ) && !ForesterUtil.isEmpty( getName() ) ) {
-            sb.append( getName() );
-            sb.append( " " );
-        }
         if ( sb.length() <= 1 ) {
             sb.append( "[" );
             sb.append( getId() );