Fileloading progressbar
[jalview.git] / src / jalview / io / AnnotationReader.java
index 4325dae..cd7abfd 100755 (executable)
@@ -35,11 +35,13 @@ public class AnnotationReader
       String line, label, description, token;\r
       int graphStyle, index;\r
       SequenceI refSeq = null;\r
-      int refSeqIndex = 0;\r
+      int refSeqIndex = 1;\r
       int existingAnnotations = 0;\r
       if(al.getAlignmentAnnotation()!=null)\r
        existingAnnotations = al.getAlignmentAnnotation().length;\r
 \r
+      int alWidth = al.getWidth();\r
+\r
       StringTokenizer st;\r
       Annotation[] annotations;\r
       AlignmentAnnotation annotation = null;\r
@@ -100,28 +102,32 @@ public class AnnotationReader
           }\r
           catch(Exception ex)\r
           {\r
-            refSeqIndex = 0;\r
+            refSeqIndex = 1;\r
           }\r
 \r
           continue;\r
         }\r
 \r
+\r
         graphStyle = AlignmentAnnotation.getGraphValueFromString(token);\r
         label = description = st.nextToken();\r
 \r
         line = st.nextToken();\r
+\r
         st = new StringTokenizer(line, "|", true);\r
-        annotations = new Annotation[st.countTokens()+refSeqIndex];\r
-        index = refSeqIndex;\r
+        annotations = new Annotation[alWidth];\r
+\r
+        index = 0;\r
         boolean emptyColumn = true;\r
-        while (st.hasMoreElements())\r
+\r
+\r
+        while (st.hasMoreElements() && index<alWidth)\r
         {\r
           token = st.nextToken().trim();\r
-\r
           if(token.equals("|"))\r
           {\r
             if(emptyColumn)\r
-              annotations[index++] = parseAnnotation("");\r
+              index++;\r
 \r
             emptyColumn = true;\r
           }\r
@@ -139,12 +145,16 @@ public class AnnotationReader
                                           0,\r
                                           graphStyle);\r
 \r
-       annotation = al.addAnnotation(annotation, refSeq);\r
-       al.setAnnotationIndex(annotation,  al.getAlignmentAnnotation().length - existingAnnotations-1);\r
-      }\r
+       if(refSeq!=null)\r
+       {\r
+         annotation.createSequenceMapping(refSeq, refSeqIndex);\r
+         refSeq.addAlignmentAnnotation(annotation);\r
+       }\r
 \r
-       al.adjustSequenceAnnotations();\r
+       al.addAnnotation(annotation);\r
 \r
+       al.setAnnotationIndex(annotation,  al.getAlignmentAnnotation().length - existingAnnotations-1);\r
+      }\r
 \r
     }catch(Exception ex)\r
     {\r
@@ -160,6 +170,7 @@ public class AnnotationReader
     String desc = "", displayChar="";\r
     char ss = ' '; // secondaryStructure\r
     float value = 0;\r
+    boolean parsedValue = false;\r
     StringTokenizer st = new StringTokenizer(string, ",");\r
     String token;\r
     while(st.hasMoreTokens())\r
@@ -168,29 +179,24 @@ public class AnnotationReader
       if(token.length()==0)\r
         continue;\r
 \r
-      if(value==0)\r
-      {  try{\r
-          value =  new Float(token).floatValue();\r
+      if(!parsedValue)\r
+      {\r
+        try{\r
+          value = new Float(token).floatValue();\r
+          displayChar = token;\r
+          parsedValue = true;\r
         }catch(NumberFormatException ex){}\r
       }\r
 \r
-      if(token.length()==1)\r
+      if(token.equals("H") || token.equals("E"))\r
       {\r
         // Either this character represents a helix or sheet\r
         // or an integer which can be displayed\r
-        if(token.equals("H") || token.equals("E"))\r
-        {\r
-          ss = token.charAt(0);\r
-        }\r
-        else //if(value!=0)\r
-        {\r
-          displayChar = token;\r
-        }\r
+        ss = token.charAt(0);\r
       }\r
       else if(desc.length()<1)\r
         desc = token;\r
-      else\r
-        displayChar = token;\r
+\r
     }\r
 \r
     return new Annotation(displayChar, desc, ss, value);\r