JAL-629 Change all stdout and stderr output to use Console.outPrintln and Console...
[jalview.git] / src / jalview / analysis / Rna.java
index 6bb123a..911ee04 100644 (file)
@@ -49,7 +49,8 @@ public class Rna
    */
   public static boolean isOpeningParenthesis(char c)
   {
-    return ('A' <= c && c <= 'Z' || c == '(' || c == '[' || c == '{' || c == '<');
+    return ('A' <= c && c <= 'Z' || c == '(' || c == '[' || c == '{'
+            || c == '<');
   }
 
   /**
@@ -74,7 +75,8 @@ public class Rna
    */
   public static boolean isClosingParenthesis(char c)
   {
-    return ('a' <= c && c <= 'z' || c == ')' || c == ']' || c == '}' || c == '>');
+    return ('a' <= c && c <= 'z' || c == ')' || c == ']' || c == '}'
+            || c == '>');
   }
 
   /**
@@ -160,8 +162,8 @@ public class Rna
         if (!stacks.containsKey(opening))
         {
           throw new WUSSParseException(MessageManager.formatMessage(
-                  "exception.mismatched_unseen_closing_char",
-                  new String[] { String.valueOf(base) }), i);
+                  "exception.mismatched_unseen_closing_char", new String[]
+                  { String.valueOf(base) }), i);
         }
 
         Stack<Integer> stack = stacks.get(opening);
@@ -169,8 +171,8 @@ public class Rna
         {
           // error whilst parsing i'th position. pass back
           throw new WUSSParseException(MessageManager.formatMessage(
-                  "exception.mismatched_closing_char",
-                  new String[] { String.valueOf(base) }), i);
+                  "exception.mismatched_closing_char", new String[]
+                  { String.valueOf(base) }), i);
         }
         int temp = stack.pop();
 
@@ -188,18 +190,14 @@ public class Rna
          * i (length of input string)
          */
         throw new WUSSParseException(MessageManager.formatMessage(
-                "exception.mismatched_opening_char",
-                new String[] { String.valueOf(opening),
-                    String.valueOf(stack.pop()) }), i);
+                "exception.mismatched_opening_char", new String[]
+                { String.valueOf(opening), String.valueOf(stack.pop()) }),
+                i);
       }
     }
     return pairs;
   }
 
-  
-
-  
-
   /**
    * Function to get the end position corresponding to a given start position
    * 
@@ -215,86 +213,6 @@ public class Rna
    */
 
   /**
-   * Figures out which helix each position belongs to and stores the helix
-   * number in the 'featureGroup' member of a SequenceFeature Based off of RALEE
-   * code ralee-helix-map.
-   * 
-   * @param pairs
-   *          Array of SequenceFeature (output from Rna.GetBasePairs)
-   */
-  protected static void computeHelixMap(SequenceFeature[] pairs)
-  {
-
-    int helix = 0; // Number of helices/current helix
-    int lastopen = 0; // Position of last open bracket reviewed
-    int lastclose = 9999999; // Position of last close bracket reviewed
-
-    int open; // Position of an open bracket under review
-    int close; // Position of a close bracket under review
-    int j; // Counter
-
-    Map<Integer, Integer> helices = new HashMap<Integer, Integer>();
-    // Keep track of helix number for each position
-
-    // Go through each base pair and assign positions a helix
-    for (int i = 0; i < pairs.length; i++)
-    {
-
-      open = pairs[i].getBegin();
-      close = pairs[i].getEnd();
-
-      // System.out.println("open " + open + " close " + close);
-      // System.out.println("lastclose " + lastclose + " lastopen " + lastopen);
-
-      // we're moving from right to left based on closing pair
-      /*
-       * catch things like <<..>>..<<..>> |
-       */
-      if (open > lastclose)
-      {
-        helix++;
-      }
-
-      /*
-       * catch things like <<..<<..>>..<<..>>>> |
-       */
-      j = pairs.length - 1;
-      while (j >= 0)
-      {
-        int popen = pairs[j].getBegin();
-
-        // System.out.println("j " + j + " popen " + popen + " lastopen "
-        // +lastopen + " open " + open);
-        if ((popen < lastopen) && (popen > open))
-        {
-          if (helices.containsValue(popen)
-                  && ((helices.get(popen)) == helix))
-          {
-            continue;
-          }
-          else
-          {
-            helix++;
-            break;
-          }
-        }
-
-        j -= 1;
-      }
-
-      // Put positions and helix information into the hashtable
-      helices.put(open, helix);
-      helices.put(close, helix);
-
-      // Record helix as featuregroup
-      pairs[i].setFeatureGroup(Integer.toString(helix));
-
-      lastopen = open;
-      lastclose = close;
-    }
-  }
-
-  /**
    * Answers true if the character is a recognised symbol for RNA secondary
    * structure. Currently accepts a-z, A-Z, ()[]{}<>.
    * 
@@ -503,8 +421,8 @@ public class Rna
       final int open = basePair.getBP5();
       final int close = basePair.getBP3();
 
-      // System.out.println("open " + open + " close " + close);
-      // System.out.println("lastclose " + lastclose + " lastopen " + lastopen);
+      // jalview.bin.Console.outPrintln("open " + open + " close " + close);
+      // jalview.bin.Console.outPrintln("lastclose " + lastclose + " lastopen " + lastopen);
 
       // we're moving from right to left based on closing pair
       /*
@@ -518,12 +436,12 @@ public class Rna
       /*
        * catch things like <<..<<..>>..<<..>>>> |
        */
-      int j = bps.size() - 1;
-      while (j >= 0)
+      int j = bps.size();
+      while (--j >= 0)
       {
         int popen = bps.get(j).getBP5();
 
-        // System.out.println("j " + j + " popen " + popen + " lastopen "
+        // jalview.bin.Console.outPrintln("j " + j + " popen " + popen + " lastopen "
         // +lastopen + " open " + open);
         if ((popen < lastopen) && (popen > open))
         {
@@ -538,7 +456,6 @@ public class Rna
             break;
           }
         }
-        j -= 1;
       }
 
       // Put positions and helix information into the hashtable
@@ -546,7 +463,7 @@ public class Rna
       helices.put(close, helix);
 
       // Record helix as featuregroup
-      result.add(new SequenceFeature("RNA helix", "", "", open, close,
+      result.add(new SequenceFeature("RNA helix", "", open, close,
               String.valueOf(helix)));
 
       lastopen = open;