+
+ public static SequenceFeature[] getHelixMap(CharSequence rnaAnnotation)
+ throws WUSSParseException
+ {
+ List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+
+ 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
+
+ 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
+ List<SimpleBP> bps = getSimpleBPs(rnaAnnotation);
+ for (SimpleBP basePair : bps)
+ {
+ final int open = basePair.getBP5();
+ final int close = basePair.getBP3();
+
+ // 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 <<..<<..>>..<<..>>>> |
+ */
+ int j = bps.size() - 1;
+ while (j >= 0)
+ {
+ int popen = bps.get(j).getBP5();
+
+ // 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
+ result.add(new SequenceFeature("RNA helix", "", open, close,
+ String.valueOf(helix)));
+
+ lastopen = open;
+ lastclose = close;
+ }
+
+ return result.toArray(new SequenceFeature[result.size()]);
+ }