Start merging of Laurens Code
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
index 236e8ee..c4268e2 100755 (executable)
@@ -17,6 +17,8 @@
  */
 package jalview.datamodel;
 
+import jalview.analysis.Rna;
+
 import java.util.Enumeration;
 import java.util.Hashtable;
 
@@ -47,6 +49,31 @@ public class AlignmentAnnotation
   /** DOCUMENT ME!! */
   public Annotation[] annotations;
 
+  /**
+   * RNA secondary structure contact positions
+   */
+  public SequenceFeature[] _rnasecstr = null;
+
+  /**
+   * Updates the _rnasecstr field Determines the positions that base pair and
+   * the positions of helices based on secondary structure from a Stockholm file
+   * 
+   * @param RNAannot
+   */
+  private void _updateRnaSecStr(String RNAannot)
+  {
+    _rnasecstr = Rna.GetBasePairs(RNAannot);
+    Rna.HelixMap(_rnasecstr);
+
+    if (_rnasecstr != null && _rnasecstr.length > 0)
+    {
+      // show all the RNA secondary structure annotation symbols.
+      showAllColLabels = true;
+      scaleColLabel = true;
+    }
+    // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup());
+  }
+
   public java.util.Hashtable sequenceMapping;
 
   /** DOCUMENT ME!! */
@@ -167,9 +194,16 @@ public class AlignmentAnnotation
     validateRangeAndDisplay();
   }
 
+  /**
+   * Checks if annotation labels represent secondary structures
+   * 
+   */
   void areLabelsSecondaryStructure()
   {
     boolean nonSSLabel = false;
+    boolean isrna = false;
+    StringBuffer rnastring = new StringBuffer();
+
     char firstChar = 0;
     for (int i = 0; i < annotations.length; i++)
     {
@@ -182,9 +216,22 @@ public class AlignmentAnnotation
       {
         hasIcons |= true;
       }
+      else
+      // Check for RNA secondary structure
+      {
+        if (annotations[i].secondaryStructure == 'S')
+        {
+          hasIcons |= true;
+          isrna |= true;
+        }
+      }
 
-      if (annotations[i].displayCharacter == null)
+      // System.out.println("displaychar " + annotations[i].displayCharacter);
+
+      if (annotations[i].displayCharacter == null
+              || annotations[i].displayCharacter.length() == 0)
       {
+        rnastring.append('.');
         continue;
       }
       if (annotations[i].displayCharacter.length() == 1)
@@ -205,6 +252,7 @@ public class AlignmentAnnotation
                 firstChar != ' '
                 && firstChar != 'H'
                 && firstChar != 'E'
+                && firstChar != 'S'
                 && firstChar != '-'
                 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
         {
@@ -219,6 +267,10 @@ public class AlignmentAnnotation
           }
         }
       }
+      else
+      {
+        rnastring.append(annotations[i].displayCharacter.charAt(1));
+      }
 
       if (annotations[i].displayCharacter.length() > 0)
       {
@@ -241,6 +293,13 @@ public class AlignmentAnnotation
 
       }
     }
+    else
+    {
+      if (isrna)
+      {
+        _updateRnaSecStr(rnastring.toString());
+      }
+    }
 
     annotationId = this.hashCode() + "";
   }