refactored syncing of alignment sequences - still buggy
authorjprocter <Jim Procter>
Mon, 5 Nov 2007 16:42:19 +0000 (16:42 +0000)
committerjprocter <Jim Procter>
Mon, 5 Nov 2007 16:42:19 +0000 (16:42 +0000)
src/jalview/io/VamsasAppDatastore.java

index 8f26680..82e9fba 100644 (file)
@@ -59,17 +59,18 @@ public class VamsasAppDatastore
   public static final String JALVIEW_ANNOTATION_ROW = "JalviewAnnotation";
 
   /**
-   * AlignmentAnnotation property to indicate that values should not be interpolated
+   * AlignmentAnnotation property to indicate that values should not be
+   * interpolated
    */
   public static final String DISCRETE_ANNOTATION = "discrete";
+
   /**
-   * continuous property - optional to specify that annotation should be represented
-   * as a continous graph line
+   * continuous property - optional to specify that annotation should be
+   * represented as a continous graph line
    */
   private static final String CONTINUOUS_ANNOTATION = "continuous";
 
-  private static final String THRESHOLD = "threshold"; 
-  
+  private static final String THRESHOLD = "threshold";
 
   Entry provEntry = null;
 
@@ -88,7 +89,7 @@ public class VamsasAppDatastore
     this.vobj2jv = vobj2jv;
     this.jv2vobj = jv2vobj;
     this.provEntry = provEntry;
