subtree deletion changed
[jalview.git] / forester / java / src / org / forester / phylogeny / PhylogenyMethods.java
index 4a2115e..bb13e65 100644 (file)
@@ -474,6 +474,13 @@ public class PhylogenyMethods {
                                 .setIdentifier( new Identifier( id, PhyloXmlUtil.UNIPROT_TAX_PROVIDER ) );
                         break;
                     }
+                    case TAXONOMY_ID: {
+                        if ( !n.getNodeData().isHasTaxonomy() ) {
+                            n.getNodeData().setTaxonomy( new Taxonomy() );
+                        }
+                        n.getNodeData().getTaxonomy().setIdentifier( new Identifier( name ) );
+                        break;
+                    }
                 }
             }
         }
@@ -593,13 +600,39 @@ public class PhylogenyMethods {
         return stats;
     }
 
-    public static DescriptiveStatistics calculatConfidenceStatistics( final Phylogeny phy ) {
+    public static DescriptiveStatistics calculatBranchLengthStatistics( final Phylogeny phy ) {
         final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
         for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
             final PhylogenyNode n = iter.next();
-            if ( !n.isExternal() ) {
+            if ( !n.isRoot() && ( n.getDistanceToParent() >= 0.0 ) ) {
+                stats.addValue( n.getDistanceToParent() );
+            }
+        }
+        return stats;
+    }
+
+    public static List<DescriptiveStatistics> calculatConfidenceStatistics( final Phylogeny phy ) {
+        final List<DescriptiveStatistics> stats = new ArrayList<DescriptiveStatistics>();
+        for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
+            final PhylogenyNode n = iter.next();
+            if ( !n.isExternal() && !n.isRoot() ) {
                 if ( n.getBranchData().isHasConfidences() ) {
-                    stats.addValue( n.getBranchData().getConfidence( 0 ).getValue() );
+                    for( int i = 0; i < n.getBranchData().getConfidences().size(); ++i ) {
+                        final Confidence c = n.getBranchData().getConfidences().get( i );
+                        if ( ( i > ( stats.size() - 1 ) ) || ( stats.get( i ) == null ) ) {
+                            stats.add( i, new BasicDescriptiveStatistics() );
+                        }
+                        if ( !ForesterUtil.isEmpty( c.getType() ) ) {
+                            if ( !ForesterUtil.isEmpty( stats.get( i ).getDescription() ) ) {
+                                if ( !stats.get( i ).getDescription().equalsIgnoreCase( c.getType() ) ) {
+                                    throw new IllegalArgumentException( "support values in node [" + n.toString()
+                                            + "] appear inconsistently ordered" );
+                                }
+                            }
+                            stats.get( i ).setDescription( c.getType() );
+                        }
+                        stats.get( i ).addValue( ( ( c != null ) && ( c.getValue() >= 0 ) ) ? c.getValue() : 0 );
+                    }
                 }
             }
         }
@@ -1611,7 +1644,8 @@ public class PhylogenyMethods {
         SEQUENCE_SYMBOL,
         SEQUENCE_NAME,
         TAXONOMY_ID_UNIPROT_1,
-        TAXONOMY_ID_UNIPROT_2;
+        TAXONOMY_ID_UNIPROT_2,
+        TAXONOMY_ID;
     }
 
     public static enum TAXONOMY_EXTRACTION {