Annotations move when full alignment edited
[jalview.git] / src / jalview / gui / Jalview2XML.java
index f1f7db1..0cac9c1 100755 (executable)
@@ -56,6 +56,8 @@ public class Jalview2XML
    */
   Hashtable viewportsAdded;
 
+  Hashtable annotationIds = new Hashtable();
+
   String uniqueSetSuffix = "";
 
 
@@ -263,16 +265,20 @@ public class Jalview2XML
             {
               jseq.setHidden(av.alignment.getHiddenSequences().isHidden(jds));
 
-              if(jal.getSequenceAt(i).getHiddenSequences()!=null)
+              if(av.hiddenRepSequences!=null
+              && av.hiddenRepSequences.containsKey(jal.getSequenceAt(i)))
               {
-                jalview.datamodel.SequenceI [] reps =
-                    jal.getSequenceAt(i).getHiddenSequences().getSequencesInOrder(jal);
+                jalview.datamodel.SequenceI[] reps =
+                    ( (jalview.datamodel.SequenceGroup)
+                     av.hiddenRepSequences.get(
+                         jal.getSequenceAt(i))).getSequencesInOrder(jal);
 
                 for(int h=0; h<reps.length; h++)
                 {
-                  jseq.addHiddenSequences(
-                      jal.findIndex(reps[h])
-                      );
+                  if (reps[h] != jal.getSequenceAt(i))
+                    jseq.addHiddenSequences(
+                        jal.findIndex(reps[h])
+                        );
                 }
               }
             }
@@ -450,6 +456,13 @@ public class Jalview2XML
             {
                 Annotation an = new Annotation();
 
+                if(aa[i].annotationId!=null)
+                {
+                  annotationIds.put(aa[i].annotationId, aa[i]);
+                }
+
+                an.setId(aa[i].annotationId);
+
                 if (aa[i].label.equals("Quality") ||
                         aa[i].label.equals("Conservation") ||
                         aa[i].label.equals("Consensus"))
@@ -574,7 +587,7 @@ public class Jalview2XML
                 groups[i].setTextCol2(sg.textColour2.getRGB());
                 groups[i].setTextColThreshold(sg.thresholdTextColour);
 
-                for (int s = 0; s < sg.getSize(false); s++)
+                for (int s = 0; s < sg.getSize(); s++)
                 {
                     jalview.datamodel.Sequence seq =
                         (jalview.datamodel.Sequence) sg.getSequenceAt(s);
@@ -953,6 +966,7 @@ public class Jalview2XML
             System.out.println("Successfully loaded archive file");
             return af;
           }
+          ex.printStackTrace();
 
             System.err.println("Exception whilst loading jalview XML file : " +
                 ex + "\n");
@@ -1201,10 +1215,20 @@ public class Jalview2XML
                  continue;
                }
 
+               if (an[i].getId() != null
+                   && annotationIds.containsKey(an[i].getId()))
+               {
+                 al.addAnnotation(
+                     (jalview.datamodel.AlignmentAnnotation)annotationIds.get(an[i].getId())
+                     );
+
+                 continue;
+              }
+
                 AnnotationElement[] ae = an[i].getAnnotationElement();
                 jalview.datamodel.Annotation[] anot = new jalview.datamodel.Annotation[al.getWidth()];
 
-                for (int aa = 0; aa < ae.length; aa++)
+                for (int aa = 0; aa < ae.length && aa<anot.length; aa++)
                 {
                     anot[ae[aa].getPosition()] = new jalview.datamodel.Annotation(ae[aa].getDisplayCharacter(),
                             ae[aa].getDescription(),
@@ -1240,6 +1264,12 @@ public class Jalview2XML
                             an[i].getDescription(), anot);
                 }
 
+                if(an[i].getId()!=null)
+                {
+                  annotationIds.put(an[i].getId(), jaa);
+                  jaa.annotationId = an[i].getId();
+                }
+
                 if(an[i].getSequenceRef()!=null)
                 {
                   jaa.createSequenceMapping(
@@ -1301,7 +1331,7 @@ public class Jalview2XML
                 if (groups[i].getConsThreshold() != 0)
                 {
                     jalview.analysis.Conservation c = new jalview.analysis.Conservation("All",
-                            ResidueProperties.propHash, 3, sg.getSequences(false), 0,
+                            ResidueProperties.propHash, 3, sg.getSequences(null), 0,
                             sg.getWidth() - 1);
                     c.calculate();
                     c.verdict(false, 25);
@@ -1362,12 +1392,17 @@ public class Jalview2XML
         {
           for(int s=0; s<JSEQ.length; s++)
           {
+            jalview.datamodel.SequenceGroup hidden =
+                new jalview.datamodel.SequenceGroup();
+
             for(int r=0; r<JSEQ[s].getHiddenSequencesCount(); r++)
             {
-              al.getSequenceAt(s).addHiddenSequence(
-                  al.getSequenceAt( JSEQ[s].getHiddenSequences(r)  )
+              hidden.addSequence(
+                  al.getSequenceAt(JSEQ[s].getHiddenSequences(r))
+                  , false
                   );
             }
+            af.viewport.hideRepSequences(al.getSequenceAt(s), hidden);
           }
 
           jalview.datamodel.SequenceI [] hseqs = new
@@ -1676,6 +1711,18 @@ public class Jalview2XML
       af.alignPanels.clear();
       af.closeMenuItem_actionPerformed(true);
 
+    /*  if(ap.av.alignment.getAlignmentAnnotation()!=null)
+      {
+        for(int i=0; i<ap.av.alignment.getAlignmentAnnotation().length; i++)
+        {
+          if(!ap.av.alignment.getAlignmentAnnotation()[i].autoCalculated)
+          {
+            af.alignPanel.av.alignment.getAlignmentAnnotation()[i] =
+                ap.av.alignment.getAlignmentAnnotation()[i];
+          }
+        }
+      }   */
+
       return af.alignPanel;
     }
 }