Are the labels all secondary Strutures? are the displayChars actually descriptions?
authoramwaterhouse <Andrew Waterhouse>
Thu, 14 Dec 2006 18:42:25 +0000 (18:42 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 14 Dec 2006 18:42:25 +0000 (18:42 +0000)
src/jalview/datamodel/AlignmentAnnotation.java
src/jalview/io/AnnotationFile.java

index c3396b6..7c57e6b 100755 (executable)
@@ -103,21 +103,53 @@ public class AlignmentAnnotation
         this.description = description;
         this.annotations = annotations;
 
-        for (int i = 0; i < annotations.length; i++)
+       areLabelsSecondaryStructure();
+    }
+
+    void areLabelsSecondaryStructure()
+    {
+      boolean nonSSLabel = false;
+      for (int i = 0; i < annotations.length; i++)
+      {
+        if(annotations[i]==null)
+          continue;
+
+        if (annotations[i].secondaryStructure == 'H' ||
+            annotations[i].secondaryStructure == 'E')
         {
-            if ((annotations[i] != null) &&
-                    ((annotations[i].secondaryStructure == 'H') ||
-                    (annotations[i].secondaryStructure == 'E')))
-            {
-                hasIcons = true;
-            }
+          hasIcons = true;
+        }
+
+        if (annotations[i].secondaryStructure != 'H'
+            && annotations[i].secondaryStructure != 'E')
+        {
+          nonSSLabel = true;
+        }
+
+        if (annotations[i].displayCharacter.length() > 0)
+        {
+          hasText = true;
+        }
+      }
+
+      if(nonSSLabel)
+      {
+        hasIcons = false;
+        for (int j = 0; j < annotations.length; j++)
+        {
+          if(annotations[j] !=null && annotations[j].secondaryStructure!=' ')
+          {
+            annotations[j].displayCharacter
+                =String.valueOf(annotations[j].secondaryStructure);
+            annotations[j].secondaryStructure = ' ';
+            if(annotations[j].description.length()<1)
+              annotations[j].description = annotations[j].displayCharacter;
+          }
 
-            if ((annotations[i] != null) &&
-                    (annotations[i].displayCharacter.length() > 0))
-            {
-                hasText = true;
-            }
         }
+
+      }
+
     }
 
     /**
@@ -171,23 +203,7 @@ public class AlignmentAnnotation
         graphMin = min;
         graphMax = max;
 
-        for (int i = 0; i < annotations.length; i++)
-        {
-            if (!hasIcons
-                && annotations[i] != null
-                && ((annotations[i].secondaryStructure == 'H') ||
-                    (annotations[i].secondaryStructure == 'E')))
-            {
-                hasIcons = true;
-            }
-
-            if (!hasText
-                && annotations[i]!=null
-                && annotations[i].displayCharacter.length() > 0)
-            {
-                hasText = true;
-            }
-        }
+        areLabelsSecondaryStructure();
 
         if(!drawValues && graphType!=NO_GRAPH)
         {
index 77f8810..a211d1a 100755 (executable)
@@ -38,7 +38,7 @@ public class AnnotationFile
 \r
     AlignmentAnnotation row;\r
     String comma;\r
-    String seqref = null;\r
+    SequenceI seqref = null;\r
 \r
     StringBuffer colours = new StringBuffer();\r
     StringBuffer graphLine = new StringBuffer();\r
@@ -55,11 +55,10 @@ public class AnnotationFile
       if( row.sequenceRef == null)\r
         seqref = null;\r
 \r
-      else if (seqref == null\r
-           || !seqref.equals(row.sequenceRef.getName()))\r
+      else if (seqref == null || seqref != row.sequenceRef)\r
       {\r
-        seqref = row.sequenceRef.getName();\r
-        text.append("\nSEQUENCE_REF\t" + seqref + "\n");\r
+        seqref = row.sequenceRef;\r
+        text.append("\nSEQUENCE_REF\t" + seqref.getName() + "\n");\r
       }\r
 \r
 \r
@@ -98,6 +97,9 @@ public class AnnotationFile
 \r
       for(int j=0; j<row.annotations.length; j++)\r
       {\r
+        if (seqref != null && jalview.util.Comparison.isGap(seqref.getCharAt(j)))\r
+          continue;\r
+\r
         if(row.annotations[j]!=null)\r
         {\r
           comma = "";\r
@@ -106,16 +108,18 @@ public class AnnotationFile
             text.append(comma + row.annotations[j].secondaryStructure);\r
             comma = ",";\r
           }\r
-          if (row.annotations[j].displayCharacter.length() > 0 \r
+          if (row.annotations[j].displayCharacter.length() > 0\r
                   && !row.annotations[j].displayCharacter.equals(" "))\r
               {\r
                 text.append(comma + row.annotations[j].displayCharacter);\r
                 comma = ",";\r
               }\r
-          if (row.annotations[j].value!=0f)\r
+\r
+          if (row.annotations[j]!=null)\r
           {\r
             color = row.annotations[j].colour;\r
-            text.append(comma + row.annotations[j].value);\r
+            if (row.annotations[j].value!=0f)\r
+              text.append(comma + row.annotations[j].value);\r
           }\r
         }\r
         text.append("|");\r
@@ -239,6 +243,11 @@ public class AnnotationFile
           refSeq = al.findName(st.nextToken());\r
           try{\r
             refSeqIndex = Integer.parseInt(st.nextToken());\r
+            if(refSeqIndex<1)\r
+            {\r
+              refSeqIndex = 1;\r
+              System.out.println("WARNING: SEQUENCE_REF index must be > 0 in AnnotationFile");\r
+            }\r
           }\r
           catch(Exception ex)\r
           {\r
@@ -307,7 +316,7 @@ public class AnnotationFile
 \r
   Annotation parseAnnotation(String string)\r
   {\r
-    String desc = "", displayChar="";\r
+    String desc = null, displayChar="";\r
     char ss = ' '; // secondaryStructure\r
     float value = 0;\r
     boolean parsedValue = false;\r
@@ -325,6 +334,7 @@ public class AnnotationFile
           displayChar = token;\r
           value = new Float(token).floatValue();\r
           parsedValue = true;\r
+          continue;\r
         }catch(NumberFormatException ex){}\r
       }\r
 \r
@@ -336,11 +346,21 @@ public class AnnotationFile
         if(displayChar.equals(token.substring(0,1)))\r
           displayChar = "";\r
       }\r
-      else if(desc.length()<1)\r
+      else if(desc==null)\r
         desc = token;\r
 \r
     }\r
 \r
+    if(desc == null)\r
+      desc = value+"";\r
+\r
+    if(displayChar.length()>1 && desc.length()==1)\r
+    {\r
+      String tmp = displayChar;\r
+      displayChar = desc;\r
+      desc = tmp;\r
+    }\r
+\r
     return new Annotation(displayChar, desc, ss, value);\r
   }\r
 \r