2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 /* Author: Lauren Michelle Lui
19 * Methods are based on RALEE methods http://personalpages.manchester.ac.uk/staff/sam.griffiths-jones/software/ralee/
22 package jalview.analysis;
24 import java.util.Hashtable;
25 import java.util.Stack;
26 import java.util.Vector;
28 import jalview.datamodel.SequenceFeature;
32 static Hashtable<Integer, Integer> pairHash = new Hashtable();
35 * Based off of RALEE code ralee-get-base-pairs. Keeps track of open bracket
36 * positions in "stack" vector. When a close bracket is reached, pair this
37 * with the last element in the "stack" vector and store in "pairs" vector.
38 * Remove last element in the "stack" vector. Continue in this manner until
39 * the whole string is processed.
42 * Secondary structure line of an RNA Stockholm file
43 * @return Array of SequenceFeature; type = RNA helix, begin is open base
44 * pair, end is close base pair
46 public static SequenceFeature[] GetBasePairs(CharSequence line)
47 throws WUSSParseException
49 Stack stack = new Stack();
50 Vector pairs = new Vector();
53 while (i < line.length())
55 char base = line.charAt(i);
57 if ((base == '<') || (base == '(') || (base == '{') || (base == '['))
61 else if ((base == '>') || (base == ')') || (base == '}')
67 // error whilst parsing i'th position. pass back
68 throw new WUSSParseException("Mismatched closing bracket", i);
70 Object temp = stack.pop();
71 pairs.addElement(temp);
78 int numpairs = pairs.size() / 2;
79 SequenceFeature[] outPairs = new SequenceFeature[numpairs];
81 // Convert pairs to array
82 for (int p = 0; p < pairs.size(); p += 2)
84 int begin = Integer.parseInt(pairs.elementAt(p).toString());
85 int end = Integer.parseInt(pairs.elementAt(p + 1).toString());
87 outPairs[p / 2] = new SequenceFeature("RNA helix", "", "", begin,
89 // pairHash.put(begin, end);
97 * Function to get the end position corresponding to a given start position
100 * - start position of a base pair
101 * @return - end position of a base pair
104 * makes no sense at the moment :( public int findEnd(int indice){ //TODO:
105 * Probably extend this to find the start to a given end? //could be done by
106 * putting everything twice to the hash ArrayList<Integer> pair = new
107 * ArrayList<Integer>(); return pairHash.get(indice); }
111 * Figures out which helix each position belongs to and stores the helix
112 * number in the 'featureGroup' member of a SequenceFeature Based off of RALEE
113 * code ralee-helix-map.
116 * Array of SequenceFeature (output from Rna.GetBasePairs)
118 public static void HelixMap(SequenceFeature[] pairs)
121 int helix = 0; // Number of helices/current helix
122 int lastopen = 0; // Position of last open bracket reviewed
123 int lastclose = 9999999; // Position of last close bracket reviewed
124 int i = pairs.length; // Number of pairs
126 int open; // Position of an open bracket under review
127 int close; // Position of a close bracket under review
130 Hashtable helices = new Hashtable(); // Keep track of helix number for each
133 // Go through each base pair and assign positions a helix
134 for (i = 0; i < pairs.length; i++)
137 open = pairs[i].getBegin();
138 close = pairs[i].getEnd();
140 // System.out.println("open " + open + " close " + close);
141 // System.out.println("lastclose " + lastclose + " lastopen " + lastopen);
143 // we're moving from right to left based on closing pair
145 * catch things like <<..>>..<<..>> |
147 if (open > lastclose)
153 * catch things like <<..<<..>>..<<..>>>> |
155 j = pairs.length - 1;
158 int popen = pairs[j].getBegin();
160 // System.out.println("j " + j + " popen " + popen + " lastopen "
161 // +lastopen + " open " + open);
162 if ((popen < lastopen) && (popen > open))
164 if (helices.containsValue(popen)
165 && (((Integer) helices.get(popen)) == helix))
179 // Put positions and helix information into the hashtable
180 helices.put(open, helix);
181 helices.put(close, helix);
183 // Record helix as featuregroup
184 pairs[i].setFeatureGroup(Integer.toString(helix));