+
+ /**
+ * Answers true if the character is a valid open pair rna secondary structure
+ * symbol. Currently accepts A-Z, ([{<
+ *
+ * @param c
+ * @return
+ */
+ public static boolean isOpeningParenthesis(char c)
+ {
+ return ('A' <= c && c <= 'Z' || c == '(' || c == '[' || c == '{'
+ || c == '<');
+ }
+
+ /**
+ * 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, )]}>
+ *
+ * @param c
+ * @return
+ */
+ public static boolean isClosingParenthesis(char c)
+ {
+ return ('a' <= c && c <= 'z' || c == ')' || c == ']' || c == '}'
+ || c == '>');
+ }
+
+ /**
+ * 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.
+ *
+ * @param c
+ * @return
+ */
+ public static char getMatchingOpeningParenthesis(char c)
+ {
+ if ('a' <= c && c <= 'z')
+ {
+ return (char) (c + 'A' - 'a');
+ }
+ switch (c)
+ {
+ case ')':
+ return '(';
+ case ']':
+ return '[';
+ case '}':
+ return '{';
+ case '>':
+ return '<';
+ default:
+ return c;
+ }
+ }
+