-    this.alignRDHash = alignRDHash; 
+    this.alignRDHash = alignRDHash;
   }
 
   /**
@@ -178,9 +179,9 @@ public class VamsasAppDatastore
    * put the alignment viewed by AlignViewport into cdoc.
    * 
    * @param av
-   *          alignViewport to be stored
+   *                alignViewport to be stored
    * @param aFtitle
-   *          title for alignment
+   *                title for alignment
    */
   public void storeVAMSAS(AlignViewport av, String aFtitle)
   {
@@ -280,14 +281,19 @@ public class VamsasAppDatastore
         {
           boolean dsmod = false;
           // verify and update principal attributes.
-          if (sq.getDescription()!=null && (sequence.getDescription()==null || !sequence.getDescription().equals(sq.getDescription())))
+          if (sq.getDescription() != null
+                  && (sequence.getDescription() == null || !sequence
+                          .getDescription().equals(sq.getDescription())))
           {
             sequence.setDescription(sq.getDescription());
             dsmod = true;
           }
-          if (sequence.getSequence()==null || !sequence.getSequence().equals(sq.getSequenceAsString()))
+          if (sequence.getSequence() == null
+                  || !sequence.getSequence().equals(
+                          sq.getSequenceAsString()))
           {
-            if (sequence.getStart()!=sq.getStart() || sequence.getEnd()!=sq.getEnd())
+            if (sequence.getStart() != sq.getStart()
+                    || sequence.getEnd() != sq.getEnd())
             {
               // update modified sequence.
               sequence.setSequence(sq.getSequenceAsString());
@@ -297,7 +303,7 @@ public class VamsasAppDatastore
             }
           }
           if (!dict.equals(sequence.getDictionary()))
-          { 
+          {
             sequence.setDictionary(dict);
             dsmod = true;
           }
@@ -318,7 +324,7 @@ public class VamsasAppDatastore
 
           for (int sf = 0; sf < sfSize; sf++)
           {
-            // TODO: update/modifiable synchronizer 
+            // TODO: update/modifiable synchronizer
             jalview.datamodel.SequenceFeature feature = (jalview.datamodel.SequenceFeature) sq
                     .getSequenceFeatures()[sf];
 
@@ -334,7 +340,7 @@ public class VamsasAppDatastore
               addProvenance(dsa.getProvenance(), "created"); // JBPNote - need
               // to update
               dsa.addSeqRef(sequence); // we have just created this annotation
-                                        // - so safe to use this
+              // - so safe to use this
               bindjvvobj(feature, dsa);
               dataset.addDataSetAnnotations(dsa);
             }
@@ -358,25 +364,38 @@ public class VamsasAppDatastore
 
         }
       }
-      if (dssmods.size()>0)
+      if (dssmods.size() > 0)
       {
         if (!nw)
         {
-          Entry pentry = this.addProvenance(dataset.getProvenance(), "updated sequences");
-          // pentry.addInput(vInput); could write in which sequences were modified.
+          Entry pentry = this.addProvenance(dataset.getProvenance(),
+                  "updated sequences");
+          // pentry.addInput(vInput); could write in which sequences were
+          // modified.
           dssmods.removeAllElements();
         }
       }
       // dataset.setProvenance(getVamsasProvenance(jal.getDataset().getProvenance()));
       // ////////////////////////////////////////////
       if (!av.getAlignment().isAligned())
-        return; // TODO: trees could be written - but for the moment we just skip
+        return; // TODO: trees could be written - but for the moment we just
+                // skip
       // ////////////////////////////////////////////
       // Save the Alignments
 
-      Alignment alignment = (Alignment) getjv2vObj(av.getSequenceSetId()); // this is so we can get
-                                                        // the alignviewport
-                                                        // back
+      Alignment alignment = (Alignment) getjv2vObj(av.getSequenceSetId()); // bind
+                                                                            // to
+                                                                            // the
+                                                                            // value
+                                                                            // used
+                                                                            // to
+                                                                            // associate
+                                                                            // different
+                                                                            // views
+                                                                            // to
+                                                                            // same
+                                                                            // alignment
+
       if (alignment == null)
       {
         alignment = new Alignment();
@@ -399,38 +418,74 @@ public class VamsasAppDatastore
         alignment.setGapChar(String.valueOf(av.getGapCharacter()));
         for (int i = 0; i < jal.getHeight(); i++)
         {
-          syncToAlignmentSequence(jal.getSequenceAt(i), alignment);
+          syncToAlignmentSequence(jal.getSequenceAt(i), alignment, null);
         }
-        alignRDHash.put(av.getSequenceSetId(),av.getUndoRedoHash());
+        alignRDHash.put(av.getSequenceSetId(), av.getUndoRedoHash());
       }
       else
       {
-        boolean alismod = av.isUndoRedoHashModified((long[]) alignRDHash.get(av.getSequenceSetId()));
+        // always prepare to clone the alignment
+        boolean alismod = av.isUndoRedoHashModified((long[]) alignRDHash
+                .get(av.getSequenceSetId()));
         // todo: verify and update mutable alignment props.
         // TODO: Use isLocked methods
-        if (alignment.getModifiable() == null || alignment.getModifiable().length()==0)
+        if (alignment.getModifiable() == null
+                || alignment.getModifiable().length() == 0)
+        // && !alignment.isDependedOn())
         {
           boolean modified = false;
+          // check existing sequences in local and in document.
+          Vector docseqs = new Vector(alignment
+                  .getAlignmentSequenceAsReference());
           for (int i = 0; i < jal.getHeight(); i++)
           {
-            modified |= syncToAlignmentSequence(jal.getSequenceAt(i), alignment);
+            modified |= syncToAlignmentSequence(jal.getSequenceAt(i),
+                    alignment, docseqs);
+          }
+          if (docseqs.size() > 0)
+          {
+            // removeValignmentSequences(alignment, docseqs);
+            docseqs.removeAllElements();
+            System.out
+                    .println("Sequence deletion from alignment is not implemented.");
+
           }
           if (modified)
           {
             if (alismod)
             {
               // info in the undo
-              addProvenance(alignment.getProvenance(), "Edited"); // TODO: insert something sensible here again 
-                      }
-            else {
+              addProvenance(alignment.getProvenance(), "Edited"); // TODO:
+                                                                  // insert
+                                                                  // something
+                                                                  // sensible
+                                                                  // here again
+            }
+            else
+            {
               // info in the undo
-              addProvenance(alignment.getProvenance(), "Attributes Edited"); // TODO: insert something sensible here again 
+              addProvenance(alignment.getProvenance(), "Attributes Edited"); // TODO:
+                                                                              // insert
+                                                                              // something
+                                                                              // sensible
+                                                                              // here
+                                                                              // again
             }
           }
-          System.out.println("update alignment in document.");
+          if (alismod)
+          {
+            System.out.println("update alignment in document.");
+          }
+          else
+          {
+            System.out.println("alignment in document left unchanged.");
+          }
         }
         else
         {
+          // unbind alignment from view.
+          // create new binding and new alignment.
+          // mark trail on new alignment as being derived from old ?
           System.out
                   .println("update edited alignment to new alignment in document.");
         }
@@ -462,8 +517,7 @@ public class VamsasAppDatastore
            * if (valseqf.getProvenance() == null) { valseqf.setProvenance(new
            * Provenance()); } addProvenance(valseqf.getProvenance(), "created"); //
            * JBPNote - // need to // update bindjvvobj(features[i], valseqf);
-           * valseq.addAlignmentSequenceAnnotation(valseqf); } }
-           *  }
+           * valseq.addAlignmentSequenceAnnotation(valseqf); } } }
            */
         }
       }
@@ -525,8 +579,8 @@ public class VamsasAppDatastore
               an.setDescription(aa[i].description);
               alignment.addAlignmentAnnotation(an);
               Seg vSeg = new Seg(); // TODO: refactor to have a default
-                                    // rangeAnnotationType initer/updater that
-                                    // takes a set of int ranges.
+              // rangeAnnotationType initer/updater that
+              // takes a set of int ranges.
               vSeg.setStart(1);
               vSeg.setInclusive(true);
               vSeg.setEnd(jal.getWidth());
@@ -540,7 +594,7 @@ public class VamsasAppDatastore
               if (aa[i].graph != AlignmentAnnotation.NO_GRAPH)
               {
                 an.setGroup(Integer.toString(aa[i].graphGroup)); // // JBPNote
-                                                                  // -
+                // -
                 // originally we
                 // were going to
                 // store
@@ -596,23 +650,29 @@ public class VamsasAppDatastore
                 // modifiable flag is supposed to be used.
               }
               setAnnotationType(an, aa[i]);
