applied 2009 GPL license
[jalview.git] / src / jalview / io / vamsas / Tree.java
index 8ff825c..b164767 100644 (file)
@@ -1,3 +1,21 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.0.b2)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
 package jalview.io.vamsas;
 
 import java.io.IOException;
@@ -168,7 +186,7 @@ public class Tree extends DatastoreItem
       prov.getEntry(0).getParam(0).setName("treeType");
       prov.getEntry(0).getParam(0).setType("utf8");
       prov.getEntry(0).getParam(0).setContent("NJ"); // TODO: type of tree is a
-                                                      // general parameter
+      // general parameter
       int ranges[] = tp.getTree().seqData.getVisibleContigs();
       // VisibleContigs are with respect to alignment coordinates. Still need
       // offsets
@@ -231,12 +249,18 @@ public class Tree extends DatastoreItem
    */
   public void UpdateSequenceTreeMap(TreePanel tp)
   {
-    if (tp == null || tree != null)
+    if (tp == null || tree == null)
       return;
     Vector leaves = new Vector();
+    if (tp.getTree() == null)
+    {
+      Cache.log.warn("Not updating SequenceTreeMap for "
+              + tree.getVorbaId());
+      return;
+    }
     tp.getTree().findLeaves(tp.getTree().getTopNode(), leaves);
     Treenode[] tn = tree.getTreenode(); // todo: select nodes for this
-                                        // particular tree
+    // particular tree
     int sz = tn.length;
     int i = 0;
 
@@ -246,7 +270,7 @@ public class Tree extends DatastoreItem
       BinaryNode mappednode = findNodeSpec(node.getNodespec(), leaves);
       if (mappednode != null && mappednode instanceof SequenceNode)
       {
-        SequenceNode leaf = (SequenceNode) leaves.elementAt(i++);
+        SequenceNode leaf = (SequenceNode) mappednode;
         // check if we can make the specified association
         Object jvseq = null;
         int vrf = 0, refv = 0;
@@ -288,7 +312,7 @@ public class Tree extends DatastoreItem
    * construct treenode mappings for mapped sequences
    * 
    * @param ntree
-   * @param newick 
+   * @param newick
    * @return
    */
   public Treenode[] makeTreeNodes(NJTree ntree, Newick newick)
@@ -426,7 +450,7 @@ public class Tree extends DatastoreItem
    * referenced in input data has already been associated with jalview objects.
    * 
    * @param tp
-   * @param alignFrame 
+   * @param alignFrame
    * @return Object[] { AlignmentView, AlignmentI - reference alignment for
    *         input }
    */
@@ -450,7 +474,8 @@ public class Tree extends DatastoreItem
         // is this the whole alignment or a specific set of sequences ?
         if (vInput.getObjRefCount() == 0)
         {
-          if (tree.getV_parent()!=null && tree.getV_parent() instanceof uk.ac.vamsas.objects.core.Alignment)
+          if (tree.getV_parent() != null
+                  && tree.getV_parent() instanceof uk.ac.vamsas.objects.core.Alignment)
           {
             javport = getViewport(tree.getV_parent());
             jal = javport.getAlignment();
@@ -471,7 +496,8 @@ public class Tree extends DatastoreItem
           else if (vInput.getObjRef(0) instanceof uk.ac.vamsas.objects.core.AlignmentSequence)
           {
             // recover an AlignmentView for the input data
-            javport = getViewport(((Vobject) vInput.getObjRef(0)).getV_parent());
+            javport = getViewport(((Vobject) vInput.getObjRef(0))
+                    .getV_parent());
             jal = javport.getAlignment();
             jalview.datamodel.SequenceI[] seqs = new jalview.datamodel.SequenceI[vInput
                     .getObjRefCount()];
@@ -553,6 +579,10 @@ public class Tree extends DatastoreItem
   {
     try
     {
+      if (ntree == null)
+      {
+        return false;
+      }
       ntree.parse();
       if (ntree.getTree() != null)
       {