X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fphylogeny%2FPhylogenyMethods.java;h=e8498c5f5dc6af177de8e310d0cc2b9ae15ef53d;hb=8dbaf0f253f5ec2721b540d1f4ad06ffb35b66b6;hp=d48db8d446ec877376f673c2da84fcdfbdfeca12;hpb=7d44b232d0b61c02ef01d96d3db1d68744015bd7;p=jalview.git diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java index d48db8d..e8498c5 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java @@ -21,7 +21,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; @@ -62,52 +62,15 @@ import org.forester.util.ForesterUtil; public class PhylogenyMethods { - //private static PhylogenyMethods _instance = null; - //private final PhylogenyNode _farthest_1 = null; - //private final PhylogenyNode _farthest_2 = null; private PhylogenyMethods() { // Hidden constructor. } - // public double calculateFurthestDistance( final Phylogeny phylogeny ) { - // if ( phylogeny.getNumberOfExternalNodes() < 2 ) { - // return 0.0; - // } - // _farthest_1 = null; - // _farthest_2 = null; - // PhylogenyNode node_1 = null; - // PhylogenyNode node_2 = null; - // double farthest_d = -Double.MAX_VALUE; - // final PhylogenyMethods methods = PhylogenyMethods.getInstance(); - // final List ext_nodes = phylogeny.getRoot().getAllExternalDescendants(); - // for( int i = 1; i < ext_nodes.size(); ++i ) { - // for( int j = 0; j < i; ++j ) { - // final double d = methods.calculateDistance( ext_nodes.get( i ), ext_nodes.get( j ) ); - // if ( d < 0.0 ) { - // throw new RuntimeException( "distance cannot be negative" ); - // } - // if ( d > farthest_d ) { - // farthest_d = d; - // node_1 = ext_nodes.get( i ); - // node_2 = ext_nodes.get( j ); - // } - // } - // } - // _farthest_1 = node_1; - // _farthest_2 = node_2; - // return farthest_d; - // } @Override public Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException(); } - // public PhylogenyNode getFarthestNode1() { - // return _farthest_1; - // } - // public PhylogenyNode getFarthestNode2() { - // return _farthest_2; - // } public static DescriptiveStatistics calculatBranchLengthStatistics( final Phylogeny phy ) { final DescriptiveStatistics stats = new BasicDescriptiveStatistics(); for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) { @@ -327,8 +290,8 @@ public class PhylogenyMethods { public static final HashMap createNameToExtNodeMap( final Phylogeny phy ) { final HashMap nodes = new HashMap(); - for( final PhylogenyNodeIterator iter = phy.iteratorExternalForward(); iter.hasNext(); ) { - final PhylogenyNode n = iter.next(); + final List ext = phy.getExternalNodes(); + for( final PhylogenyNode n : ext ) { nodes.put( n.getName(), n ); } return nodes; @@ -408,7 +371,7 @@ public class PhylogenyMethods { final ArrayList to_delete = new ArrayList(); for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) { final PhylogenyNode n = iter.next(); - if ( ( !n.isExternal() ) && ( !n.isRoot() ) && ( n.getNumberOfDescendants() == 1 ) ) { + if ( ( !n.isExternal() ) && ( n.getNumberOfDescendants() == 1 ) ) { to_delete.add( n ); } } @@ -439,7 +402,7 @@ public class PhylogenyMethods { public static List getAllDescendants( final PhylogenyNode node ) { final List descs = new ArrayList(); - final Set encountered = new HashSet(); + final Set encountered = new HashSet(); if ( !node.isExternal() ) { final List exts = node.getAllExternalDescendants(); for( PhylogenyNode current : exts ) { @@ -700,39 +663,6 @@ public class PhylogenyMethods { phylogeny.recalculateNumberOfExternalDescendants( true ); } - public static void midpointRootOLD( final Phylogeny phylogeny ) { - // if ( phylogeny.getNumberOfExternalNodes() < 2 ) { - // return; - // } - // final PhylogenyMethods methods = getInstance(); - //final double farthest_d = methods.calculateFurthestDistance( phylogeny ); - // final PhylogenyNode f1 = methods.getFarthestNode1(); - // final PhylogenyNode f2 = methods.getFarthestNode2(); - // if ( farthest_d <= 0.0 ) { - // return; - // } - // double x = farthest_d / 2.0; - // PhylogenyNode n = f1; - // if ( PhylogenyMethods.getDistance( f1, phylogeny.getRoot() ) < PhylogenyMethods.getDistance( f2, phylogeny - // .getRoot() ) ) { - // n = f2; - // } - // while ( ( x > n.getDistanceToParent() ) && !n.isRoot() ) { - // x -= ( n.getDistanceToParent() > 0 ? n.getDistanceToParent() : 0 ); - // n = n.getParent(); - // } - // phylogeny.reRoot( n, x ); - // phylogeny.recalculateNumberOfExternalDescendants( true ); - // final PhylogenyNode a = getFurthestDescendant( phylogeny.getRoot().getChildNode1() ); - // final PhylogenyNode b = getFurthestDescendant( phylogeny.getRoot().getChildNode2() ); - // final double da = getDistance( a, phylogeny.getRoot() ); - // final double db = getDistance( b, phylogeny.getRoot() ); - // if ( Math.abs( da - db ) > 0.000001 ) { - // throw new FailedConditionCheckException( "this should not have happened: midpoint rooting failed: da=" - // + da + ", db=" + db + ", diff=" + Math.abs( da - db ) ); - // } - } - public static void normalizeBootstrapValues( final Phylogeny phylogeny, final double max_bootstrap_value, final double max_normalized_value ) { @@ -764,25 +694,6 @@ public class PhylogenyMethods { } /** - * Returns the set of distinct taxonomies of - * all external nodes of node. - * If at least one the external nodes has no taxonomy, - * null is returned. - * - */ - public static Set obtainDistinctTaxonomies( final PhylogenyNode node ) { - final List descs = node.getAllExternalDescendants(); - final Set tax_set = new HashSet(); - for( final PhylogenyNode n : descs ) { - if ( !n.getNodeData().isHasTaxonomy() || n.getNodeData().getTaxonomy().isEmpty() ) { - return null; - } - tax_set.add( n.getNodeData().getTaxonomy() ); - } - return tax_set; - } - - /** * Returns a map of distinct taxonomies of * all external nodes of node. * If at least one of the external nodes has no taxonomy, @@ -882,7 +793,7 @@ public class PhylogenyMethods { return; } phy.setIdToNodeMap( null ); - int i = PhylogenyNode.getNodeCount(); + long i = PhylogenyNode.getNodeCount(); for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) { it.next().setId( i++ ); } @@ -1394,13 +1305,16 @@ public class PhylogenyMethods { if ( !n.getNodeData().isHasTaxonomy() ) { throw new IllegalArgumentException( "no taxonomic data in node: " + n ); } - // ref_ext_taxo.add( getSpecies( n ) ); if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { ref_ext_taxo.add( n.getNodeData().getTaxonomy().getScientificName() ); } if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) { ref_ext_taxo.add( n.getNodeData().getTaxonomy().getTaxonomyCode() ); } + if ( ( n.getNodeData().getTaxonomy().getIdentifier() != null ) + && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getIdentifier().getValue() ) ) { + ref_ext_taxo.add( n.getNodeData().getTaxonomy().getIdentifier().getValuePlusProvider() ); + } } final ArrayList nodes_to_delete = new ArrayList(); for( final PhylogenyNodeIterator it = to_be_stripped.iteratorExternalForward(); it.hasNext(); ) { @@ -1409,7 +1323,9 @@ public class PhylogenyMethods { nodes_to_delete.add( n ); } else if ( !( ref_ext_taxo.contains( n.getNodeData().getTaxonomy().getScientificName() ) ) - && !( ref_ext_taxo.contains( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) { + && !( ref_ext_taxo.contains( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) + && !( ( n.getNodeData().getTaxonomy().getIdentifier() != null ) && ref_ext_taxo.contains( n + .getNodeData().getTaxonomy().getIdentifier().getValuePlusProvider() ) ) ) { nodes_to_delete.add( n ); } }