JAL-2189 source formatting
[jalview.git] / src / jalview / analysis / Rna.java
index f497f0e..89c5c30 100644 (file)
@@ -52,6 +52,19 @@ public class Rna
   }
 
   /**
+   * Answers true if the string is a valid open pair rna secondary structure
+   * symbol. Currently accepts A-Z, ([{<
+   * 
+   * @param s
+   * @return
+   */
+  public static boolean isOpeningParenthesis(String s)
+  {
+    return s != null && s.length() == 1
+            && isOpeningParenthesis(s.charAt(0));
+  }
+
+  /**
    * Answers true if the character is a valid close pair rna secondary structure
    * symbol. Currently accepts a-z, )]}>
    * 
@@ -64,6 +77,19 @@ public class Rna
   }
 
   /**
+   * Answers true if the string is a valid close pair rna secondary structure
+   * symbol. Currently accepts a-z, )]}>
+   * 
+   * @param s
+   * @return
+   */
+  public static boolean isClosingParenthesis(String s)
+  {
+    return s != null && s.length() == 1
+            && isClosingParenthesis(s.charAt(0));
+  }
+
+  /**
    * Returns the matching open pair symbol for the given closing symbol.
    * Currently returns A-Z for a-z, or ([{< for )]}>, or the input symbol if it
    * is not a valid closing symbol.
@@ -298,6 +324,18 @@ public class Rna
   }
 
   /**
+   * Answers true if the string is a recognised symbol for RNA secondary
+   * structure. Currently accepts a-z, A-Z, ()[]{}<>.
+   * 
+   * @param s
+   * @return
+   */
+  public static boolean isRnaSecondaryStructureSymbol(String s)
+  {
+    return isOpeningParenthesis(s) || isClosingParenthesis(s);
+  }
+
+  /**
    * Translates a string to RNA secondary structure representation. Returns the
    * string with any non-SS characters changed to spaces. Accepted characters
    * are a-z, A-Z, and (){}[]<> brackets.
@@ -321,8 +359,8 @@ public class Rna
   }
 
   /**
-   * Answers true if the base-pair is either a canonical (A-T/U, C-G) or a
-   * wobble (G-T/U) pair (either way round), else false
+   * Answers true if the base-pair is either a Watson-Crick (A:T/U, C:G) or a
+   * wobble (G:T/U) pair (either way round), else false
    * 
    * @param first
    * @param second
@@ -338,7 +376,7 @@ public class Rna
     {
       second -= 32;
     }
-  
+
     switch (first)
     {
     case 'A':
@@ -379,6 +417,62 @@ public class Rna
   }
 
   /**
+   * Answers true if the base-pair is Watson-Crick - (A:T/U or C:G, either way
+   * round), else false
+   * 
+   * @param first
+   * @param second
+   * @return
+   */
+  public static boolean isCanonicalPair(char first, char second)
+  {
+
+    if (first > 'Z')
+    {
+      first -= 32;
+    }
+    if (second > 'Z')
+    {
+      second -= 32;
+    }
+
+    switch (first)
+    {
+    case 'A':
+      switch (second)
+      {
+      case 'T':
+      case 'U':
+        return true;
+      }
+      break;
+    case 'G':
+      switch (second)
+      {
+      case 'C':
+        return true;
+      }
+      break;
+    case 'C':
+      switch (second)
+      {
+      case 'G':
+        return true;
+      }
+      break;
+    case 'T':
+    case 'U':
+      switch (second)
+      {
+      case 'A':
+        return true;
+      }
+      break;
+    }
+    return false;
+  }
+
+  /**
    * Returns the matching close pair symbol for the given opening symbol.
    * Currently returns a-z for A-Z, or )]}> for ([{<, or the input symbol if it
    * is not a valid opening symbol.