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;
35 import fr.orsay.lri.varna.controlers.ControleurInterpolator;
36 import fr.orsay.lri.varna.exceptions.ExceptionDrawingAlgorithm;
37 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
38 import fr.orsay.lri.varna.exceptions.ExceptionModeleStyleBaseSyntaxError;
39 import fr.orsay.lri.varna.exceptions.ExceptionNAViewAlgorithm;
40 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
41 import fr.orsay.lri.varna.exceptions.ExceptionParameterError;
42 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
43 import fr.orsay.lri.varna.exceptions.MappingException;
44 import fr.orsay.lri.varna.models.VARNAConfig;
45 import fr.orsay.lri.varna.models.rna.Mapping;
46 import fr.orsay.lri.varna.models.rna.ModeleBase;
47 import fr.orsay.lri.varna.models.rna.ModelBaseStyle;
48 import fr.orsay.lri.varna.models.rna.RNA;
50 import fr.orsay.lri.varna.interfaces.InterfaceVARNAListener;;
52 public class SuperpositionDemo extends JFrame implements InterfaceVARNAListener {
57 private static final long serialVersionUID = -790155708306987257L;
59 private static final String DEFAULT_SEQUENCE1 = "CGCGCACGCGAUAUUUCGCGUCGCGCAUUUGCGCGUAGCGCG";
60 private static final String DEFAULT_SEQUENCE2 = "CGCGCACGCGAUAUUUCGCGUCGCGCAUUUGCGCGUAGCGCG";
62 private static final String DEFAULT_STRUCTURE1 = "(((((.(((((----....----))))).(((((....)))))..)))))";
63 private static final String DEFAULT_STRUCTURE2 = "(((((.(((((((((....))))))))).--------------..)))))";
64 // private static final String DEFAULT_STRUCTURE1 = "((((....))))";
65 // private static final String DEFAULT_STRUCTURE2 =
66 // "((((..(((....)))..))))";
68 private VARNAPanel _vpMaster;
69 private VARNAPanel _vpSlave;
71 private JPanel _tools = new JPanel();
72 private JPanel _input = new JPanel();
74 private JPanel _seqPanel = new JPanel();
75 private JPanel _struct1Panel = new JPanel();
76 private JPanel _struct2Panel = new JPanel();
77 private JLabel _info = new JLabel();
78 private JTextField _struct1 = new JTextField(DEFAULT_STRUCTURE1);
79 private JTextField _struct2 = new JTextField(DEFAULT_STRUCTURE2);
80 private JTextField _seq1 = new JTextField(DEFAULT_SEQUENCE1);
81 private JTextField _seq2 = new JTextField(DEFAULT_SEQUENCE2);
82 private JLabel _struct1Label = new JLabel(" Str1:");
83 private JLabel _struct2Label = new JLabel(" Str2:");
84 private JLabel _seqLabel = new JLabel(" Seq:");
85 private JButton _goButton = new JButton("Go");
86 private JButton _switchButton = new JButton("Switch");
88 private String _str1Backup = "";
89 private String _str2Backup = "";
90 private RNA _RNA1 = new RNA();
91 private RNA _RNA2 = new RNA();
93 private static String errorOpt = "error";
94 @SuppressWarnings("unused")
95 private boolean _error;
97 private Color _backgroundColor = Color.white;
99 @SuppressWarnings("unused")
100 private int _algoCode;
102 private int _currentDisplay = 1;
104 public static ModelBaseStyle createStyle(String txt)
106 ModelBaseStyle result = new ModelBaseStyle();
108 result.assignParameters(txt);
109 } catch (ExceptionModeleStyleBaseSyntaxError e) {
110 // TODO Auto-generated catch block
112 } catch (ExceptionParameterError e) {
113 // TODO Auto-generated catch block
119 public void applyTo(VARNAPanel vp, ModelBaseStyle mb, int[] indices)
121 for(int i=0;i<indices.length;i++)
123 ModeleBase m = vp.getRNA().getBaseAt(indices[i]);
125 if (m.getElementStructure()!=-1)
127 vp.getRNA().getBaseAt(m.getElementStructure()).setStyleBase(mb);
134 public SuperpositionDemo() {
137 _vpMaster = new VARNAPanel(getText1(), getStruct1());
138 _vpSlave = new VARNAPanel(getText2(), getStruct2());
139 } catch (ExceptionNonEqualLength e) {
140 _vpMaster.errorDialog(e);
142 _vpMaster.setPreferredSize(new Dimension(400, 400));
146 private void RNAPanelDemoInit() {
147 int marginTools = 40;
149 setBackground(_backgroundColor);
150 _vpMaster.setBackground(_backgroundColor);
151 _vpMaster.addVARNAListener(this);
152 //_vpSlave.setModifiable(false);
153 _vpSlave.setBackground(Color.decode("#F0F0F0"));
155 _vpMaster.drawRNA(getRNA((_currentDisplay)%2));
156 _vpSlave.drawRNA(getRNA((_currentDisplay+1)%2));
158 /*ModeleStyleBase red = createStyle("label=#ff4d4d,fill=#ffdddd,outline=#ff4d4d");
159 int[] ired = {6,7,8,9,10};
160 applyTo(_vpMaster, red, ired);
161 applyTo(_vpSlave, red, ired);
162 ModeleStyleBase blue = createStyle("label=#0000ff,fill=#ddddff,outline=#0000ff");
163 int[] iblue = {0,1,2,3,4};
164 applyTo(_vpMaster, blue, iblue);
165 applyTo(_vpSlave, blue, iblue);
166 ModeleStyleBase purple = createStyle("label=#cc00cc,fill=#ffddff,outline=#cc00cc");
167 int[] ipurple = {21,22,23,24,25};
168 applyTo(_vpMaster, purple, ipurple);
169 ModeleStyleBase green = createStyle("label=#009900,fill=#aaeeaa,outline=#009900");
170 int[] igreen = {11,12,13,14};
171 applyTo(_vpSlave, green, igreen);*/
173 Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12");
175 _seqLabel.setHorizontalTextPosition(JLabel.LEFT);
176 _seqLabel.setPreferredSize(new Dimension(marginTools, 15));
177 _seq1.setFont(textFieldsFont);
178 _seq1.setText(getRNA1().getSeq());
179 _seq2.setFont(textFieldsFont);
180 _seq2.setText(getRNA2().getSeq());
182 _goButton.addActionListener(new ActionListener() {
184 public void actionPerformed(ActionEvent e) {
185 _currentDisplay = (_currentDisplay + 1) % 2;
186 _vpMaster.drawRNA(getRNA(_currentDisplay));
187 _vpSlave.drawRNA(getRNA((_currentDisplay + 1) % 2));
188 onStructureRedrawn();
192 _switchButton.addActionListener(new ActionListener() {
193 public void actionPerformed(ActionEvent e) {
195 _currentDisplay = (_currentDisplay + 1) % 2;
197 Mapping m = Mapping.readMappingFromAlignment(
198 getStruct(_currentDisplay), getStruct((_currentDisplay+1)%2));
199 Mapping m2 = Mapping.readMappingFromAlignment(
200 getStruct((_currentDisplay+1)%2), getStruct(_currentDisplay));
201 _vpMaster.showRNAInterpolated(getRNA(_currentDisplay), m);
202 _vpSlave.showRNAInterpolated(getRNA((_currentDisplay+1)%2), m2);
203 onStructureRedrawn();
205 catch (MappingException e3)
208 _vpMaster.drawRNAInterpolated(getText(_currentDisplay),getStruct(_currentDisplay));
209 } catch (ExceptionNonEqualLength e1) {
210 // TODO Auto-generated catch block
211 e1.printStackTrace();
219 _seqPanel.setLayout(new BorderLayout());
220 _seqPanel.add(_seqLabel, BorderLayout.WEST);
221 _seqPanel.add(_seq1, BorderLayout.CENTER);
223 _struct1Label.setPreferredSize(new Dimension(marginTools, 15));
224 _struct1Label.setHorizontalTextPosition(JLabel.LEFT);
225 _struct1.setFont(textFieldsFont);
226 _struct1Panel.setLayout(new BorderLayout());
227 _struct1Panel.add(_struct1Label, BorderLayout.WEST);
228 _struct1Panel.add(_struct1, BorderLayout.CENTER);
230 _struct2Label.setPreferredSize(new Dimension(marginTools, 15));
231 _struct2Label.setHorizontalTextPosition(JLabel.LEFT);
232 _struct2.setFont(textFieldsFont);
233 _struct2Panel.setLayout(new BorderLayout());
234 _struct2Panel.add(_struct2Label, BorderLayout.WEST);
235 _struct2Panel.add(_struct2, BorderLayout.CENTER);
237 _input.setLayout(new GridLayout(3, 0));
238 _input.add(_seqPanel);
239 _input.add(_struct1Panel);
240 _input.add(_struct2Panel);
242 JPanel goPanel = new JPanel();
243 goPanel.setLayout(new BorderLayout());
245 _tools.setLayout(new BorderLayout());
246 _tools.add(_input, BorderLayout.CENTER);
247 _tools.add(_info, BorderLayout.SOUTH);
248 _tools.add(goPanel, BorderLayout.EAST);
250 goPanel.add(_goButton, BorderLayout.CENTER);
251 goPanel.add(_switchButton, BorderLayout.SOUTH);
253 getContentPane().setLayout(new BorderLayout());
254 JPanel VARNAs = new JPanel();
255 VARNAs.setLayout(new GridLayout(1,2));
256 VARNAs.add(_vpMaster);
257 VARNAs.add(_vpSlave);
258 getContentPane().add(VARNAs, BorderLayout.CENTER);
259 getContentPane().add(_tools, BorderLayout.SOUTH);
263 _vpMaster.getVARNAUI().UIRadiate();
264 _vpSlave.getVARNAUI().UIRadiate();
266 onStructureRedrawn();
269 public RNA getMasterRNA()
271 return getRNA(_currentDisplay);
274 public RNA getSlaveRNA1()
276 return getRNA((_currentDisplay+1)%2);
279 public RNA getSlaveRNA2()
281 return getRNA((_currentDisplay+2)%2);
285 public RNA getRNA(int i) {
287 { return getRNA1(); }
289 { return getRNA2(); }
293 public RNA getRNA1() {
294 if (!_str1Backup.equals(getStruct1())) {
296 _RNA1.setRNA(getText1(), getStruct1());
297 _RNA1.drawRNA(_vpMaster.getDrawMode(),_vpMaster.getConfig());
298 } catch (ExceptionUnmatchedClosingParentheses e) {
300 } catch (ExceptionFileFormatOrSyntax e1) {
301 _vpMaster.errorDialog(e1);
302 } catch (ExceptionDrawingAlgorithm e) {
303 // TODO Auto-generated catch block
306 _str1Backup = getStruct1();
311 public RNA getRNA2() {
312 if (!_str2Backup.equals(getStruct2())) {
314 _RNA2.setRNA(getText2(), getStruct2());
315 _RNA2.drawRNA(_vpMaster.getDrawMode(),_vpMaster.getConfig());
316 } catch (ExceptionUnmatchedClosingParentheses e) {
318 } catch (ExceptionFileFormatOrSyntax e1) {
319 _vpMaster.errorDialog(e1);
320 } catch (ExceptionDrawingAlgorithm e) {
321 // TODO Auto-generated catch block
324 _str2Backup = getStruct2();
329 public String getText(int i)
334 public String getStruct(int i)
337 return _struct1.getText();
339 return _struct2.getText();
343 public String getText1()
345 return _seq1.getText();
348 public String getText2()
350 return _seq2.getText();
353 public String getStruct1() {
354 return cleanStruct(_struct1.getText());
357 public String getStruct2() {
358 return cleanStruct(_struct2.getText());
361 private String cleanStruct(String struct) {
362 struct = struct.replaceAll("[:-]", "");
366 public String[][] getParameterInfo() {
368 // Parameter Name Kind of Value Description,
369 { "sequenceDBN", "String", "A raw RNA sequence" },
370 { "structureDBN", "String",
371 "An RNA structure in dot bracket notation (DBN)" },
372 { errorOpt, "boolean", "To show errors" }, };
377 _vpMaster.setBackground(_backgroundColor);
381 @SuppressWarnings("unused")
382 private Color getSafeColor(String col, Color def) {
385 result = Color.decode(col);
386 } catch (Exception e) {
388 result = Color.getColor(col, def);
389 } catch (Exception e2) {
396 public VARNAPanel get_varnaPanel() {
400 public void set_varnaPanel(VARNAPanel surface) {
404 public JTextField get_struct() {
408 public void set_struct(JTextField _struct) {
409 this._struct1 = _struct;
412 public JLabel get_info() {
416 public void set_info(JLabel _info) {
420 public static void main(String[] args) {
421 SuperpositionDemo d = new SuperpositionDemo();
422 d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
427 public void onStructureRedrawn() {
429 Mapping m = Mapping.readMappingFromAlignment(
430 this.getStruct((_currentDisplay+1)%2), getStruct((_currentDisplay)%2));
431 ControleurInterpolator.moveNearOtherRNA(getRNA((_currentDisplay)%2), getRNA((_currentDisplay+1)%2), m);
435 catch (MappingException e3) {System.out.println(e3.toString());}
438 public void onWarningEmitted(String s) {
439 // TODO Auto-generated method stub
443 public void onLoad(String path) {
444 // TODO Auto-generated method stub
448 public void onLoaded() {
449 // TODO Auto-generated method stub
453 public void onUINewStructure(VARNAConfig v, RNA r) {
454 // TODO Auto-generated method stub
458 public void onZoomLevelChanged(){
459 // TODO Auto-generated method stub
463 public void onTranslationChanged() {
464 // TODO Auto-generated method stub