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.applications;
21 VARNA is a Java library for quick automated drawings RNA secondary structure
22 Copyright (C) 2007 Yann Ponty
24 This program is free software:you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by
26 the Free Software Foundation, either version 3 of the License, or
27 (at your option) any later version.
29 This program is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 GNU General Public License for more details.
34 You should have received a copy of the GNU General Public License
35 along with this program. If not, see <http://www.gnu.org/licenses/>.
38 import java.awt.BorderLayout;
39 import java.awt.Color;
40 import java.awt.Dimension;
42 import java.awt.GridLayout;
44 import javax.swing.JApplet;
45 import javax.swing.JLabel;
46 import javax.swing.JPanel;
47 import javax.swing.JTextField;
49 import fr.orsay.lri.varna.VARNAPanel;
50 import fr.orsay.lri.varna.controlers.ControleurDemoTextField;
51 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
52 import fr.orsay.lri.varna.models.rna.RNA;
55 * An RNA 2d Panel demo applet
57 * @author Yann Ponty & Darty Kévin
61 public class VARNAOnlineDemo extends JApplet {
66 private static final long serialVersionUID = -790155708306987257L;
68 private static final String DEFAULT_SEQUENCE = "CAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIA";
70 private static final String DEFAULT_STRUCTURE = "..(((((...(((((...(((((...(((((.....)))))...))))).....(((((...(((((.....)))))...))))).....)))))...)))))..";
72 private VARNAPanel _vp;
74 private JPanel _tools = new JPanel();
75 private JPanel _input = new JPanel();
77 private JPanel _seqPanel = new JPanel();
78 private JPanel _structPanel = new JPanel();
79 private JLabel _info = new JLabel();
80 private JTextField _struct = new JTextField();
81 private JTextField _seq = new JTextField();
82 private JLabel _structLabel = new JLabel(" Str:");
83 private JLabel _seqLabel = new JLabel(" Seq:");
85 private static String errorOpt = "error";
86 private boolean _error;
88 private Color _backgroundColor = Color.white;
90 private int _algoCode;
92 public VARNAOnlineDemo() {
95 _vp = new VARNAPanel(_seq.getText(), _struct.getText());
96 _vp.setErrorsOn(false);
97 } catch (ExceptionNonEqualLength e) {
103 private void RNAPanelDemoInit() {
104 int marginTools = 40;
106 setBackground(_backgroundColor);
107 _vp.setBackground(_backgroundColor);
110 _vp.getRNA().setRNA(_seq.getText(), _struct.getText());
111 _vp.setErrorsOn(false);
112 } catch (Exception e1) {
116 Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12");
118 _seqLabel.setHorizontalTextPosition(JLabel.LEFT);
119 _seqLabel.setPreferredSize(new Dimension(marginTools, 15));
120 _seq.setFont(textFieldsFont);
121 _seq.setText(_vp.getRNA().getSeq());
123 _seqPanel.setLayout(new BorderLayout());
124 _seqPanel.add(_seqLabel, BorderLayout.WEST);
125 _seqPanel.add(_seq, BorderLayout.CENTER);
127 _structLabel.setPreferredSize(new Dimension(marginTools, 15));
128 _structLabel.setHorizontalTextPosition(JLabel.LEFT);
129 _struct.setFont(textFieldsFont);
130 _struct.setText(_vp.getRNA().getStructDBN());
131 _structPanel.setLayout(new BorderLayout());
132 _structPanel.add(_structLabel, BorderLayout.WEST);
133 _structPanel.add(_struct, BorderLayout.CENTER);
135 ControleurDemoTextField controleurTextField = new ControleurDemoTextField(this);
136 _seq.addCaretListener(controleurTextField);
137 _struct.addCaretListener(controleurTextField);
139 _input.setLayout(new GridLayout(3, 0));
140 _input.add(_seqPanel);
141 _input.add(_structPanel);
143 _tools.setLayout(new BorderLayout());
144 _tools.add(_input, BorderLayout.CENTER);
145 _tools.add(_info, BorderLayout.SOUTH);
147 getContentPane().setLayout(new BorderLayout());
148 getContentPane().add(_vp, BorderLayout.CENTER);
149 getContentPane().add(_tools, BorderLayout.SOUTH);
152 _vp.getVARNAUI().UIRadiate();
155 public String[][] getParameterInfo() {
157 // Parameter Name Kind of Value Description,
158 { "sequenceDBN", "String", "A raw RNA sequence" },
159 { "structureDBN", "String",
160 "An RNA structure in dot bracket notation (DBN)" },
161 { errorOpt, "boolean", "To show errors" }, };
166 retrieveParametersValues();
167 _vp.setBackground(_backgroundColor);
171 private Color getSafeColor(String col, Color def) {
174 result = Color.decode(col);
175 } catch (Exception e) {
177 result = Color.getColor(col, def);
178 } catch (Exception e2) {
185 private String getParameterValue(String key, String def) {
187 tmp = getParameter(key);
195 private void retrieveParametersValues() {
196 _error = Boolean.parseBoolean(getParameterValue(errorOpt, "false"));
197 _vp.setErrorsOn(_error);
198 _backgroundColor = getSafeColor(getParameterValue("background",
199 _backgroundColor.toString()), _backgroundColor);
200 _vp.setBackground(_backgroundColor);
201 _seq.setText(getParameterValue("sequenceDBN", ""));
202 _struct.setText(getParameterValue("structureDBN", ""));
203 String _algo = getParameterValue("algorithm", "radiate");
204 if (_algo.equals("circular"))
205 _algoCode = RNA.DRAW_MODE_CIRCULAR;
206 else if (_algo.equals("naview"))
207 _algoCode = RNA.DRAW_MODE_NAVIEW;
208 else if (_algo.equals("line"))
209 _algoCode = RNA.DRAW_MODE_LINEAR;
211 _algoCode = RNA.DRAW_MODE_RADIATE;
212 if (_seq.getText().equals("") && _struct.getText().equals("")) {
213 _seq.setText(DEFAULT_SEQUENCE);
214 _struct.setText(DEFAULT_STRUCTURE);
217 _vp.drawRNA(_seq.getText(), _struct.getText(), _algoCode);
218 } catch (ExceptionNonEqualLength e) {
224 public VARNAPanel get_varnaPanel() {
228 public void set_varnaPanel(VARNAPanel surface) {
232 public JTextField get_struct() {
236 public void set_struct(JTextField _struct) {
237 this._struct = _struct;
240 public JTextField get_seq() {
244 public void set_seq(JTextField _seq) {
248 public JLabel get_info() {
252 public void set_info(JLabel _info) {