JAL-2805 added getter in trees for retrieving all node sequences
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 9 Jan 2018 10:21:01 +0000 (10:21 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 9 Jan 2018 10:44:19 +0000 (10:44 +0000)
src/jalview/ext/archaeopteryx/Tree.java
src/jalview/ext/treeviewer/TreeI.java

index 345820d..76808e8 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.ext.archaeopteryx;
 
+import jalview.datamodel.SequenceI;
 import jalview.ext.treeviewer.TreeFrameI;
 import jalview.ext.treeviewer.TreeI;
 import jalview.ext.treeviewer.TreeNodeI;
@@ -23,6 +24,7 @@ public class Tree implements TreeI
   {
     tree = new Phylogeny();
   }
+
   public Tree(Phylogeny aptxTree)
   {
     tree = aptxTree;
@@ -150,5 +152,31 @@ public class Tree implements TreeI
             instanceTitle));
   }
 
+  @Override
+  public SequenceI[] getNodeSequences()
+  {
+    SequenceI[] treeSeqs = new SequenceI[tree.getNodeCount()];
+    Iterator<TreeNodeI> iter = iterateInPreOrder();
+    int i = 0;
+    while (iter.hasNext())
+    {
+      SequenceI nodeSeq = iter.next().getSequence();
+      treeSeqs[i++] = nodeSeq;
+    }
+    return treeSeqs;
+  }
+
+  @Override
+  public TreeNodeI[] getAllNodes()
+  {
+    TreeNodeI[] treeNodes = new TreeNodeI[tree.getNodeCount()];
+    Iterator<TreeNodeI> iter = iterateInPreOrder();
+    int i = 0;
+    while (iter.hasNext())
+    {
+      treeNodes[i++] = iter.next();
+    }
+    return treeNodes;
+  }
 
 }
index 0ebf991..9bc20da 100644 (file)
@@ -1,5 +1,7 @@
 package jalview.ext.treeviewer;
 
+import jalview.datamodel.SequenceI;
+
 import java.util.Iterator;
 
 public interface TreeI
@@ -10,8 +12,12 @@ public interface TreeI
 
   public TreeNodeI getFurthestNode();
 
+  public TreeNodeI[] getAllNodes();
+
   public String[] getAllLeafNames();
 
+  public SequenceI[] getNodeSequences();
+
   public void setTreeName(String treeTitle);
 
   public void setRerootable(boolean b);