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;
20 import java.awt.BorderLayout;
21 import java.awt.Color;
22 import java.awt.Dimension;
24 import java.awt.GridLayout;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
28 import javax.swing.JButton;
29 import javax.swing.JFrame;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
34 import fr.orsay.lri.varna.VARNAPanel;
36 import fr.orsay.lri.varna.models.rna.RNA;
39 public class AlignmentDemo extends JFrame{
44 private static final long serialVersionUID = -790155708306987257L;
46 private static final String DEFAULT_SEQUENCE1 = "CGCGCACGCGA----UAUU----UCGCGUCGCGCAUUUGCGCGUAGCGCG";
47 private static final String DEFAULT_STRUCTURE1 = "(((((.(((((----....----))))).(((((....)))))..)))))";
49 private static final String DEFAULT_SEQUENCE2 = "CGCGCACGCGSGCGCGUUUGCGCUCGCGU---------------AGCGCG";
50 private static final String DEFAULT_STRUCTURE2 = "(((((.(((((((((....))))))))).--------------..)))))";
51 // private static final String DEFAULT_STRUCTURE1 = "((((....))))";
52 // private static final String DEFAULT_STRUCTURE2 =
53 // "((((..(((....)))..))))";
55 private VARNAPanel _vpMaster;
57 private JPanel _tools = new JPanel();
58 private JPanel _input = new JPanel();
60 private JPanel _seq1Panel = new JPanel();
61 private JPanel _seq2Panel = new JPanel();
62 private JPanel _struct1Panel = new JPanel();
63 private JPanel _struct2Panel = new JPanel();
64 private JLabel _info = new JLabel();
65 private JTextField _struct1 = new JTextField(DEFAULT_STRUCTURE1);
66 private JTextField _struct2 = new JTextField(DEFAULT_STRUCTURE2);
67 private JTextField _seq1 = new JTextField(DEFAULT_SEQUENCE1);
68 private JTextField _seq2 = new JTextField(DEFAULT_SEQUENCE2);
69 private JLabel _struct1Label = new JLabel(" Str1:");
70 private JLabel _struct2Label = new JLabel(" Str2:");
71 private JLabel _seq1Label = new JLabel(" Seq1:");
72 private JLabel _seq2Label = new JLabel(" Seq2:");
73 private JButton _goButton = new JButton("Go");
75 private String _str1Backup = "";
76 private String _str2Backup = "";
77 private String _seq1Backup = "";
78 private String _seq2Backup = "";
79 private RNA _RNA = new RNA();
81 private static String errorOpt = "error";
82 @SuppressWarnings("unused")
83 private boolean _error;
85 private Color _backgroundColor = Color.white;
87 @SuppressWarnings("unused")
88 private int _algoCode;
91 public AlignmentDemo() {
93 _vpMaster = new VARNAPanel(getSeq1(), getStruct1(), getSeq2(), getStruct2(), RNA.DRAW_MODE_RADIATE,"");
94 _vpMaster.setPreferredSize(new Dimension(600, 400));
98 private void RNAPanelDemoInit() {
101 setBackground(_backgroundColor);
102 _vpMaster.setBackground(_backgroundColor);
104 Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12");
107 _goButton.addActionListener(new ActionListener() {
109 public void actionPerformed(ActionEvent e) {
110 _vpMaster.drawRNA(getSeq1(), getStruct1(), getSeq2(), getStruct2(), _vpMaster.getDrawMode());
116 _seq1Label.setHorizontalTextPosition(JLabel.LEFT);
117 _seq1Label.setPreferredSize(new Dimension(marginTools, 15));
118 _seq1.setFont(textFieldsFont);
120 _seq1Panel.setLayout(new BorderLayout());
121 _seq1Panel.add(_seq1Label, BorderLayout.WEST);
122 _seq1Panel.add(_seq1, BorderLayout.CENTER);
124 _seq2Label.setHorizontalTextPosition(JLabel.LEFT);
125 _seq2Label.setPreferredSize(new Dimension(marginTools, 15));
126 _seq2.setFont(textFieldsFont);
128 _seq2Panel.setLayout(new BorderLayout());
129 _seq2Panel.add(_seq2Label, BorderLayout.WEST);
130 _seq2Panel.add(_seq2, BorderLayout.CENTER);
132 _struct1Label.setPreferredSize(new Dimension(marginTools, 15));
133 _struct1Label.setHorizontalTextPosition(JLabel.LEFT);
134 _struct1.setFont(textFieldsFont);
135 _struct1Panel.setLayout(new BorderLayout());
136 _struct1Panel.add(_struct1Label, BorderLayout.WEST);
137 _struct1Panel.add(_struct1, BorderLayout.CENTER);
139 _struct2Label.setPreferredSize(new Dimension(marginTools, 15));
140 _struct2Label.setHorizontalTextPosition(JLabel.LEFT);
141 _struct2.setFont(textFieldsFont);
142 _struct2Panel.setLayout(new BorderLayout());
143 _struct2Panel.add(_struct2Label, BorderLayout.WEST);
144 _struct2Panel.add(_struct2, BorderLayout.CENTER);
146 _input.setLayout(new GridLayout(4, 0));
147 _input.add(_seq1Panel);
148 _input.add(_struct1Panel);
149 _input.add(_seq2Panel);
150 _input.add(_struct2Panel);
152 JPanel goPanel = new JPanel();
153 goPanel.setLayout(new BorderLayout());
155 _tools.setLayout(new BorderLayout());
156 _tools.add(_input, BorderLayout.CENTER);
157 _tools.add(_info, BorderLayout.SOUTH);
158 _tools.add(goPanel, BorderLayout.EAST);
160 goPanel.add(_goButton, BorderLayout.CENTER);
162 getContentPane().setLayout(new BorderLayout());
163 JPanel VARNAs = new JPanel();
164 VARNAs.setLayout(new GridLayout(1,1));
165 VARNAs.add(_vpMaster);
166 getContentPane().add(VARNAs, BorderLayout.CENTER);
167 getContentPane().add(_tools, BorderLayout.SOUTH);
170 _vpMaster.getVARNAUI().UIRadiate();
173 public RNA getRNA() {
175 if (!( _str1Backup.equals(getStruct1())
176 && _str2Backup.equals(getStruct2())
177 && _seq1Backup.equals(getSeq1())
178 && _seq2Backup.equals(getSeq2())
180 _vpMaster.drawRNA(getSeq1(), getStruct1(), getSeq2(), getStruct2(), _vpMaster.getDrawMode());
181 _RNA = _vpMaster.getRNA();
182 _str1Backup = getStruct1();
183 _str2Backup = getStruct2();
184 _seq1Backup = getSeq1();
185 _seq2Backup = getSeq2();
191 public String getStruct1() {
192 return cleanStruct(_struct1.getText());
195 public String getStruct2() {
196 return cleanStruct(_struct2.getText());
199 public String getSeq1() {
200 return cleanStruct(_seq1.getText());
203 public String getSeq2() {
204 return cleanStruct(_seq2.getText());
208 private String cleanStruct(String struct) {
209 struct = struct.replaceAll("[:-]", "-");
213 public String[][] getParameterInfo() {
215 // Parameter Name Kind of Value Description,
216 { "sequenceDBN", "String", "A raw RNA sequence" },
217 { "structureDBN", "String",
218 "An RNA structure in dot bracket notation (DBN)" },
219 { errorOpt, "boolean", "To show errors" }, };
224 _vpMaster.setBackground(_backgroundColor);
228 @SuppressWarnings("unused")
229 private Color getSafeColor(String col, Color def) {
232 result = Color.decode(col);
233 } catch (Exception e) {
235 result = Color.getColor(col, def);
236 } catch (Exception e2) {
243 public VARNAPanel get_varnaPanel() {
247 public void set_varnaPanel(VARNAPanel surface) {
251 public JTextField get_struct() {
255 public void set_struct(JTextField _struct) {
256 this._struct1 = _struct;
259 public JTextField get_seq() {
263 public void set_seq(JTextField _seq) {
267 public JLabel get_info() {
271 public void set_info(JLabel _info) {
275 public static void main(String[] args) {
276 AlignmentDemo d = new AlignmentDemo();
277 d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
282 public void onWarningEmitted(String s) {
283 // TODO Auto-generated method stub