"rio" work
[jalview.git] / forester / java / src / org / forester / phylogeny / PhylogenyMethods.java
index 64c7965..b89575e 100644 (file)
@@ -159,6 +159,12 @@ public class PhylogenyMethods {
      * @return LCA of node1 and node2
      */
     public final static PhylogenyNode calculateLCA( PhylogenyNode node1, PhylogenyNode node2 ) {
+        if ( node1 == null ) {
+            throw new IllegalArgumentException( "first argument (node) is null" );
+        }
+        if ( node2 == null ) {
+            throw new IllegalArgumentException( "second argument (node) is null" );
+        }
         if ( node1 == node2 ) {
             return node1;
         }
@@ -211,6 +217,12 @@ public class PhylogenyMethods {
      * @return LCA of node1 and node2
      */
     public final static PhylogenyNode calculateLCAonTreeWithIdsInPreOrder( PhylogenyNode node1, PhylogenyNode node2 ) {
+        if ( node1 == null ) {
+            throw new IllegalArgumentException( "first argument (node) is null" );
+        }
+        if ( node2 == null ) {
+            throw new IllegalArgumentException( "second argument (node) is null" );
+        }
         while ( node1 != node2 ) {
             if ( node1.getId() > node2.getId() ) {
                 node1 = node1.getParent();
@@ -1157,42 +1169,6 @@ public class PhylogenyMethods {
         return nodes;
     }
 
-    public static String inferCommonPartOfScientificNameOfDescendants( final PhylogenyNode node ) {
-        final List<PhylogenyNode> descs = node.getDescendants();
-        String sn = null;
-        for( final PhylogenyNode n : descs ) {
-            if ( !n.getNodeData().isHasTaxonomy()
-                    || ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
-                return null;
-            }
-            else if ( sn == null ) {
-                sn = n.getNodeData().getTaxonomy().getScientificName().trim();
-            }
-            else {
-                String sn_current = n.getNodeData().getTaxonomy().getScientificName().trim();
-                if ( !sn.equals( sn_current ) ) {
-                    boolean overlap = false;
-                    while ( ( sn.indexOf( ' ' ) >= 0 ) || ( sn_current.indexOf( ' ' ) >= 0 ) ) {
-                        if ( ForesterUtil.countChars( sn, ' ' ) > ForesterUtil.countChars( sn_current, ' ' ) ) {
-                            sn = sn.substring( 0, sn.lastIndexOf( ' ' ) ).trim();
-                        }
-                        else {
-                            sn_current = sn_current.substring( 0, sn_current.lastIndexOf( ' ' ) ).trim();
-                        }
-                        if ( sn.equals( sn_current ) ) {
-                            overlap = true;
-                            break;
-                        }
-                    }
-                    if ( !overlap ) {
-                        return null;
-                    }
-                }
-            }
-        }
-        return sn;
-    }
-
     public static boolean isHasExternalDescendant( final PhylogenyNode node ) {
         for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
             if ( node.getChildNode( i ).isExternal() ) {
@@ -1637,9 +1613,10 @@ public class PhylogenyMethods {
      *            a reference Phylogeny
      * @param to_be_stripped
      *            Phylogeny to be stripped
-     * @return number of external nodes removed from to_be_stripped
+     * @return nodes removed from to_be_stripped
      */
-    public static int taxonomyBasedDeletionOfExternalNodes( final Phylogeny reference, final Phylogeny to_be_stripped ) {
+    public static List<PhylogenyNode> taxonomyBasedDeletionOfExternalNodes( final Phylogeny reference,
+                                                                            final Phylogeny to_be_stripped ) {
         final Set<String> ref_ext_taxo = new HashSet<String>();
         for( final PhylogenyNodeIterator it = reference.iteratorExternalForward(); it.hasNext(); ) {
             final PhylogenyNode n = it.next();
@@ -1670,7 +1647,7 @@ public class PhylogenyMethods {
         }
         to_be_stripped.clearHashIdToNodeMap();
         to_be_stripped.externalNodesHaveChanged();
-        return nodes_to_delete.size();
+        return nodes_to_delete;
     }
 
     /**
@@ -1728,10 +1705,6 @@ public class PhylogenyMethods {
         TAXONOMY_ID;
     }
 
-    public static enum TAXONOMY_EXTRACTION {
-        NO, YES, PFAM_STYLE_ONLY;
-    }
-
     public static enum DESCENDANT_SORT_PRIORITY {
         TAXONOMY, SEQUENCE, NODE_NAME;
     }