-              
+
               if (aa[i].graph != jalview.datamodel.AlignmentAnnotation.NO_GRAPH)
               {
                 an.setGraph(true);
                 an.setGroup(Integer.toString(aa[i].graphGroup));
-                if (aa[i].threshold!=null && aa[i].threshold.displayed)
-                  an.addProperty(newProperty(THRESHOLD, "float", ""+aa[i].threshold.value));
-                  if (aa[i].threshold.label!=null)
-                    an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+aa[i].threshold.label));
+                if (aa[i].threshold != null && aa[i].threshold.displayed)
+                {
+                  an.addProperty(newProperty(THRESHOLD, "float", ""
+                          + aa[i].threshold.value));
+                  if (aa[i].threshold.label != null)
+                  {
+                    an.addProperty(newProperty(THRESHOLD + "Name",
+                            "string", "" + aa[i].threshold.label));
+                  }
                 }
-              
               }
-            
+
+            }
+
             else
             {
               if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT
-                                              // LOCK METHODS)
+              // LOCK METHODS)
               {
                 // verify annotation - update (perhaps)
                 Cache.log
@@ -663,24 +723,101 @@ public class VamsasAppDatastore
     }
 
   }
+
+  /**
+   * remove docseqs from the given alignment marking provenance appropriately
+   * and removing any references to the sequences.
+   * 
+   * @param alignment
+   * @param docseqs
+   */
+  private void removeValignmentSequences(Alignment alignment, Vector docseqs)
+  {
+    // delete these from document. This really needs to be a generic document
+    // API function derived by CASTOR.
+    Enumeration en = docseqs.elements();
+    while (en.hasMoreElements())
+    {
+      alignment.removeAlignmentSequence((AlignmentSequence) en
+              .nextElement());
+    }
+    Entry pe = addProvenance(alignment.getProvenance(), "Removed "
+            + docseqs.size() + " sequences");
+    en = alignment.enumerateAlignmentAnnotation();
+    Vector toremove = new Vector();
+    while (en.hasMoreElements())
+    {
+      uk.ac.vamsas.objects.core.AlignmentAnnotation alan = (uk.ac.vamsas.objects.core.AlignmentAnnotation) en
+              .nextElement();
+      if (alan.getSeqrefsCount() > 0)
+      {
+        int p = 0;
+        Vector storem = new Vector();
+        Enumeration sr = alan.enumerateSeqrefs();
+        while (sr.hasMoreElements())
+        {
+          Object alsr = sr.nextElement();
+          if (docseqs.contains(alsr))
+          {
+            storem.addElement(alsr);
+          }
+        }
+        // remove references to the deleted sequences
+        sr = storem.elements();
+        while (sr.hasMoreElements())
+        {
+          alan.removeSeqrefs(sr.nextElement());
+        }
+
+        if (alan.getSeqrefsCount() == 0)
+        {
+          // should then delete alan from dataset
+          toremove.addElement(alan);
+        }
+      }
+    }
+    // remove any annotation that used to be associated to a specific bunch of
+    // sequences
+    en = toremove.elements();
+    while (en.hasMoreElements())
+    {
+      alignment
+              .removeAlignmentAnnotation((uk.ac.vamsas.objects.core.AlignmentAnnotation) en
+                      .nextElement());
+    }
+    // TODO: search through alignment annotations to remove any references to
+    // this alignment sequence
+  }
+
   /**
-   *  sync a jalview alignment seuqence into a vamsas alignment
-   *  assumes all lock transformation/bindings have been sorted out before hand.
-   *  creates/syncs the vamsas alignment sequence for jvalsq and adds it to the alignment if necessary.
+   * sync a jalview alignment seuqence into a vamsas alignment assumes all lock
+   * transformation/bindings have been sorted out before hand. creates/syncs the
+   * vamsas alignment sequence for jvalsq and adds it to the alignment if
+   * necessary. unbounddocseq is a duplicate of the vamsas alignment sequences
+   * and these are removed after being processed w.r.t a bound jvalsq
+   * 
    */
   private boolean syncToAlignmentSequence(SequenceI jvalsq,
-          Alignment alignment)
+          Alignment alignment, Vector unbounddocseq)
   {
     boolean modal = false;
     // todo: islocked method here
-    boolean up2doc=false;
+    boolean up2doc = false;
     AlignmentSequence alseq = (AlignmentSequence) getjv2vObj(jvalsq);
-    if (alseq==null)
+    if (alseq == null)
     {
       alseq = new AlignmentSequence();
       up2doc = true;
     }
-    // boolean locked = (alignment.getModifiable()==null || alignment.getModifiable().length()>0);
+    else
+    {
+      if (unbounddocseq != null)
+      {
+        unbounddocseq.removeElement(alseq);
+      }
+    }
+    // boolean locked = (alignment.getModifiable()==null ||
+    // alignment.getModifiable().length()>0);
     // TODO: VAMSAS: translate lowercase symbols to annotation ?
     if (up2doc || !alseq.getSequence().equals(jvalsq.getSequenceAsString()))
     {
@@ -694,7 +831,9 @@ public class VamsasAppDatastore
       modal = true;
       alseq.setName(jvalsq.getName());
     }
-    if (jvalsq.getDescription()!=null && (alseq.getDescription()==null || !jvalsq.getDescription().equals(alseq.getDescription())))
+    if (jvalsq.getDescription() != null
+            && (alseq.getDescription() == null || !jvalsq.getDescription()
+                    .equals(alseq.getDescription())))
     {
       modal = true;
       alseq.setDescription(jvalsq.getDescription());
@@ -702,41 +841,44 @@ public class VamsasAppDatastore
     if (getjv2vObj(jvalsq.getDatasetSequence()) == null)
     {
       Cache.log
-      .warn("Serious Implementation error - Unbound dataset sequence in alignment: "
-              + jvalsq.getDatasetSequence());
+              .warn("Serious Implementation error - Unbound dataset sequence in alignment: "
+                      + jvalsq.getDatasetSequence());
     }
-    alseq.setRefid(getjv2vObj(jvalsq
-            .getDatasetSequence()));
+    alseq.setRefid(getjv2vObj(jvalsq.getDatasetSequence()));
     if (up2doc)
     {
-      
+
       alignment.addAlignmentSequence(alseq);
       bindjvvobj(jvalsq, alseq);
     }
     return up2doc || modal;
   }
+
   /**
-   *  locally sync a jalview alignment seuqence from a vamsas alignment
-   *  assumes all lock transformation/bindings have been sorted out before hand.
-   *  creates/syncs the jvalsq from the alignment sequence
+   * locally sync a jalview alignment seuqence from a vamsas alignment assumes
+   * all lock transformation/bindings have been sorted out before hand.
+   * creates/syncs the jvalsq from the alignment sequence
    */
-  private boolean syncFromAlignmentSequence(AlignmentSequence valseq, char valGapchar, char gapChar, Vector dsseqs)
-          
+  private boolean syncFromAlignmentSequence(AlignmentSequence valseq,
+          char valGapchar, char gapChar, Vector dsseqs)
+
   {
     boolean modal = false;
     // todo: islocked method here
-    boolean upFromdoc=false;
+    boolean upFromdoc = false;
     jalview.datamodel.SequenceI alseq = (SequenceI) getvObj2jv(valseq);
-    if (alseq==null)
+    if (alseq == null)
     {
       upFromdoc = true;
     }
     if (alseq != null)
     {
 
-      // boolean locked = (alignment.getModifiable()==null || alignment.getModifiable().length()>0);
+      // boolean locked = (alignment.getModifiable()==null ||
+      // alignment.getModifiable().length()>0);
       // TODO: VAMSAS: translate lowercase symbols to annotation ?
-      if (upFromdoc || !valseq.getSequence().equals(alseq.getSequenceAsString()))
+      if (upFromdoc
+              || !valseq.getSequence().equals(alseq.getSequenceAsString()))
       {
         // this might go *horribly* wrong
         alseq.setSequence(new String(valseq.getSequence()).replace(
@@ -750,9 +892,9 @@ public class VamsasAppDatastore
         modal = true;
         alseq.setName(valseq.getName());
       }
-      if (alseq.getDescription()==null 
-              || (valseq.getDescription()==null 
-                      || alseq.getDescription().equals(valseq.getDescription())))
+      if (alseq.getDescription() == null
+              || (valseq.getDescription() == null || alseq.getDescription()
+                      .equals(valseq.getDescription())))
       {
         alseq.setDescription(valseq.getDescription());
         modal = true;
@@ -765,22 +907,21 @@ public class VamsasAppDatastore
     }
     else
     {
-      alseq = new jalview.datamodel.Sequence(valseq.getName(),
-              valseq.getSequence().replace(valGapchar, gapChar),
-              (int) valseq.getStart(), (int) valseq.getEnd());
+      alseq = new jalview.datamodel.Sequence(valseq.getName(), valseq
+              .getSequence().replace(valGapchar, gapChar), (int) valseq
+              .getStart(), (int) valseq.getEnd());
 
       Vobject datsetseq = (Vobject) valseq.getRefid();
       if (datsetseq != null)
       {
-        alseq
-                .setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
-                                                                        // if
-                                                                        // AlignemntSequence
-                                                                        // reference
-                                                                        // isn't
-                                                                        // a
-                                                                        // simple
-                                                                        // SequenceI
+        alseq.setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
+        // if
+        // AlignemntSequence
+        // reference
+        // isn't
+        // a
+        // simple
+        // SequenceI
       }
       else
       {
@@ -799,8 +940,7 @@ public class VamsasAppDatastore
       {
         modal = true;
       }
-      alseq
-              .setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
+      alseq.setDatasetSequence((SequenceI) getvObj2jv(datsetseq)); // exceptions
     }
     return upFromdoc || modal;
   }
@@ -893,11 +1033,13 @@ public class VamsasAppDatastore
       // the Jalview
       // specific
       // bits.
-      if (alan.getThreshold()!=null && alan.getThreshold().displayed)
+      if (alan.getThreshold() != null && alan.getThreshold().displayed)
       {
-        an.addProperty(newProperty(THRESHOLD, "float", ""+alan.getThreshold().value));
-        if (alan.getThreshold().label!=null)
-          an.addProperty(newProperty(THRESHOLD+"Name", "string", ""+alan.getThreshold().label));
+        an.addProperty(newProperty(THRESHOLD, "float", ""
+                + alan.getThreshold().value));
+        if (alan.getThreshold().label != null)
+          an.addProperty(newProperty(THRESHOLD + "Name", "string", ""
+                  + alan.getThreshold().label));
       }
       ((DataSet) sref.getV_parent()).addDataSetAnnotations(an);
       bindjvvobj(alan, an);
@@ -906,7 +1048,7 @@ public class VamsasAppDatastore
     {
       // update reference sequence Annotation
       if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
-                                      // METHODS)
+      // METHODS)
       {
         // verify existing alignment sequence annotation is up to date
         System.out.println("update dataset sequence annotation.");
@@ -960,7 +1102,7 @@ public class VamsasAppDatastore
        * something extracted from another program, etc)
        */
       an.setType(JALVIEW_ANNOTATION_ROW); // TODO: better fix
-                                                          // this rough guess ;)
+      // this rough guess ;)
       alsref.addAlignmentSequenceAnnotation(an);
       bindjvvobj(alan, an);
       // These properties are directly supported by the
@@ -974,7 +1116,7 @@ public class VamsasAppDatastore
     {
       // update reference sequence Annotation
       if (an.getModifiable() == null) // TODO: USE VAMSAS LIBRARY OBJECT LOCK
-                                      // METHODS)
+      // METHODS)
       {
         // verify existing alignment sequence annotation is up to date
         System.out.println("update alignment sequence annotation.");
@@ -990,41 +1132,46 @@ public class VamsasAppDatastore
 
   /**
    * set vamsas annotation object type from jalview annotation
+   * 
    * @param an
    * @param alan
    */
-  private void setAnnotationType(RangeAnnotation an, AlignmentAnnotation alan)
+  private void setAnnotationType(RangeAnnotation an,
+          AlignmentAnnotation alan)
   {
     if (an instanceof AlignmentSequenceAnnotation)
     {
       if (alan.graph != AlignmentAnnotation.NO_GRAPH)
       {
-        ((AlignmentSequenceAnnotation)an).setGraph(true);
-      } else
+        ((AlignmentSequenceAnnotation) an).setGraph(true);
+      }
+      else
       {
-      ((AlignmentSequenceAnnotation)an).setGraph(false);
+        ((AlignmentSequenceAnnotation) an).setGraph(false);
       }
     }
     if (an instanceof uk.ac.vamsas.objects.core.AlignmentAnnotation)
     {
       if (alan.graph != AlignmentAnnotation.NO_GRAPH)
       {
-        ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(true);
-      } else
+        ((uk.ac.vamsas.objects.core.AlignmentAnnotation) an).setGraph(true);
+      }
+      else
       {
-      ((uk.ac.vamsas.objects.core.AlignmentAnnotation)an).setGraph(false);
+        ((uk.ac.vamsas.objects.core.AlignmentAnnotation) an)
+                .setGraph(false);
       }
     }
     switch (alan.graph)
     {
-      case AlignmentAnnotation.BAR_GRAPH:
-        an.addProperty(newProperty(DISCRETE_ANNOTATION, "boolean","true"));
-        break;
-      case AlignmentAnnotation.LINE_GRAPH:
-        an.addProperty(newProperty(CONTINUOUS_ANNOTATION, "boolean","true"));
-        break;
-        default:
-          // don't add any kind of discrete or continous property info.
+    case AlignmentAnnotation.BAR_GRAPH:
+      an.addProperty(newProperty(DISCRETE_ANNOTATION, "boolean", "true"));
+      break;
+    case AlignmentAnnotation.LINE_GRAPH:
+      an.addProperty(newProperty(CONTINUOUS_ANNOTATION, "boolean", "true"));
+      break;
+    default:
+      // don't add any kind of discrete or continous property info.
     }
   }
 
@@ -1048,9 +1195,10 @@ public class VamsasAppDatastore
    * correctly create a RangeAnnotation from a jalview sequence feature
    * 
    * @param dsa
-   *          (typically DataSetAnnotations or AlignmentSequenceAnnotation)
+   *                (typically DataSetAnnotations or
+   *                AlignmentSequenceAnnotation)
    * @param feature
-   *          (the feature to be mapped from)
+   *                (the feature to be mapped from)
    * @return
    */
   private RangeAnnotation getDSAnnotationFromJalview(RangeAnnotation dsa,
@@ -1096,7 +1244,7 @@ public class VamsasAppDatastore
    * 
    * @param visSeg
    * @param ensureDirection
-   *          when true - always ensure start is less than end.
+   *                when true - always ensure start is less than end.
    * @return int[] { start, end, direction} where direction==1 for range running
    *         from end to start.
    */
@@ -1252,7 +1400,7 @@ public class VamsasAppDatastore
             {
               SequenceI dsSeq = (SequenceI) getvObj2jv((Vobject) dseta
                       .getSeqRef(0)); // TODO: deal with group dataset
-                                      // annotations
+              // annotations
               if (dsSeq == null)
               {
                 jalview.bin.Cache.log
@@ -1295,8 +1443,8 @@ public class VamsasAppDatastore
           {
             uk.ac.vamsas.objects.core.Alignment alignment = dataset
                     .getAlignment(al);
-            AlignViewport av=findViewport(alignment);
-            
+            AlignViewport av = findViewport(alignment);
+
             jalview.datamodel.AlignmentI jal = null;
             if (av != null)
             {
@@ -1307,7 +1455,7 @@ public class VamsasAppDatastore
             boolean refreshal = false;
             Vector newasAnnots = new Vector();
             char gapChar = ' '; // default for new alignments read in from the
-                                // document
+            // document
             if (jal != null)
             {
               dsseqs = jal.getSequences(); // for merge/update
@@ -1322,9 +1470,11 @@ public class VamsasAppDatastore
             {
               AlignmentSequence valseq = alignment.getAlignmentSequence(i);
               jalview.datamodel.Sequence alseq = (jalview.datamodel.Sequence) getvObj2jv(valseq);
-              if (syncFromAlignmentSequence(valseq, valGapchar, gapChar, dsseqs) && alseq!=null)
+              if (syncFromAlignmentSequence(valseq, valGapchar, gapChar,
+                      dsseqs)
+                      && alseq != null)
               {
-                
+
                 // updated to sequence from the document
                 jremain--;
                 refreshal = true;
@@ -1336,27 +1486,27 @@ public class VamsasAppDatastore
                 for (int a = 0; a < vasannot.length; a++)
                 {
                   jalview.datamodel.AlignmentAnnotation asa = (jalview.datamodel.AlignmentAnnotation) getvObj2jv(vasannot[a]); // TODO:
-                                                                                                                                // 1:many
-                                                                                                                                // jalview
-                                                                                                                                // alignment
-                                                                                                                                // sequence
-                                                                                                                                // annotations
+                  // 1:many
+                  // jalview
+                  // alignment
+                  // sequence
+                  // annotations
                   if (asa == null)
                   {
                     int se[] = getBounds(vasannot[a]);
                     asa = getjAlignmentAnnotation(jal, vasannot[a]);
                     asa.setSequenceRef(alseq);
                     asa.createSequenceMapping(alseq, se[0], false); // TODO:
-                                                                    // verify
-                                                                    // that
-                                                                    // positions
-                                                                    // in
-                                                                    // alseqAnnotation
-                                                                    // correspond
-                                                                    // to
-                                                                    // ungapped
-                                                                    // residue
-                                                                    // positions.
+                    // verify
+                    // that
+                    // positions
+                    // in
+                    // alseqAnnotation
+                    // correspond
+                    // to
+                    // ungapped
+                    // residue
+                    // positions.
                     alseq.addAlignmentAnnotation(asa);
                     bindjvvobj(asa, vasannot[a]);
                     newasAnnots.add(asa);
@@ -1365,9 +1515,9 @@ public class VamsasAppDatastore
                   {
                     // update existing annotation - can do this in place
                     if (vasannot[a].getModifiable() == null) // TODO: USE
-                                                              // VAMSAS LIBRARY
-                                                              // OBJECT LOCK
-                                                              // METHODS)
+                    // VAMSAS LIBRARY
+                    // OBJECT LOCK
+                    // METHODS)
                     {
                       Cache.log
                               .info("UNIMPLEMENTED: not recovering user modifiable sequence alignment annotation");
@@ -1433,8 +1583,8 @@ public class VamsasAppDatastore
                   Cache.log
                           .debug("update from vamsas alignment annotation to existing jalview alignment annotation.");
                   if (an[j].getModifiable() == null) // TODO: USE VAMSAS
-                                                      // LIBRARY OBJECT LOCK
-                                                      // METHODS)
+                  // LIBRARY OBJECT LOCK
+                  // METHODS)
                   {
                     // TODO: user defined annotation is totally mutable... - so
                     // load it up or throw away if locally edited.
@@ -1469,8 +1619,7 @@ public class VamsasAppDatastore
               {
                 for (int p = 0, pe = alignment.getPropertyCount(); p < pe; p++)
                 {
-                  if (alignment.getProperty(p).getName().equals(
-                          "title"))
+                  if (alignment.getProperty(p).getName().equals("title"))
                   {
                     title = alignment.getProperty(p).getContent();
                   }
@@ -1480,12 +1629,10 @@ public class VamsasAppDatastore
               // alignment using its provenance.
               if (Cache.log.isDebugEnabled())
               {
-                title = title + "("
-                 + alignment.getVorbaId() + ")";
-                
+                title = title + "(" + alignment.getVorbaId() + ")";
+
               }
-              jalview.gui.Desktop.addInternalFrame(alignFrame, title 
-                      ,
+              jalview.gui.Desktop.addInternalFrame(alignFrame, title,
                       AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
               bindjvvobj(av.getSequenceSetId(), alignment);
             }
@@ -1511,27 +1658,28 @@ public class VamsasAppDatastore
                         this, alignFrame, alignment.getTree(t));
                 TreePanel tp = null;
                 if (vstree.isValidTree())
-                { 
-                  tp = alignFrame
-                        .ShowNewickTree(vstree.getNewickTree(), vstree
-                                .getTitle(), vstree.getInputData(), 600,
-                                500, t * 20 + 50, t * 20 + 50);
-                  
+                {
+                  tp = alignFrame.ShowNewickTree(vstree.getNewickTree(),
+                          vstree.getTitle(), vstree.getInputData(), 600,
+                          500, t * 20 + 50, t * 20 + 50);
+
                 }
-                if (tp!=null)
-                { 
+                if (tp != null)
+                {
                   bindjvvobj(tp, alignment.getTree(t));
                   try
                   {
                     vstree.UpdateSequenceTreeMap(tp);
                   } catch (RuntimeException e)
                   {
-                    Cache.log.warn("update of labels failed.",e);
+                    Cache.log.warn("update of labels failed.", e);
                   }
                 }
                 else
                 {
-                  Cache.log.warn("Cannot create tree for tree "+t+" in document ("+alignment.getTree(t).getVorbaId());
+                  Cache.log.warn("Cannot create tree for tree " + t
+                          + " in document ("
+                          + alignment.getTree(t).getVorbaId());
                 }
 
               }
@@ -1558,9 +1706,9 @@ public class VamsasAppDatastore
 
   public AlignViewport findViewport(Alignment alignment)
   {
-    AlignViewport av=null;
-    AlignViewport[] avs = findViewportForSequenceSetId((String)getvObj2jv(alignment));
-    if (avs!=null)
+    AlignViewport av = null;
+    AlignViewport[] avs = findViewportForSequenceSetId((String) getvObj2jv(alignment));
+    if (avs != null)
     {
       av = avs[0];
     }
@@ -1578,13 +1726,14 @@ public class VamsasAppDatastore
       {
         if (frames[t] instanceof AlignFrame)
         {
-          if (((AlignFrame) frames[t]).getViewport().getSequenceSetId().equals(sequenceSetId))
+          if (((AlignFrame) frames[t]).getViewport().getSequenceSetId()
+                  .equals(sequenceSetId))
           {
             viewp.addElement(((AlignFrame) frames[t]).getViewport());
           }
         }
       }
-      if (viewp.size()>0)
+      if (viewp.size() > 0)
       {
         AlignViewport[] vp = new AlignViewport[viewp.size()];
         viewp.copyInto(vp);
@@ -1635,7 +1784,7 @@ public class VamsasAppDatastore
     { new jalview.datamodel.Annotation[rangeMap.length],
         new jalview.datamodel.Annotation[rangeMap.length] };
     boolean mergeable = true; // false if 'after positions cant be placed on
-                              // same annotation row as positions.
+    // same annotation row as positions.
 
     if (annotation.getAnnotationElementCount() > 0)
     {
@@ -1643,7 +1792,7 @@ public class VamsasAppDatastore
       for (int aa = 0; aa < ae.length; aa++)
       {
         int pos = (int) ae[aa].getPosition() - 1; // pos counts from 1 to
-                                                  // (|seg.start-seg.end|+1)
+        // (|seg.start-seg.end|+1)
         if (pos >= 0 && pos < rangeMap.length)
         {
           int row = ae[aa].getAfter() ? 1 : 0;
@@ -1668,9 +1817,9 @@ public class VamsasAppDatastore
             }
           }
           String dc = null; // ae[aa].getDisplayCharacter()==null ? "dc" :
-                            // ae[aa].getDisplayCharacter();
+          // ae[aa].getDisplayCharacter();
           String ss = null; // ae[aa].getSecondaryStructure()==null ? "ss" :
-                            // ae[aa].getSecondaryStructure();
+          // ae[aa].getSecondaryStructure();
           java.awt.Color colour = null;
           if (ae[aa].getGlyphCount() > 0)
           {
@@ -1706,8 +1855,9 @@ public class VamsasAppDatastore
               }
               else
               {
-                Cache.log.debug("IMPLEMENTATION TODO: Ignoring unknown glyph type "
-                        + glyphs[g].getDict());
+                Cache.log
+                        .debug("IMPLEMENTATION TODO: Ignoring unknown glyph type "
+                                + glyphs[g].getDict());
               }
             }
           }
@@ -1752,7 +1902,7 @@ public class VamsasAppDatastore
             anot[0][i] = anot[1][i];
             anot[0][i].description = anot[0][i].description + " (after)";
             AeContent[HASDESCSTR] = true; // we have valid description string
-                                          // data
+            // data
             anot[1][i] = null;
           }
         }
@@ -1780,8 +1930,9 @@ public class VamsasAppDatastore
 
   /**
    * @param jal
-   *          the jalview alignment to which the annotation will be attached
-   *          (ideally - freshly updated from corresponding vamsas alignment)
+   *                the jalview alignment to which the annotation will be
+   *                attached (ideally - freshly updated from corresponding
+   *                vamsas alignment)
    * @param annotation
    * @return unbound jalview alignment annotation object.
    */
@@ -1804,46 +1955,48 @@ public class VamsasAppDatastore
     Object[] parsedRangeAnnotation = parseRangeAnnotation(annotation);
     String a_label = annotation.getLabel();
     String a_descr = annotation.getDescription();
-    GraphLine gl=null;
-    int type=0;
-    boolean interp=true; // cleared if annotation is DISCRETE
+    GraphLine gl = null;
+    int type = 0;
+    boolean interp = true; // cleared if annotation is DISCRETE
     // set type and other attributes from properties
     if (annotation.getPropertyCount() > 0)
     {
       // look for special jalview properties
-      uk.ac.vamsas.objects.core.Property[] props = annotation
-              .getProperty();
+      uk.ac.vamsas.objects.core.Property[] props = annotation.getProperty();
       for (int p = 0; p < props.length; p++)
       {
         if (props[p].getName().equalsIgnoreCase(DISCRETE_ANNOTATION))
         {
           type = AlignmentAnnotation.BAR_GRAPH;
-          interp=false;
-        } else if
-         (props[p].getName().equalsIgnoreCase(CONTINUOUS_ANNOTATION)) {
+          interp = false;
+        }
+        else if (props[p].getName().equalsIgnoreCase(CONTINUOUS_ANNOTATION))
+        {
           type = AlignmentAnnotation.LINE_GRAPH;
-        } else if
-        (props[p].getName().equalsIgnoreCase(THRESHOLD))
+        }
+        else if (props[p].getName().equalsIgnoreCase(THRESHOLD))
         {
-          Float val=null;
-          try {
+          Float val = null;
+          try
+          {
             val = new Float(props[p].getContent());
-          }catch (Exception e)
+          } catch (Exception e)
           {
             Cache.log.warn("Failed to parse threshold property");
           }
-          if (val!=null)
-          if (gl==null)
-          {
-            gl = new GraphLine(val.floatValue(), "", java.awt.Color.black);
-          } else
-          {
-            gl.value = val.floatValue();
-          }
+          if (val != null)
+            if (gl == null)
+            {
+              gl = new GraphLine(val.floatValue(), "", java.awt.Color.black);
+            }
+            else
+            {
+              gl.value = val.floatValue();
+            }
         }
-        else if (props[p].getName().equalsIgnoreCase(THRESHOLD+"Name"))
+        else if (props[p].getName().equalsIgnoreCase(THRESHOLD + "Name"))
         {
-          if (gl==null)
+          if (gl == null)
             gl = new GraphLine(0, "", java.awt.Color.black);
           gl.label = props[p].getContent();
         }
@@ -1888,9 +2041,12 @@ public class VamsasAppDatastore
        */
       if (has[HASVALS])
       {
-        if (type==0)
+        if (type == 0)
         {
-          type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH; // default type of value annotation
+          type = jalview.datamodel.AlignmentAnnotation.BAR_GRAPH; // default
+                                                                  // type of
+                                                                  // value
+                                                                  // annotation
           if (has[HASHPHOB])
           {
             // no hints - so we ensure HPHOB display is like this.
@@ -1950,17 +2106,19 @@ public class VamsasAppDatastore
             if (!has[HASDC])
             {
               if (!interp)
-                {
-                if (arow[i].description!=null && arow[i].description.length()<3)
+              {
+                if (arow[i].description != null
+                        && arow[i].description.length() < 3)
                 {
                   // copy over the description as the display char.
                   arow[i].displayCharacter = new String(arow[i].description);
                 }
-                } else
-                {
-                  // mark the position as a point used for the interpolation.
+              }
+              else
+              {
+                // mark the position as a point used for the interpolation.
                 arow[i].displayCharacter = arow[i].value + "";
-                }
+              }
             }
           }
         }
@@ -1969,10 +2127,12 @@ public class VamsasAppDatastore
       }
       else
       {
-        if (annotation.getAnnotationElementCount()==0)
+        if (annotation.getAnnotationElementCount() == 0)
         {
           // empty annotation array
-          // TODO: alignment 'features' compare rangeType spec to alignment width - if it is not complete, then mark regions on the annotation row.
+          // TODO: alignment 'features' compare rangeType spec to alignment
+          // width - if it is not complete, then mark regions on the annotation
+          // row.
         }
         jan = new jalview.datamodel.AlignmentAnnotation(a_label, a_descr,
                 arow);
@@ -1983,8 +2143,10 @@ public class VamsasAppDatastore
         Cache.log.warn("Ignoring " + annotation.getLinkCount()
                 + "links added to AlignmentAnnotation.");
       }
-      if (annotation.getModifiable() == null || annotation.getModifiable().length()==0) // TODO: USE VAMSAS LIBRARY OBJECT
-                                              // LOCK METHODS)
+      if (annotation.getModifiable() == null
+              || annotation.getModifiable().length() == 0) // TODO: USE VAMSAS
+                                                            // LIBRARY OBJECT
+      // LOCK METHODS)
       {
         jan.editable = true;
       }
@@ -1993,7 +2155,13 @@ public class VamsasAppDatastore
         if (annotation.getGroup() != null
                 && annotation.getGroup().length() > 0)
         {
-          jan.graphGroup = Integer.parseInt(annotation.getGroup()); // TODO: group similarly named annotation together ?
+          jan.graphGroup = Integer.parseInt(annotation.getGroup()); // TODO:
+                                                                    // group
+                                                                    // similarly
+                                                                    // named
+                                                                    // annotation
+                                                                    // together
+                                                                    // ?
         }
       } catch (Exception e)
       {
@@ -2140,12 +2308,12 @@ public class VamsasAppDatastore
   /**
    * 
    * @param maprange
-   *          where the from range is the local mapped range, and the to range
-   *          is the 'mapped' range in the MapRangeType
+   *                where the from range is the local mapped range, and the to
+   *                range is the 'mapped' range in the MapRangeType
    * @param default
-   *          unit for local
+   *                unit for local
    * @param default
-   *          unit for mapped
+   *                unit for mapped
    * @return MapList
    */
   private jalview.util.MapList parsemapType(MapType maprange, int localu,