X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fphylogeny%2FPhylogenyNode.java;h=d37cc3b849b584335b7770a04239f05906d3c92f;hb=803a2b32992b5944b73c6dfcb80ceb58c09b81c1;hp=32fec23463c35d7cb6a66c0dcc4a961881e6720b;hpb=39ad4632ee57d8ab720a7ad08c2ba4cccffa05bb;p=jalview.git diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java index 32fec23..d37cc3b 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java @@ -23,7 +23,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.phylogeny; @@ -42,69 +42,105 @@ import org.forester.phylogeny.iterators.PreorderTreeIterator; import org.forester.util.ForesterUtil; /** - * Warning. Implementation of method 'compareTo' only looks at + * Warning. Implementation of method 'compareTo' only looks at * node name. Thus, use of this class in SortedSets might lead * to unexpected behavior. * */ -public final class PhylogenyNode implements PhylogenyNodeI, Comparable { +public final class PhylogenyNode implements Comparable { - private static int _node_count = 0; - private byte _indicator; - private int _id; - private int _sum_ext_nodes; - private float _x; - private float _y; - private double _distance_parent = PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT; + private static long NODE_COUNT = 0; + private BranchData _branch_data; private boolean _collapse; - private PhylogenyNode _parent; - private PhylogenyNode _link; private ArrayList _descendants; + private double _distance_parent = PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT; + private long _id; + private byte _indicator; + private PhylogenyNode _link; private NodeData _node_data; - private BranchData _branch_data; + private PhylogenyNode _parent; + private int _sum_ext_nodes; + private float _x; private float _x_secondary; + private float _y; private float _y_secondary; /** * Default constructor for PhylogenyNode. */ public PhylogenyNode() { - // init(); setId( PhylogenyNode.getNodeCount() ); PhylogenyNode.increaseNodeCount(); setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!) } - public void removeConnections() { - _parent = null; - _link = null; - _descendants = null; + 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, false, false, false ); + setId( PhylogenyNode.getNodeCount() ); + PhylogenyNode.increaseNodeCount(); + setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!). + } + + private PhylogenyNode( final String nhx, + final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, + final boolean replace_underscores, + final boolean parse_extended_tags ) throws NHXFormatException, PhyloXmlDataFormatException { + NHXParser.parseNHX( nhx, + this, + taxonomy_extraction, + replace_underscores, + false, + false, + parse_extended_tags ); + setId( PhylogenyNode.getNodeCount() ); + PhylogenyNode.increaseNodeCount(); + setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!). } /** * Adds PhylogenyNode n to the list of child nodes and sets the _parent of n * to this. - * + * * @param n * the PhylogenyNode to add */ - @Override - final public void addAsChild( final PhylogenyNodeI node ) { - final PhylogenyNode n = ( PhylogenyNode ) node; + final public void addAsChild( final PhylogenyNode node ) { + final PhylogenyNode n = node; addChildNode( n ); n.setParent( this ); } - /** - * Adds PhylogenyNode n to the list of child nodes. But does NOT set the - * _parent of n to this. - * - * @see addAsChild( PhylogenyNode n ) - * @param n - * the PhylogenyNode to add - */ - final private void addChildNode( final PhylogenyNode child ) { - getDescendants().add( child ); + public final int calculateDepth() { + PhylogenyNode n = this; + int steps = 0; + while ( n._parent != null ) { + steps++; + n = n._parent; + } + return steps; + } + + public final double calculateDistanceToRoot() { + PhylogenyNode n = this; + double d = 0.0; + while ( n._parent != null ) { + if ( n._distance_parent > 0.0 ) { + d += n._distance_parent; + } + n = n._parent; + } + return d; } @Override @@ -117,15 +153,12 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable getAllDescendants() { + return _descendants; + } + /** * Returns a List containing references to all external children of this * PhylogenyNode. - * + * * @return List of references to external Nodes */ final public List getAllExternalDescendants() { @@ -249,7 +283,7 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable getAllExternalDescendantsNames() { @@ -268,20 +302,15 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable - * + * * @return the child node index of this node * @throws UnsupportedOperationException * if this node is a root node @@ -328,7 +357,7 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable * [last modified Aug 14, 2006 by CMZ] - * + * * @return the child node index of this node * @throws UnsupportedOperationException * if this node is a root node @@ -356,7 +385,6 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable * [last modified May 18, 2005 by CMZ] - * + * * @return the first child node of this node */ public final PhylogenyNode getFirstChildNode() { @@ -373,6 +401,13 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable * [last modified May 18, 2005 by CMZ] - * + * * @return the last child node of this node */ public final PhylogenyNode getLastChildNode() { @@ -399,6 +434,10 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable getAllDescendants() { - return _descendants; - } - final public int getNumberOfDescendants() { if ( _descendants == null ) { return 0; @@ -599,30 +611,6 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable(); - // _parent = null; //TODO not needed? - // _id = 0; //TODO not needed? - //initializeData(); //TODO not needed? - //} - /** - * Deletes data of this PhylogenyNode. Links to the other Nodes in the - * Phylogeny, the ID and the sum of external nodes are NOT deleted. Field - * "_link" (_link to Nodes in other Phylogeny) IS deleted. - * - * @see #getLink() (Last modified: 12/20/03) - */ - // final private void initializeData() { - // _indicator = 0; - // _x = 0; - // _y = 0; - // //_node_name = ""; - // _distance_parent = PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT; - // _collapse = false; - // _link = null; - // _branch_data = null; - // _node_data = null; - // } /** * Returns whether this PhylogenyNode should be drawn as collapsed. */ @@ -638,9 +626,13 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable * [last modified June 01, 2005 by CMZ] - * + * * @return true if this node is the last child node of its _parent, false * otherwise */ @@ -719,11 +701,6 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable 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() ); @@ -998,47 +949,22 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable