JAL-1781 annotation.sequenceRef now sequence id not name, incrementing features/JAL-1781annotationXmlIds
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 18 Jun 2015 08:18:14 +0000 (09:18 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 18 Jun 2015 08:18:14 +0000 (09:18 +0100)
annotation ids

src/jalview/datamodel/AlignmentAnnotation.java
src/jalview/gui/Jalview2XML.java

index 4c5ea17..322fd54 100755 (executable)
  */
 package jalview.datamodel;
 
-import jalview.analysis.Rna;
-import jalview.analysis.SecStrConsensus.SimpleBP;
-import jalview.analysis.WUSSParseException;
-
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -32,6 +28,10 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import jalview.analysis.Rna;
+import jalview.analysis.SecStrConsensus.SimpleBP;
+import jalview.analysis.WUSSParseException;
+
 /**
  * DOCUMENT ME!
  * 
@@ -40,6 +40,8 @@ import java.util.Map.Entry;
  */
 public class AlignmentAnnotation
 {
+  private static final String ANNOTATION_ID_PREFIX = "ann";
+
   /*
    * Identifers for different types of profile data
    */
@@ -49,6 +51,8 @@ public class AlignmentAnnotation
 
   public static final int CDNA_PROFILE = 2;
 
+  private static long counter = 0;
+
   /**
    * If true, this annotations is calculated every edit, eg consensus, quality
    * or conservation graphs
@@ -282,6 +286,7 @@ public class AlignmentAnnotation
   public AlignmentAnnotation(String label, String description,
           Annotation[] annotations)
   {
+    setAnnotationId();
     // always editable?
     editable = true;
     this.label = label;
@@ -458,8 +463,6 @@ public class AlignmentAnnotation
         _updateRnaSecStr(new AnnotCharSequence());
       }
     }
-
-    annotationId = this.hashCode() + "";
   }
 
   /**
@@ -565,6 +568,7 @@ public class AlignmentAnnotation
   public AlignmentAnnotation(String label, String description,
           Annotation[] annotations, float min, float max, int graphType)
   {
+    setAnnotationId();
     // graphs are not editable
     editable = graphType == 0;
 
@@ -664,6 +668,7 @@ public class AlignmentAnnotation
    */
   public AlignmentAnnotation(AlignmentAnnotation annotation)
   {
+    setAnnotationId();
     this.label = new String(annotation.label);
     if (annotation.description != null)
     {
@@ -1382,4 +1387,18 @@ public class AlignmentAnnotation
     return sequenceMapping == null ? null : sequenceMapping.get(position);
 
   }
+
+  /**
+   * Set the id to "ann" followed by a counter that increments so as to be
+   * unique for the lifetime of the JVM
+   */
+  protected final void setAnnotationId()
+  {
+    this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
+  }
+
+  protected static synchronized long nextId()
+  {
+    return counter++;
+  }
 }
index e443512..da9c6a9 100644 (file)
@@ -1511,9 +1511,8 @@ public class Jalview2XML
 
       if (aa[i].sequenceRef != null)
       {
-        // TODO later annotation sequenceRef should be the XML ID of the
-        // sequence rather than its display name
-        an.setSequenceRef(aa[i].sequenceRef.getName());
+        // 2.9 JAL-1781 xref on sequence id rather than name
+        an.setSequenceRef(seqsToIds.get(aa[i].sequenceRef));
       }
       if (aa[i].groupRef != null)
       {
@@ -2872,13 +2871,20 @@ public class Jalview2XML
           jaa.annotationId = an[i].getId();
         }
         // recover sequence association
-        if (an[i].getSequenceRef() != null)
+        String sequenceRef = an[i].getSequenceRef();
+        if (sequenceRef != null)
         {
-          if (al.findName(an[i].getSequenceRef()) != null)
+          // from 2.9 sequenceRef is to sequence id (JAL-1781)
+          SequenceI sequence = seqRefIds.get(sequenceRef);
+          if (sequence == null)
           {
-            jaa.createSequenceMapping(al.findName(an[i].getSequenceRef()),
-                    1, true);
-            al.findName(an[i].getSequenceRef()).addAlignmentAnnotation(jaa);
+            // in pre-2.9 projects sequence ref is to sequence name
+            sequence = al.findName(sequenceRef);
+          }
+          if (sequence != null)
+          {
+            jaa.createSequenceMapping(sequence, 1, true);
+            sequence.addAlignmentAnnotation(jaa);
           }
         }
         // and make a note of any group association