X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fphylogeny%2FPhylogenyNode.java;h=23eeec1731affab68de9132a038c52be8d6cc0b5;hb=7e567e18a5ba32035a8db4ca041023c9e862d25b;hp=2b7c2cf80860a0024adc13cc2705e8aff6e25b8e;hpb=299c529fea070487998aee60ed7810af57f3a071;p=jalview.git diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java index 2b7c2cf..23eeec1 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java @@ -74,10 +74,19 @@ public final class PhylogenyNode implements Comparable { setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!) } + public PhylogenyNode( final String node_name ) { + setId( PhylogenyNode.getNodeCount() ); + PhylogenyNode.increaseNodeCount(); + setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!) + if ( node_name != null ) { + getNodeData().setNodeName( node_name ); + } + } + 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!!). @@ -878,10 +887,8 @@ public final class PhylogenyNode implements Comparable { // --------------------------------------------------------- // 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() @@ -904,29 +911,19 @@ public final class PhylogenyNode implements Comparable { 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 ); - } - if ( ForesterUtil.isContainsParanthesesableNhCharacter( data ) ) { - sb.append( '\'' ); - sb.append( data ); - sb.append( '\'' ); + else if ( !ForesterUtil.isEmpty( getNodeData().getSequence().getSymbol() ) ) { + data = getNodeData().getSequence().getSymbol(); } - 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() ); @@ -948,18 +945,10 @@ public final class PhylogenyNode implements Comparable { * 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( ":" );