X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fphylogeny%2FPhylogenyMethods.java;h=75250ebb8742880f384507ddded666d88f1f59b3;hb=2b1c49af616eb01a99a69daf8f703f494b1a5a7e;hp=c881906681b1837062933c78c6ef049e39eb0852;hpb=4e8cb17afec5430c00ff6a026d1528c188e91cda;p=jalview.git diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java index c881906..75250eb 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyMethods.java @@ -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(); @@ -583,16 +595,14 @@ public class PhylogenyMethods { return PhylogenyDataUtil.BRANCH_LENGTH_DEFAULT; } - // Helper for getUltraParalogousNodes( PhylogenyNode ). - public static boolean areAllChildrenDuplications( final PhylogenyNode n ) { + public final static boolean isAllDecendentsAreDuplications( final PhylogenyNode n ) { if ( n.isExternal() ) { - return false; + return true; } else { if ( n.isDuplication() ) { - //FIXME test me! for( final PhylogenyNode desc : n.getDescendants() ) { - if ( !areAllChildrenDuplications( desc ) ) { + if ( !isAllDecendentsAreDuplications( desc ) ) { return false; } } @@ -1065,13 +1075,14 @@ public class PhylogenyMethods { * @param n * external PhylogenyNode whose strictly speciation related Nodes * are to be returned - * @return Vector of references to all strictly speciation related Nodes of + * @return References to all strictly speciation related Nodes of * PhylogenyNode n of this Phylogeny, null if this Phylogeny is * empty or if n is internal */ public static List getSuperOrthologousNodes( final PhylogenyNode n ) { // FIXME - PhylogenyNode node = n, deepest = null; + PhylogenyNode node = n; + PhylogenyNode deepest = null; final List v = new ArrayList(); if ( !node.isExternal() ) { return null; @@ -1148,9 +1159,9 @@ public class PhylogenyMethods { // FIXME test me PhylogenyNode node = n; if ( !node.isExternal() ) { - return null; + throw new IllegalArgumentException( "attempt to get ultra-paralogous nodes of internal node" ); } - while ( !node.isRoot() && node.getParent().isDuplication() && areAllChildrenDuplications( node.getParent() ) ) { + while ( !node.isRoot() && node.getParent().isDuplication() && isAllDecendentsAreDuplications( node.getParent() ) ) { node = node.getParent(); } final List nodes = node.getAllExternalDescendants(); @@ -1158,42 +1169,6 @@ public class PhylogenyMethods { return nodes; } - public static String inferCommonPartOfScientificNameOfDescendants( final PhylogenyNode node ) { - final List 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() ) { @@ -1638,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 taxonomyBasedDeletionOfExternalNodes( final Phylogeny reference, + final Phylogeny to_be_stripped ) { final Set ref_ext_taxo = new HashSet(); for( final PhylogenyNodeIterator it = reference.iteratorExternalForward(); it.hasNext(); ) { final PhylogenyNode n = it.next(); @@ -1666,12 +1642,12 @@ public class PhylogenyMethods { nodes_to_delete.add( n ); } } - for( final PhylogenyNode phylogenyNode : nodes_to_delete ) { - to_be_stripped.deleteSubtree( phylogenyNode, true ); + for( final PhylogenyNode n : nodes_to_delete ) { + to_be_stripped.deleteSubtree( n, true ); } to_be_stripped.clearHashIdToNodeMap(); to_be_stripped.externalNodesHaveChanged(); - return nodes_to_delete.size(); + return nodes_to_delete; } /** @@ -1729,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; }