1 /* Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
2 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
4 * This file is part of Jalview.
6 * Jalview is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10 * Jalview is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * 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.Vector;
27 import jalview.datamodel.SequenceFeature;
32 * Based off of RALEE code ralee-get-base-pairs. Keeps track of open bracket
33 * positions in "stack" vector. When a close bracket is reached, pair this
34 * with the last element in the "stack" vector and store in "pairs" vector.
35 * Remove last element in the "stack" vector. Continue in this manner until
36 * the whole string is processed.
39 * Secondary structure line of an RNA Stockholm file
40 * @return Array of SequenceFeature; type = RNA helix, begin is open base
41 * pair, end is close base pair
43 public static SequenceFeature[] GetBasePairs(String line)
46 Vector stack = new Vector();
47 Vector pairs = new Vector();
50 while (i < line.length())
52 char base = line.charAt(i);
54 if ((base == '<') || (base == '(') || (base == '{') || (base == '['))
58 else if ((base == '>') || (base == ')') || (base == '}')
62 Object temp = stack.lastElement();
63 stack.remove(stack.size() - 1);
64 pairs.addElement(temp);
71 int numpairs = pairs.size() / 2;
72 SequenceFeature[] outPairs = new SequenceFeature[numpairs];
74 // Convert pairs to array
75 for (int p = 0; p < pairs.size(); p += 2)
77 int begin = Integer.parseInt(pairs.elementAt(p).toString());
78 int end = Integer.parseInt(pairs.elementAt(p + 1).toString());
80 outPairs[p / 2] = new SequenceFeature("RNA helix", "", "", begin,
88 * Figures out which helix each position belongs to and stores the helix
89 * number in the 'featureGroup' member of a SequenceFeature Based off of RALEE
90 * code ralee-helix-map.
93 * Array of SequenceFeature (output from Rna.GetBasePairs)
95 public static void HelixMap(SequenceFeature[] pairs)
98 int helix = 0; // Number of helices/current helix
99 int lastopen = 0; // Position of last open bracket reviewed
100 int lastclose = 9999999; // Position of last close bracket reviewed
101 int i = pairs.length; // Number of pairs
103 int open; // Position of an open bracket under review
104 int close; // Position of a close bracket under review
107 Hashtable helices = new Hashtable(); // Keep track of helix number for each
110 // Go through each base pair and assign positions a helix
111 for (i = 0; i < pairs.length; i++)
114 open = pairs[i].getBegin();
115 close = pairs[i].getEnd();
117 // System.out.println("open " + open + " close " + close);
118 // System.out.println("lastclose " + lastclose + " lastopen " + lastopen);
120 // we're moving from right to left based on closing pair
122 * catch things like <<..>>..<<..>> |
124 if (open > lastclose)
130 * catch things like <<..<<..>>..<<..>>>> |
132 j = pairs.length - 1;
135 int popen = pairs[j].getBegin();
137 // System.out.println("j " + j + " popen " + popen + " lastopen "
138 // +lastopen + " open " + open);
139 if ((popen < lastopen) && (popen > open))
141 if (helices.containsValue(popen)
142 && (((Integer) helices.get(popen)) == helix))
156 // Put positions and helix information into the hashtable
157 helices.put(open, helix);
158 helices.put(close, helix);
160 // Record helix as featuregroup
161 pairs[i].setFeatureGroup(Integer.toString(helix));
162 pairs[i].setFeatureGroup(Integer.toString(helix));