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/
20 * Additional Author: Jan Engelhart (2011) - Structure consensus and bug fixing
21 * Additional Author: Anne Menard (2012) - Pseudoknot support and secondary structure consensus
24 package jalview.analysis;
26 import java.util.Hashtable;
27 import java.util.Stack;
28 import java.util.Vector;
30 import jalview.datamodel.SequenceFeature;
34 static Hashtable<Integer, Integer> pairHash = new Hashtable();
37 * Based off of RALEE code ralee-get-base-pairs. Keeps track of open bracket
38 * positions in "stack" vector. When a close bracket is reached, pair this
39 * with the last element in the "stack" vector and store in "pairs" vector.
40 * Remove last element in the "stack" vector. Continue in this manner until
41 * the whole string is processed.
44 * Secondary structure line of an RNA Stockholm file
45 * @return Array of SequenceFeature; type = RNA helix, begin is open base
46 * pair, end is close base pair
48 public static SequenceFeature[] GetBasePairs(CharSequence line)
49 throws WUSSParseException
51 Stack stack = new Stack();
52 Vector pairs = new Vector();
55 while (i < line.length())
57 char base = line.charAt(i);
59 if ((base == '<') || (base == '(') || (base == '{') || (base == '[')|| (base == 'A')|| (base == 'B')|| (base == 'C')|| (base == 'D')|| (base == '1')|| (base == 'F')|| (base == 'G')|| (base == '2')|| (base == 'I')|| (base == 'J')|| (base == 'K')|| (base == 'L')|| (base == 'M')|| (base == 'N')|| (base == 'O')|| (base == 'P')|| (base == 'Q')|| (base == 'R')|| (base == 'S')|| (base == 'T')|| (base == 'U')|| (base == 'V')|| (base == 'W')|| (base == 'X')|| (base == 'Y')|| (base == 'Z'))
63 else if ((base == '>') || (base == ')') || (base == '}')|| (base == ']')|| (base == 'a')|| (base == 'b')|| (base == 'c')|| (base == 'd')|| (base == 'e')|| (base == 'f')|| (base == 'g')|| (base == 'h')|| (base == 'i')|| (base == 'j')|| (base == 'k')|| (base == 'l')|| (base == 'm')|| (base == 'n')|| (base == 'o')|| (base == 'p')|| (base == 'q')|| (base == 'r')|| (base == 's')|| (base == 't')|| (base == 'u')|| (base == 'v')|| (base == 'w')|| (base == 'x')|| (base == 'y')|| (base == 'z'))
69 // error whilst parsing i'th position. pass back
70 throw new WUSSParseException("Mismatched closing bracket", i);
72 Object temp = stack.pop();
73 pairs.addElement(temp);
80 int numpairs = pairs.size() / 2;
81 SequenceFeature[] outPairs = new SequenceFeature[numpairs];
83 // Convert pairs to array
84 for (int p = 0; p < pairs.size(); p += 2)
86 int begin = Integer.parseInt(pairs.elementAt(p).toString());
87 int end = Integer.parseInt(pairs.elementAt(p + 1).toString());
89 outPairs[p / 2] = new SequenceFeature("RNA helix", "", "", begin,
91 // pairHash.put(begin, end);
99 * Function to get the end position corresponding to a given start position
102 * - start position of a base pair
103 * @return - end position of a base pair
106 * makes no sense at the moment :( public int findEnd(int indice){ //TODO:
107 * Probably extend this to find the start to a given end? //could be done by
108 * putting everything twice to the hash ArrayList<Integer> pair = new
109 * ArrayList<Integer>(); return pairHash.get(indice); }
113 * Figures out which helix each position belongs to and stores the helix
114 * number in the 'featureGroup' member of a SequenceFeature Based off of RALEE
115 * code ralee-helix-map.
118 * Array of SequenceFeature (output from Rna.GetBasePairs)
120 public static void HelixMap(SequenceFeature[] pairs)
123 int helix = 0; // Number of helices/current helix
124 int lastopen = 0; // Position of last open bracket reviewed
125 int lastclose = 9999999; // Position of last close bracket reviewed
126 int i = pairs.length; // Number of pairs
128 int open; // Position of an open bracket under review
129 int close; // Position of a close bracket under review
132 Hashtable helices = new Hashtable(); // Keep track of helix number for each
135 // Go through each base pair and assign positions a helix
136 for (i = 0; i < pairs.length; i++)
139 open = pairs[i].getBegin();
140 close = pairs[i].getEnd();
142 // System.out.println("open " + open + " close " + close);
143 // System.out.println("lastclose " + lastclose + " lastopen " + lastopen);
145 // we're moving from right to left based on closing pair
147 * catch things like <<..>>..<<..>> |
149 if (open > lastclose)
155 * catch things like <<..<<..>>..<<..>>>> |
157 j = pairs.length - 1;
160 int popen = pairs[j].getBegin();
162 // System.out.println("j " + j + " popen " + popen + " lastopen "
163 // +lastopen + " open " + open);
164 if ((popen < lastopen) && (popen > open))
166 if (helices.containsValue(popen)
167 && (((Integer) helices.get(popen)) == helix))
181 // Put positions and helix information into the hashtable
182 helices.put(open, helix);
183 helices.put(close, helix);
185 // Record helix as featuregroup
186 pairs[i].setFeatureGroup(Integer.toString(helix));