inprogress
[jalview.git] / forester / java / src / org / forester / phylogeny / Phylogeny.java
index b41f5fa..723fab8 100644 (file)
@@ -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;
 
@@ -68,7 +68,7 @@ public class Phylogeny {
     private Confidence                                          _confidence;
     private Identifier                                          _identifier;
     private boolean                                             _rerootable;
-    private HashMap<Integer, PhylogenyNode>                     _id_to_node_map;
+    private HashMap<Long, PhylogenyNode>                        _id_to_node_map;
     private List<PhylogenyNode>                                 _external_nodes_set;
     private Collection<Sequence>                                _sequenceRelationQueries;
     private Collection<SequenceRelation.SEQUENCE_RELATION_TYPE> _relevant_sequence_relation_types;
@@ -157,8 +157,6 @@ public class Phylogeny {
     public Phylogeny copy() {
         return copy( _root );
     }
-    
-  
 
     /**
      * Returns a deep copy of this Phylogeny.
@@ -392,7 +390,7 @@ public class Phylogeny {
      * Finds the PhylogenyNode of this Phylogeny which has a matching ID number.
      * @return PhylogenyNode with matching ID, null if not found
      */
-    public PhylogenyNode getNode( final int id ) throws NoSuchElementException {
+    public PhylogenyNode getNode( final long id ) throws NoSuchElementException {
         if ( isEmpty() ) {
             throw new NoSuchElementException( "attempt to get node in an empty phylogeny" );
         }
@@ -477,6 +475,20 @@ public class Phylogeny {
         return nodes;
     }
 
+    public List<PhylogenyNode> getNodesViaSequenceSymbol( final String seq_name ) {
+        if ( isEmpty() ) {
+            return null;
+        }
+        final List<PhylogenyNode> nodes = new ArrayList<PhylogenyNode>();
+        for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
+            final PhylogenyNode n = iter.next();
+            if ( n.getNodeData().isHasSequence() && n.getNodeData().getSequence().getSymbol().equals( seq_name ) ) {
+                nodes.add( n );
+            }
+        }
+        return nodes;
+    }
+
     public List<PhylogenyNode> getNodesViaTaxonomyCode( final String taxonomy_code ) {
         if ( isEmpty() ) {
             return null;
@@ -743,7 +755,7 @@ public class Phylogeny {
             return;
         }
         _id_to_node_map = null;
-        int max = 0;
+        long max = 0;
         for( final PhylogenyNodeIterator it = iteratorPreorder(); it.hasNext(); ) {
             final PhylogenyNode node = it.next();
             if ( node.isRoot() ) {
@@ -813,40 +825,11 @@ public class Phylogeny {
      * @param id
      *            ID (int) of PhylogenyNode of this Phylogeny
      */
-    public void reRoot( final int id ) {
+    public void reRoot( final long id ) {
         reRoot( getNode( id ) );
     }
 
     /**
-     * Places the root of this Phylogeny on Branch b. The new root is always
-     * placed on the middle of the branch b.
-     * 
-     */
-    public void reRoot( final PhylogenyBranch b ) {
-        final PhylogenyNode n1 = b.getFirstNode();
-        final PhylogenyNode n2 = b.getSecondNode();
-        if ( n1.isExternal() ) {
-            reRoot( n1 );
-        }
-        else if ( n2.isExternal() ) {
-            reRoot( n2 );
-        }
-        else if ( ( n2 == n1.getChildNode1() ) || ( n2 == n1.getChildNode2() ) ) {
-            reRoot( n2 );
-        }
-        else if ( ( n1 == n2.getChildNode1() ) || ( n1 == n2.getChildNode2() ) ) {
-            reRoot( n1 );
-        }
-        else if ( ( n1.getParent() != null ) && n1.getParent().isRoot()
-                && ( ( n1.getParent().getChildNode1() == n2 ) || ( n1.getParent().getChildNode2() == n2 ) ) ) {
-            reRoot( n1 );
-        }
-        else {
-            throw new IllegalArgumentException( "reRoot( Branch b ): b is not a branch." );
-        }
-    }
-
-    /**
      * Places the root of this Phylogeny on the parent branch PhylogenyNode n.
      * The new root is always placed on the middle of the branch.
      * <p>
@@ -1042,7 +1025,7 @@ public class Phylogeny {
         _identifier = identifier;
     }
 
-    public void setIdToNodeMap( final HashMap<Integer, PhylogenyNode> idhash ) {
+    public void setIdToNodeMap( final HashMap<Long, PhylogenyNode> idhash ) {
         _id_to_node_map = idhash;
     }
 
@@ -1075,7 +1058,7 @@ public class Phylogeny {
 
     public void setRoot( final PhylogenyNode n ) {
         _root = n;
-    } 
+    }
 
     /**
      * Sets whether this Phylogeny is rooted or not.
@@ -1170,7 +1153,7 @@ public class Phylogeny {
         return;
     } // unRoot()
 
-    private HashMap<Integer, PhylogenyNode> getIdToNodeMap() {
+    private HashMap<Long, PhylogenyNode> getIdToNodeMap() {
         return _id_to_node_map;
     }
 
@@ -1275,7 +1258,7 @@ public class Phylogeny {
         if ( isEmpty() ) {
             return;
         }
-        setIdToNodeMap( new HashMap<Integer, PhylogenyNode>() );
+        setIdToNodeMap( new HashMap<Long, PhylogenyNode>() );
         for( final PhylogenyNodeIterator iter = iteratorPreorder(); iter.hasNext(); ) {
             final PhylogenyNode node = iter.next();
             getIdToNodeMap().put( node.getId(), node );