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.awt.geom.Point2D;
23 import javax.xml.transform.sax.TransformerHandler;
25 import org.xml.sax.SAXException;
26 import org.xml.sax.helpers.AttributesImpl;
28 import fr.orsay.lri.varna.utils.XMLUtils;
32 * <b>The RNA base comparison model</b>. In each bases we'll place <b>two
33 * characters</b> representing nitrogenous bases of both RNA that have to be
34 * compared. So, in each base in the comparison model, we'll have a <b>couple of
35 * bases</b>, with the same coordinates on the final drawing.
40 public class ModeleBasesComparison extends ModeleBase {
49 private static final long serialVersionUID = -2733063250714562463L;
52 * The base of the first RNA associated with the base of the second RNA.
54 private Character _base1;
57 * The base of the second RNA associated with the base of the first RNA.
59 private Character _base2;
62 * This ModeleBasesComparison owning statement. It's value will be 0 if this
63 * base is common for both RNA that had been compared, 1 if this base is
64 * related to the first RNA, 2 if related to the second. Default is -1.
66 private int _appartenance = -1;
69 * This base's offset in the sequence
73 public static String XML_ELEMENT_NAME = "NTPair";
74 public static String XML_VAR_FIRST_CONTENT_NAME = "base1";
75 public static String XML_VAR_SECOND_CONTENT_NAME = "base2";
76 public static String XML_VAR_MEMBERSHIP_NAME = "type";
80 public void toXML(TransformerHandler hd) throws SAXException
82 AttributesImpl atts = new AttributesImpl();
83 atts.addAttribute("","",XML_VAR_INDEX_NAME,"CDATA",""+_index);
84 atts.addAttribute("","",XML_VAR_NUMBER_NAME,"CDATA",""+_realIndex);
85 atts.addAttribute("","",XML_VAR_CUSTOM_DRAWN_NAME,"CDATA",""+_colorie);
86 atts.addAttribute("","",XML_VAR_LABEL_NAME,"CDATA",""+_label);
87 atts.addAttribute("","",XML_VAR_MEMBERSHIP_NAME,"CDATA",""+_appartenance);
88 atts.addAttribute("","","VALUE","CDATA",""+_value);
89 hd.startElement("","",XML_ELEMENT_NAME,atts);
91 hd.startElement("","",XML_VAR_FIRST_CONTENT_NAME,atts);
92 XMLUtils.exportCDATAString(hd, ""+_base1);
93 hd.endElement("","",XML_VAR_FIRST_CONTENT_NAME);
95 hd.startElement("","",XML_VAR_SECOND_CONTENT_NAME,atts);
96 XMLUtils.exportCDATAString(hd, ""+_base2);
97 hd.endElement("","",XML_VAR_SECOND_CONTENT_NAME);
99 _coords.toXML(hd,XML_VAR_POSITION_NAME);
100 _center.toXML(hd,XML_VAR_CENTER_NAME);
102 { _styleBase.toXML(hd); }
103 hd.endElement("","",XML_ELEMENT_NAME);
109 * -> END LOCAL FIELDS <--
112 public static Color FIRST_RNA_COLOR = Color.decode("#FFDD99");
113 public static Color SECOND_RNA_COLOR = Color.decode("#99DDFF");
114 public static Color BOTH_RNA_COLOR = Color.decode("#99DD99");
115 public static Color DEFAULT_RNA_COLOR = Color.white;
122 * Creates a new comparison base with the default display style and no
125 public ModeleBasesComparison(int index) {
126 this(' ', ' ', index);
130 * Creates a new comparison base at the specified coordinates, with the
131 * default display style and no nitrogenous bases.
134 * - The coordinates in which the comparison base has to be
137 public ModeleBasesComparison(Point2D coords, int index) {
138 this(' ', ' ', new Point2D.Double(coords.getX(), coords.getY()), index);
142 * Creates a new comparison base with the specified nitrogenous bases.
145 * - The first RNA' nitrogenous base
147 * - The second RNA' nitrogenous base
149 public ModeleBasesComparison(char base1, char base2, int index) {
150 this(base1, base2, -1, index);
154 * Creates a new comparison base with the specified nitrogenous bases, at
155 * the specified coordinates.
158 * - The first RNA' nitrogenous base
160 * - The second RNA' nitrogenous base
162 * - The coordinates in which the comparison base has to be
165 public ModeleBasesComparison(char base1, char base2, Point2D coords,
167 this(new Point2D.Double(coords.getX(), coords.getY()), base1, base2,
168 true, new ModelBaseStyle(), -1, index);
172 * Creates a new comparison base with the specified nitrogenous bases.
175 * - The first RNA' nitrogenous base
177 * - The second RNA' nitrogenous base
179 public ModeleBasesComparison(char base1, char base2, int elementStructure,
181 this(new Point2D.Double(), base1, base2, true, new ModelBaseStyle(),
182 elementStructure, index);
186 * Creates a new comparison base with the specified nitrogenous bases.
189 * - This base's XY coordinates
191 * - The first RNA' nitrogenous base
193 * - The second RNA' nitrogenous base
195 * - Whether or not this base will be drawn
197 * - The drawing style for this base
198 * @param elementStructure
199 * - The index of a bp partner in the secondary structure
201 * - Index of this base in its initial sequence
203 public ModeleBasesComparison(Point2D coords, char base1, char base2,
204 boolean colorie, ModelBaseStyle mb, int elementStructure, int index) {
209 _coords = new VARNAPoint(coords.getX(), coords.getY());
214 * -> END CONSTRUCTORS <--
222 * Return the display style associated to this comparison base.
224 * @return The display style associated to this comparison base.
226 public ModelBaseStyle getStyleBase() {
229 return new ModelBaseStyle();
233 * Allows to know if this comparison base is colored.
235 * @return TRUE if this comparison base is colored, else FALSE.
237 public Boolean getColored() {
242 * Sets the coloration authorization of this comparison base.
245 * - TRUE if this comparison base has to be colored, else FALSE.
247 public void set_colored(Boolean colored) {
248 this._colorie = colored;
253 * Return the base of the first RNA in this comparison base.
255 * @return The base of the first RNA in this comparison base.
257 public Character getBase1() {
262 * Sets the base of the first RNA in this comparison base.
265 * - The base of the first RNA in this comparison base.
267 public void setBase1(Character _base1) {
268 this._base1 = _base1;
272 * Return the base of the second RNA in this comparison base.
274 * @return The base of the second RNA in this comparison base.
276 public Character getBase2() {
281 * Sets the base of the second RNA in this comparison base.
284 * - The base of the second RNA in this comparison base.
286 public void setBase2(Character _base2) {
287 this._base2 = _base2;
291 * --> END GETTERS & SETTERS <--
295 * Gets the string representation of the two bases in this
296 * ModeleBasesComparison.
298 * @return the string representation of the two bases in this
299 * ModeleBasesComparison.
301 public String getBases() {
302 return String.valueOf(_base1) + String.valueOf(_base2);
305 public String getContent() {
311 * Gets this base's related RNA.
313 * @return 0 if this base is common for both RNA<br>
314 * 1 if this base is related to the first RNA<br>
315 * 2 if this base is related to the second RNA
317 public int get_appartenance() {
318 return _appartenance;
322 * Sets this base's related RNA.
324 * @param _appartenance
325 * : 0 if this base is common for both RNA<br>
326 * 1 if this base is related to the first RNA<br>
327 * 2 if this base is related to the second RNA.
329 public void set_appartenance(int _appartenance) {
330 if (_appartenance == 0) {
331 this.getStyleBase().setBaseInnerColor(BOTH_RNA_COLOR);
332 } else if (_appartenance == 1) {
333 this.getStyleBase().setBaseInnerColor(FIRST_RNA_COLOR);
334 } else if (_appartenance == 2) {
335 this.getStyleBase().setBaseInnerColor(SECOND_RNA_COLOR);
337 this.getStyleBase().setBaseInnerColor(DEFAULT_RNA_COLOR);
339 this._appartenance = _appartenance;
344 public int getIndex() {
349 public void setContent(String s) {
350 this.setBase1(s.charAt(0));
351 this.setBase2(s.charAt(1));