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.ArrayList;
25 import java.util.Hashtable;
26 import java.util.Vector;
28 import jalview.datamodel.SequenceFeature;
32 static Hashtable<Integer, Integer> pairHash = new Hashtable();
34 * Based off of RALEE code ralee-get-base-pairs. Keeps track of open bracket
35 * positions in "stack" vector. When a close bracket is reached, pair this
36 * with the last element in the "stack" vector and store in "pairs" vector.
37 * Remove last element in the "stack" vector. Continue in this manner until
38 * the whole string is processed.
41 * Secondary structure line of an RNA Stockholm file
42 * @return Array of SequenceFeature; type = RNA helix, begin is open base
43 * pair, end is close base pair
45 public static SequenceFeature[] GetBasePairs(String line)
48 Vector stack = new Vector();
49 Vector pairs = new Vector();
52 while (i < line.length())
54 char base = line.charAt(i);
56 if ((base == '<') || (base == '(') || (base == '{') || (base == '['))
60 else if ((base == '>') || (base == ')') || (base == '}')
64 Object temp = stack.lastElement();
65 stack.remove(stack.size() - 1);
66 pairs.addElement(temp);
73 int numpairs = pairs.size() / 2;
74 SequenceFeature[] outPairs = new SequenceFeature[numpairs];
76 // Convert pairs to array
77 for (int p = 0; p < pairs.size(); p += 2)
79 int begin = Integer.parseInt(pairs.elementAt(p).toString());
80 int end = Integer.parseInt(pairs.elementAt(p + 1).toString());
82 outPairs[p / 2] = new SequenceFeature("RNA helix", "", "", begin,
84 //pairHash.put(begin, end);
93 * Function to get the end position corresponding to a given start position
94 * @param indice - start position of a base pair
95 * @return - end position of a base pair
97 /*makes no sense at the moment :(
98 public int findEnd(int indice){
99 //TODO: Probably extend this to find the start to a given end?
100 //could be done by putting everything twice to the hash
101 ArrayList<Integer> pair = new ArrayList<Integer>();
102 return pairHash.get(indice);
107 * Figures out which helix each position belongs to and stores the helix
108 * number in the 'featureGroup' member of a SequenceFeature Based off of RALEE
109 * code ralee-helix-map.
112 * Array of SequenceFeature (output from Rna.GetBasePairs)
114 public static void HelixMap(SequenceFeature[] pairs)
117 int helix = 0; // Number of helices/current helix
118 int lastopen = 0; // Position of last open bracket reviewed
119 int lastclose = 9999999; // Position of last close bracket reviewed
120 int i = pairs.length; // Number of pairs
122 int open; // Position of an open bracket under review
123 int close; // Position of a close bracket under review
126 Hashtable helices = new Hashtable(); // Keep track of helix number for each
129 // Go through each base pair and assign positions a helix
130 for (i = 0; i < pairs.length; i++)
133 open = pairs[i].getBegin();
134 close = pairs[i].getEnd();
136 // System.out.println("open " + open + " close " + close);
137 // System.out.println("lastclose " + lastclose + " lastopen " + lastopen);
139 // we're moving from right to left based on closing pair
141 * catch things like <<..>>..<<..>> |
143 if (open > lastclose)
149 * catch things like <<..<<..>>..<<..>>>> |
151 j = pairs.length - 1;
154 int popen = pairs[j].getBegin();
156 // System.out.println("j " + j + " popen " + popen + " lastopen "
157 // +lastopen + " open " + open);
158 if ((popen < lastopen) && (popen > open))
160 if (helices.containsValue(popen)
161 && (((Integer) helices.get(popen)) == helix))
175 // Put positions and helix information into the hashtable
176 helices.put(open, helix);
177 helices.put(close, helix);
179 // Record helix as featuregroup
180 pairs[i].setFeatureGroup(Integer.toString(helix));