formatting
[jalview.git] / src / jalview / gui / Jalview2XML.java
index 6652aea..7d6d519 100755 (executable)
@@ -56,6 +56,8 @@ public class Jalview2XML
    */
   Hashtable viewportsAdded;
 
+  Hashtable annotationIds = new Hashtable();
+
   String uniqueSetSuffix = "";
 
 
@@ -454,9 +456,16 @@ public class Jalview2XML
             {
                 Annotation an = new Annotation();
 
-                if (aa[i].label.equals("Quality") ||
-                        aa[i].label.equals("Conservation") ||
-                        aa[i].label.equals("Consensus"))
+                if(aa[i].annotationId!=null)
+                {
+                  annotationIds.put(aa[i].annotationId, aa[i]);
+                }
+
+                an.setId(aa[i].annotationId);
+
+                if (aa[i]==av.quality ||
+                        aa[i]==av.conservation ||
+                        aa[i]==av.consensus)
                 {
                     an.setLabel(aa[i].label);
                     an.setGraph(true);
@@ -957,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");
@@ -1205,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(),
@@ -1244,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(
@@ -1287,9 +1313,16 @@ public class Jalview2XML
                 for (int s = 0; s < groups[i].getSeqCount(); s++)
                 {
                     String seqId = groups[i].getSeq(s)+"";
-                    seqs.addElement((jalview.datamodel.SequenceI) seqRefIds.get(seqId));
+                    jalview.datamodel.SequenceI ts = (jalview.datamodel.SequenceI)
+                        seqRefIds.get(seqId);
+
+                    if (ts != null)
+                      seqs.addElement(ts);
                 }
 
+                if(seqs.size()<1)
+                  continue;
+
                 jalview.datamodel.SequenceGroup sg = new jalview.datamodel.SequenceGroup(seqs,
                         groups[i].getName(), cs, groups[i].getDisplayBoxes(),
                         groups[i].getDisplayText(), groups[i].getColourText(),
@@ -1685,6 +1718,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;
     }
 }