JAL-1620 version bump and release notes
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
index 936ba42..9550e83 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
  * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
@@ -25,6 +25,8 @@ import jalview.analysis.SecStrConsensus.SimpleBP;
 import jalview.analysis.WUSSParseException;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -73,9 +75,10 @@ public class AlignmentAnnotation
   public SequenceFeature[] _rnasecstr = null;
 
   /**
-   * position of annotation resulting in invalid WUSS parsing or -1
+   * position of annotation resulting in invalid WUSS parsing or -1. -2 means
+   * there was no RNA structure in this annotation
    */
-  private long invalidrnastruc = -1;
+  private long invalidrnastruc = -2;
 
   /**
    * Updates the _rnasecstr field Determines the positions that base pair and
@@ -108,10 +111,47 @@ public class AlignmentAnnotation
       isrna = true;
       showAllColLabels = true;
       scaleColLabel = true;
+      _markRnaHelices();
     }
     // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup());
+
   }
 
+  private void _markRnaHelices()
+  {
+    int mxval = 0;
+    // Figure out number of helices
+    // Length of rnasecstr is the number of pairs of positions that base pair
+    // with each other in the secondary structure
+    for (int x = 0; x < _rnasecstr.length; x++)
+    {
+
+      /*
+       * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
+       * this.annotation._rnasecstr[x].getBegin());
+       */
+      // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
+      int val = 0;
+      try
+      {
+        val = Integer.valueOf(_rnasecstr[x].getFeatureGroup());
+        if (mxval < val)
+        {
+          mxval = val;
+        }
+      } catch (NumberFormatException q)
+      {
+      }
+      ;
+
+      annotations[_rnasecstr[x].getBegin()].value = val;
+      annotations[_rnasecstr[x].getEnd()].value = val;
+
+      // annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val;
+      // annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val;
+    }
+    setScore(mxval);
+  }
   /**
    * map of positions in the associated annotation
    */
@@ -453,11 +493,10 @@ public class AlignmentAnnotation
     @Override
     public char charAt(int index)
     {
-      String dc;
       return ((index + offset < 0) || (index + offset) >= max
-              || annotations[index + offset] == null || (dc = annotations[index
-              + offset].displayCharacter.trim()).length() < 1) ? '.' : dc
-              .charAt(0);
+              || annotations[index + offset] == null || (annotations[index
+ + offset].secondaryStructure < ' ') ? ' '
+              : annotations[index + offset].secondaryStructure);
     }
 
     public String toString()
@@ -467,9 +506,8 @@ public class AlignmentAnnotation
 
       for (int i = offset; i < mx; i++)
       {
-        String dc;
-        string[i] = (annotations[i] == null || (dc = annotations[i].displayCharacter
-                .trim()).length() < 1) ? '.' : dc.charAt(0);
+        string[i] = (annotations[i] == null || (annotations[i].secondaryStructure < 32)) ? ' '
+                : annotations[i].secondaryStructure;
       }
       return new String(string);
     }
@@ -634,6 +672,14 @@ public class AlignmentAnnotation
     this.scaleColLabel = annotation.scaleColLabel;
     this.showAllColLabels = annotation.showAllColLabels;
     this.calcId = annotation.calcId;
+    if (annotation.properties!=null)
+    {
+      properties = new HashMap<String,String>();
+      for (Map.Entry<String, String> val:annotation.properties.entrySet())
+      {
+        properties.put(val.getKey(), val.getValue());
+      }
+    }
     if (this.hasScore = annotation.hasScore)
     {
       this.score = annotation.score;
@@ -642,9 +688,9 @@ public class AlignmentAnnotation
     {
       threshold = new GraphLine(annotation.threshold);
     }
+    Annotation[] ann = annotation.annotations;
     if (annotation.annotations != null)
     {
-      Annotation[] ann = annotation.annotations;
       this.annotations = new Annotation[ann.length];
       for (int i = 0; i < ann.length; i++)
       {
@@ -657,24 +703,26 @@ public class AlignmentAnnotation
           }
         }
       }
-      ;
-      if (annotation.sequenceRef != null)
+    }
+    if (annotation.sequenceRef != null)
+    {
+      this.sequenceRef = annotation.sequenceRef;
+      if (annotation.sequenceMapping != null)
       {
-        this.sequenceRef = annotation.sequenceRef;
-        if (annotation.sequenceMapping != null)
+        Integer p = null;
+        sequenceMapping = new Hashtable();
+        Enumeration pos = annotation.sequenceMapping.keys();
+        while (pos.hasMoreElements())
         {
-          Integer p = null;
-          sequenceMapping = new Hashtable();
-          Enumeration pos = annotation.sequenceMapping.keys();
-          while (pos.hasMoreElements())
+          // could optimise this!
+          p = (Integer) pos.nextElement();
+          Annotation a = annotation.sequenceMapping.get(p);
+          if (a == null)
+          {
+            continue;
+          }
+          if (ann != null)
           {
-            // could optimise this!
-            p = (Integer) pos.nextElement();
-            Annotation a = annotation.sequenceMapping.get(p);
-            if (a == null)
-            {
-              continue;
-            }
             for (int i = 0; i < ann.length; i++)
             {
               if (ann[i] == a)
@@ -684,10 +732,10 @@ public class AlignmentAnnotation
             }
           }
         }
-        else
-        {
-          this.sequenceMapping = null;
-        }
+      }
+      else
+      {
+        this.sequenceMapping = null;
       }
     }
     // TODO: check if we need to do this: JAL-952
@@ -1272,7 +1320,7 @@ public class AlignmentAnnotation
     }
   }
 
-  public Object getProperty(String property)
+  public String getProperty(String property)
   {
     if (properties == null)
     {
@@ -1289,4 +1337,18 @@ public class AlignmentAnnotation
     }
     properties.put(property, value);
   }
+
+  public boolean hasProperties()
+  {
+    return properties != null && properties.size() > 0;
+  }
+
+  public Collection<String> getProperties()
+  {
+    if (properties == null)
+    {
+      return Collections.EMPTY_LIST;
+    }
+    return properties.keySet();
+  }
 }