2 VARNA is a tool for the automated drawing, visualization and annotation of the secondary structure of RNA, designed as a companion software for web servers and databases.
3 Copyright (C) 2008 Kevin Darty, Alain Denise and Yann Ponty.
4 electronic mail : Yann.Ponty@lri.fr
5 paper mail : LRI, bat 490 Université Paris-Sud 91405 Orsay Cedex France
7 This file is part of VARNA version 3.1.
8 VARNA version 3.1 is free software: you can redistribute it and/or 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 VARNA version 3.1 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with VARNA version 3.1.
16 If not, see http://www.gnu.org/licenses.
18 package fr.orsay.lri.varna.models.rna;
20 import java.awt.Color;
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.Random;
25 import javax.xml.transform.sax.TransformerHandler;
27 import org.xml.sax.SAXException;
28 import org.xml.sax.helpers.AttributesImpl;
30 import fr.orsay.lri.varna.exceptions.ExceptionModeleStyleBaseSyntaxError;
31 import fr.orsay.lri.varna.exceptions.ExceptionParameterError;
32 import fr.orsay.lri.varna.models.VARNAConfig;
35 public class ModeleBP implements Serializable, Comparable<ModeleBP> {
40 private static final long serialVersionUID = -1344722280822711931L;
45 public enum Stericity {
49 private ModeleBase _partner5;
51 private ModeleBase _partner3;
53 private Stericity _stericity;
54 private ModeleBPStyle _style;
57 public static String XML_ELEMENT_NAME = "bp";
58 public static String XML_VAR_PARTNER5_NAME = "part5";
59 public static String XML_VAR_EDGE5_NAME = "edge5";
60 public static String XML_VAR_PARTNER3_NAME = "part3";
61 public static String XML_VAR_EDGE3_NAME = "edge3";
62 public static String XML_VAR_STERICITY_NAME = "orient";
63 public static String XML_VAR_SEC_STR_NAME = "secstr";
65 public void toXML(TransformerHandler hd, boolean inSecondaryStructure) throws SAXException
67 AttributesImpl atts = new AttributesImpl();
68 atts.addAttribute("","",XML_VAR_PARTNER5_NAME,"CDATA",""+_partner5.getIndex());
69 atts.addAttribute("","",XML_VAR_PARTNER3_NAME,"CDATA",""+_partner3.getIndex());
70 atts.addAttribute("","",XML_VAR_EDGE5_NAME,"CDATA",""+_edge5);
71 atts.addAttribute("","",XML_VAR_EDGE3_NAME,"CDATA",""+_edge3);
72 atts.addAttribute("","",XML_VAR_STERICITY_NAME,"CDATA",""+_stericity);
73 atts.addAttribute("","",XML_VAR_SEC_STR_NAME,"CDATA",""+inSecondaryStructure);
74 hd.startElement("","",XML_ELEMENT_NAME,atts);
76 hd.endElement("","",XML_ELEMENT_NAME);
79 public void toXML(TransformerHandler hd) throws SAXException
86 public ModeleBP(ModeleBase part5, ModeleBase part3) {
87 this(part5, part3, Edge.WC, Edge.WC, Stericity.CIS);
90 //private static Random rnd = new Random(System.currentTimeMillis());
92 public ModeleBP(ModeleBase part5, ModeleBase part3, Edge edge5,
93 Edge edge3, Stericity ster) {
99 _style = new ModeleBPStyle();
102 public ModeleBP(String text) throws ExceptionModeleStyleBaseSyntaxError, ExceptionParameterError {
103 _style = new ModeleBPStyle();
104 assignParameters(text);
107 public void setStericity(Stericity s) {
111 public void setEdge5(Edge e) {
115 public void setEdge3(Edge e) {
119 public void setStyle(ModeleBPStyle e) {
123 public ModeleBPStyle getStyle() {
127 public boolean isCanonicalGC() {
128 String si = _partner5.getContent();
129 String sj = _partner3.getContent();
130 if ((si.length() >= 1) && (sj.length() >= 1)) {
131 char ci = si.toUpperCase().charAt(0);
132 char cj = sj.toUpperCase().charAt(0);
133 if (((ci == 'G') && (cj == 'C')) || ((ci == 'C') && (cj == 'G'))) {
134 return isCanonical() && (getStericity() == Stericity.CIS);
140 public boolean isCanonicalAU() {
141 String si = _partner5.getContent();
142 String sj = _partner3.getContent();
143 if ((si.length() >= 1) && (sj.length() >= 1)) {
144 char ci = si.toUpperCase().charAt(0);
145 char cj = sj.toUpperCase().charAt(0);
146 if (((ci == 'A') && (cj == 'U'))
147 || ((ci == 'U') && (cj == 'A'))
148 || ((ci == 'U') && (cj == 'T'))
149 || ((ci == 'T') && (cj == 'U'))) {
150 return isCanonical();
156 public boolean isWobbleUG() {
157 String si = _partner5.getContent();
158 String sj = _partner3.getContent();
159 if ((si.length() >= 1) && (sj.length() >= 1)) {
160 char ci = si.toUpperCase().charAt(0);
161 char cj = sj.toUpperCase().charAt(0);
162 if (((ci == 'G') && (cj == 'U')) || ((ci == 'U') && (cj == 'G'))) {
163 return (isCanonical());
169 public boolean isCanonical() {
170 return (_edge5 == Edge.WC) && (_edge3 == Edge.WC)
171 && (_stericity == Stericity.CIS);
174 public Stericity getStericity() {
178 public boolean isCIS() {
179 return (_stericity == Stericity.CIS);
182 public boolean isTRANS() {
183 return (_stericity == Stericity.TRANS);
186 public Edge getEdgePartner5() {
190 public Edge getEdgePartner3() {
194 public ModeleBase getPartner(ModeleBase mb) {
201 public ModeleBase getPartner5() {
205 public ModeleBase getPartner3() {
209 public int getIndex5() {
210 return _partner5.getIndex();
213 public int getIndex3() {
214 return _partner3.getIndex();
217 public void setPartner5(ModeleBase mb) {
221 public void setPartner3(ModeleBase mb) {
227 public static final String PARAM_COLOR = "color";
228 public static final String PARAM_THICKNESS = "thickness";
229 public static final String PARAM_EDGE5 = "edge5";
230 public static final String PARAM_EDGE3 = "edge3";
231 public static final String PARAM_STERICITY = "stericity";
233 public static final String VALUE_WATSON_CRICK = "wc";
234 public static final String VALUE_HOOGSTEEN = "h";
235 public static final String VALUE_SUGAR = "s";
236 public static final String VALUE_CIS = "cis";
237 public static final String VALUE_TRANS = "trans";
239 public void assignParameters(String parametersValue)
240 throws ExceptionModeleStyleBaseSyntaxError, ExceptionParameterError {
241 if (parametersValue.equals(""))
244 String[] parametersL = parametersValue.split(",");
246 ArrayList<String> namesArray = new ArrayList<String>();
247 ArrayList<String> valuesArray = new ArrayList<String>();
249 for (int i = 0; i < parametersL.length; i++) {
250 param = parametersL[i].split("=");
251 if (param.length != 2)
252 throw new ExceptionModeleStyleBaseSyntaxError(
253 "Bad parameter: '" + param[0] + "' ...");
254 namesArray.add(param[0].replace(" ", ""));
255 valuesArray.add(param[1].replace(" ", ""));
258 for (int i = 0; i < namesArray.size(); i++) {
259 if (namesArray.get(i).toLowerCase().equals(PARAM_COLOR)) {
261 _style.setCustomColor(ModelBaseStyle
262 .getSafeColor(valuesArray.get(i)));
263 } catch (NumberFormatException e) {
264 throw new ExceptionParameterError(e.getMessage(),
265 "Bad inner color Syntax:" + valuesArray.get(i));
267 } else if (namesArray.get(i).toLowerCase().equals(PARAM_THICKNESS)) {
269 _style.setThickness(Double.parseDouble(valuesArray.get(i)));
270 } catch (NumberFormatException e) {
271 throw new ExceptionParameterError(e.getMessage(),
272 "Bad value for bp thickness:" + valuesArray.get(i));
274 } else if (namesArray.get(i).toLowerCase().equals(PARAM_EDGE5)) {
275 String s = valuesArray.get(i);
276 if (s.toLowerCase().equals(VALUE_WATSON_CRICK)) {
278 } else if (s.toLowerCase().equals(VALUE_HOOGSTEEN)) {
279 setEdge5(Edge.HOOGSTEEN);
280 } else if (s.toLowerCase().equals(VALUE_SUGAR)) {
281 setEdge5(Edge.SUGAR);
283 throw new ExceptionParameterError("Bad value for edge:"
284 + valuesArray.get(i));
285 } else if (namesArray.get(i).toLowerCase().equals(PARAM_EDGE3)) {
286 String s = valuesArray.get(i);
287 if (s.toLowerCase().equals(VALUE_WATSON_CRICK)) {
289 } else if (s.toLowerCase().equals(VALUE_HOOGSTEEN)) {
290 setEdge3(Edge.HOOGSTEEN);
291 } else if (s.toLowerCase().equals(VALUE_SUGAR)) {
292 setEdge3(Edge.SUGAR);
294 throw new ExceptionParameterError("Bad value for edge:"
295 + valuesArray.get(i));
296 } else if (namesArray.get(i).toLowerCase().equals(PARAM_STERICITY)) {
297 String s = valuesArray.get(i);
298 if (s.toLowerCase().equals(VALUE_CIS)) {
299 setStericity(Stericity.CIS);
300 } else if (s.toLowerCase().equals(VALUE_TRANS)) {
301 setStericity(Stericity.TRANS);
303 throw new ExceptionParameterError(
304 "Bad value for stericity:" + valuesArray.get(i));
306 throw new ExceptionModeleStyleBaseSyntaxError(
307 "Unknown parameter:" + namesArray.get(i));
311 public String toString() {
313 result += "(" + _partner5.getIndex() + "," + _partner3.getIndex() + ")";
314 //result += " [" + _partner5.getElementStructure() + ","
315 // + _partner3.getElementStructure() + "]\n";
316 //result += " 5':" + _partner5 + "\n";
317 //result += " 3':" + _partner3;
322 public int compareTo(ModeleBP mb) {
323 if (getIndex5()!=mb.getIndex5())
324 { return getIndex5()-mb.getIndex5(); }
325 return getIndex3()-mb.getIndex3();