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;
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 it under
25 * the terms of the GNU General Public License as published by the Free Software
26 * Foundation, either version 3 of the License, or (at your option) any later
29 * This program is distributed in the hope that it will be useful, but WITHOUT
30 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
31 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
34 * You should have received a copy of the GNU General Public License along with
35 * this program. If not, see <http://www.gnu.org/licenses/>.
38 import java.awt.Color;
39 import java.awt.Dimension;
41 import java.awt.Point;
42 import java.awt.geom.Point2D;
43 import java.io.BufferedReader;
45 import java.io.FileNotFoundException;
46 import java.io.FileReader;
47 import java.io.IOException;
48 import java.io.InputStream;
49 import java.io.InputStreamReader;
51 import java.net.URLConnection;
52 import java.util.ArrayList;
53 import java.util.Collection;
55 import fr.orsay.lri.varna.VARNAPanel;
56 import fr.orsay.lri.varna.exceptions.ExceptionDrawingAlgorithm;
57 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
58 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
59 import fr.orsay.lri.varna.exceptions.ExceptionModeleStyleBaseSyntaxError;
60 import fr.orsay.lri.varna.exceptions.ExceptionNAViewAlgorithm;
61 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
62 import fr.orsay.lri.varna.exceptions.ExceptionParameterError;
63 import fr.orsay.lri.varna.factories.RNAFactory;
64 import fr.orsay.lri.varna.interfaces.InterfaceParameterLoader;
65 import fr.orsay.lri.varna.models.annotations.ChemProbAnnotation;
66 import fr.orsay.lri.varna.models.annotations.HighlightRegionAnnotation;
67 import fr.orsay.lri.varna.models.annotations.TextAnnotation;
68 import fr.orsay.lri.varna.models.rna.ModeleBase;
69 import fr.orsay.lri.varna.models.rna.ModeleColorMap;
70 import fr.orsay.lri.varna.models.rna.ModeleBP;
71 import fr.orsay.lri.varna.models.rna.ModelBaseStyle;
72 import fr.orsay.lri.varna.models.rna.RNA;
75 * An RNA 2d Panel demo applet
81 public class VARNAConfigLoader {
83 private static final int MAXSTYLE = 50;
87 public static String algoOpt = "algorithm";
88 public static String annotationsOpt = "annotations";
89 public static String applyBasesStyleOpt = "applyBasesStyle";
90 public static String auxBPsOpt = "auxBPs";
91 public static String autoHelicesOpt = "autoHelices";
92 public static String autoInteriorLoopsOpt = "autoInteriorLoops";
93 public static String autoTerminalLoopsOpt = "autoTerminalLoops";
95 public static String backboneColorOpt = "backbone";
96 public static String backgroundColorOpt = "background";
97 public static String baseInnerColorOpt = "baseInner";
98 public static String baseNameColorOpt = "baseName";
99 public static String baseNumbersColorOpt = "baseNum";
100 public static String baseOutlineColorOpt = "baseOutline";
101 public static String basesStyleOpt = "basesStyle";
102 public static String borderOpt = "border";
103 public static String bondColorOpt = "bp";
104 public static String bpIncrementOpt = "bpIncrement";
105 public static String bpStyleOpt = "bpStyle";
107 public static String colorMapOpt = "colorMap";
108 public static String colorMapCaptionOpt = "colorMapCaption";
109 public static String colorMapDefOpt = "colorMapStyle";
110 public static String colorMapMinOpt = "colorMapMin";
111 public static String colorMapMaxOpt = "colorMapMax";
112 public static String comparisonModeOpt = "comparisonMode";
113 public static String chemProbOpt = "chemProb";
114 public static String customBasesOpt = "customBases";
115 public static String customBPsOpt = "customBPs";
117 public static String drawNCOpt = "drawNC";
118 public static String drawBasesOpt = "drawBases";
119 public static String drawTertiaryOpt = "drawTertiary";
120 public static String drawColorMapOpt = "drawColorMap";
121 public static String drawBackboneOpt = "drawBackbone";
123 public static String errorOpt = "error";
125 public static String fillBasesOpt = "fillBases";
126 public static String firstSequenceForComparisonOpt = "firstSequence";
127 public static String firstStructureForComparisonOpt = "firstStructure";
128 public static String flatExteriorLoopOpt = "flat";
129 public static String flipOpt = "flip";
131 public static String gapsBaseColorOpt = "gapsColor";
133 public static String highlightRegionOpt = "highlightRegion";
135 public static String nonStandardColorOpt = "nsBasesColor";
136 public static String numColumnsOpt = "rows";
137 public static String numRowsOpt = "columns";
139 public static String orientationOpt = "orientation";
141 public static String modifiableOpt = "modifiable";
143 public static String periodNumOpt = "periodNum";
145 public static String rotationOpt = "rotation";
147 public static String secondSequenceForComparisonOpt = "secondSequence";
148 public static String secondStructureForComparisonOpt = "secondStructure";
149 public static String sequenceOpt = "sequenceDBN";
150 public static String spaceBetweenBasesOpt = "spaceBetweenBases";
151 public static String structureOpt = "structureDBN";
153 public static String titleOpt = "title";
154 public static String titleColorOpt = "titleColor";
155 public static String titleSizeOpt = "titleSize";
157 public static String URLOpt = "url";
159 public static String warningOpt = "warning";
161 public static String zoomOpt = "zoom";
162 public static String zoomAmountOpt = "zoomAmount";
164 // Applet assignable parameters
165 private String _algo;
166 public String _annotations;
167 public String _chemProbs;
168 private double _rotation;
170 private String _sseq;
171 private String _sstruct;
173 private int _numRows;
174 private int _numColumns;
176 private String _title;
177 private int _titleSize;
178 private Color _titleColor;
180 private String _auxBPs;
181 private String _highlightRegion;
183 private boolean _autoHelices;
184 private boolean _autoInteriorLoops;
185 private boolean _autoTerminalLoops;
187 private boolean _drawBackbone;
188 private Color _backboneColor;
189 private Color _bondColor;
190 private VARNAConfig.BP_STYLE _bpStyle;
191 private Color _baseOutlineColor;
192 private Color _baseInnerColor;
193 private Color _baseNumColor;
194 private Color _baseNameColor;
195 private Color _gapsColor;
196 private Color _nonStandardColor;
198 private boolean _flatExteriorLoop;
199 private String _flip;
201 private String _customBases;
202 private String _customBPs;
204 private String _colorMapStyle;
205 private String _colorMapCaption;
206 private String _colorMapValues;
207 private double _colorMapMin = Double.MIN_VALUE;
208 private double _colorMapMax = Double.MAX_VALUE;
210 private double _spaceBetweenBases = Double.MIN_VALUE;
212 private boolean _drawNC;
213 private boolean _drawBases;
214 private boolean _drawTertiary;
215 private boolean _drawColorMap;
217 private boolean _fillBases;
219 private int _periodResNum;
220 private Dimension _border;
222 private Color _backgroundColor;
224 private String _orientation;
226 private boolean _warning, _error;
228 private boolean _modifiable;
230 private double _zoom, _zoomAmount;
232 private ArrayList<ModelBaseStyle> _basesStyleList;
234 private boolean _comparisonMode;
236 private String _firstSequence;
237 private String _secondSequence;
238 private String _firstStructure;
239 private String _secondStructure;
241 private VARNAPanel _mainSurface;
243 private boolean _useNonStandardColor;
244 private boolean _useGapsColor;
245 private double _bpIncrement;
247 private boolean _useInnerBaseColor;
248 private boolean _useBaseNameColor;
249 private boolean _useBaseNumbersColor;
250 private boolean _useBaseOutlineColor;
254 protected ArrayList<VARNAPanel> _VARNAPanelList = new ArrayList<VARNAPanel>();
256 InterfaceParameterLoader _optionProducer;
258 public VARNAConfigLoader(InterfaceParameterLoader il) {
259 _optionProducer = il;
262 public ArrayList<VARNAPanel> createVARNAPanels()
263 throws ExceptionParameterError,
264 ExceptionModeleStyleBaseSyntaxError, ExceptionNonEqualLength,
265 IOException, ExceptionFileFormatOrSyntax, ExceptionLoadingFailed {
266 _VARNAPanelList.clear();
267 retrieveParametersValues();
268 return _VARNAPanelList;
271 public int getNbRows() {
272 return this._numRows;
275 public int getNbColumns() {
276 return this._numColumns;
279 private void initValues() {
281 // Applet assignable parameters
284 _autoHelices = false;
285 _autoInteriorLoops = false;
286 _autoTerminalLoops = false;
288 _backgroundColor = VARNAConfig.DEFAULT_BACKGROUND_COLOR;
294 _colorMapValues = "";
295 _colorMapCaption = "";
296 _drawColorMap = false;
301 _drawTertiary = true;
302 _border = new Dimension(0, 0);
304 // "CAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIA";
306 // "..(((((...(((((...(((((...(((((.....)))))...))))).....(((((...(((((.....)))))...))))).....)))))...)))))..";
307 _periodResNum = VARNAConfig.DEFAULT_PERIOD;
310 _titleSize = VARNAConfig.DEFAULT_TITLE_FONT.getSize();
312 _backboneColor = VARNAConfig.DEFAULT_BACKBONE_COLOR;
313 _drawBackbone = true;
315 _bondColor = VARNAConfig.DEFAULT_BOND_COLOR;
316 _bpStyle = VARNAConfig.DEFAULT_BP_STYLE;
318 _highlightRegion = "";
320 _baseOutlineColor = VARNAConfig.BASE_OUTLINE_COLOR_DEFAULT;
321 _baseInnerColor = VARNAConfig.BASE_INNER_COLOR_DEFAULT;
322 _baseNumColor = VARNAConfig.BASE_NUMBER_COLOR_DEFAULT;
323 _baseNameColor = VARNAConfig.BASE_NAME_COLOR_DEFAULT;
325 _titleColor = VARNAConfig.DEFAULT_TITLE_COLOR;
329 _zoom = VARNAConfig.DEFAULT_ZOOM;
330 _zoomAmount = VARNAConfig.DEFAULT_AMOUNT;
332 _comparisonMode = false;
334 _firstStructure = "";
335 _secondSequence = "";
336 _secondStructure = "";
338 _gapsColor = VARNAConfig.DEFAULT_DASH_BASE_COLOR;
339 _useGapsColor = false;
340 _nonStandardColor = VARNAConfig.DEFAULT_SPECIAL_BASE_COLOR;
341 _useNonStandardColor = false;
343 _useInnerBaseColor = false;
344 _useBaseNameColor = false;
345 _useBaseNumbersColor = false;
346 _useBaseOutlineColor = false;
348 _bpIncrement = VARNAConfig.DEFAULT_BP_INCREMENT;
351 _flatExteriorLoop = true;
354 _spaceBetweenBases = VARNAConfig.DEFAULT_SPACE_BETWEEN_BASES;
357 public static Color getSafeColor(String col, Color def) {
360 result = Color.decode(col);
362 } catch (NumberFormatException e) {
364 result = Color.getColor(col, def);
365 } catch (Exception e2) {
373 public static final String LEONTIS_WESTHOF_BP_STYLE = "lw";
374 public static final String LEONTIS_WESTHOF_BP_STYLE_ALT = "lwalt";
375 public static final String SIMPLE_BP_STYLE = "simple";
376 public static final String RNAVIZ_BP_STYLE = "rnaviz";
377 public static final String NONE_BP_STYLE = "none";
379 private VARNAConfig.BP_STYLE getSafeBPStyle(String opt,
380 VARNAConfig.BP_STYLE def) {
381 VARNAConfig.BP_STYLE b = VARNAConfig.BP_STYLE.getStyle(opt);
390 public static String[][] getParameterInfo() {
392 // Parameter Name Kind of Value Description
396 "Drawing algorithm, choosen from ["
397 + VARNAConfigLoader.ALGORITHM_NAVIEW + ","
398 + VARNAConfigLoader.ALGORITHM_LINE + ","
399 + VARNAConfigLoader.ALGORITHM_RADIATE + ","
400 + VARNAConfigLoader.ALGORITHM_CIRCULAR + "]" },
401 { annotationsOpt, "string", "A set of textual annotations" },
402 { applyBasesStyleOpt, "String", "Base style application" },
406 "Adds a list of (possibly non-canonical) base-pairs to those already defined by the main secondary structure (Ex: \"(1,10);(2,11);(3,12)\"). Custom BP styles can be specified (Ex: \"(2,11):thickness=4;(3,12):color=#FF0000\")." },
407 { autoHelicesOpt, "", "" },
408 { autoInteriorLoopsOpt, "", "" },
409 { autoTerminalLoopsOpt, "", "" },
410 { backboneColorOpt, "Color", "Backbone color (Ex: #334455)" },
411 { backgroundColorOpt, "Color", "Background color (Ex: #334455)" },
412 { baseInnerColorOpt, "Color",
413 "Default value for inner base color (Ex: #334455)" },
414 { baseNameColorOpt, "Color",
415 "Residues font color (Ex: #334455)" },
416 { baseNumbersColorOpt, "Color",
417 "Base numbers font color (Ex: #334455)" },
418 { baseOutlineColorOpt, "Color",
419 "Base outline color (Ex: #334455)" },
420 { basesStyleOpt, "String", "Base style declaration" },
421 { borderOpt, "String",
422 "Border width and height in pixels (Ex: \"20x40\")" },
423 { bondColorOpt, "Color", "Base pair color (Ex: #334455)" },
424 { bpIncrementOpt, "float",
425 "Distance between nested base-pairs (i.e. arcs) in linear representation" },
429 "Look and feel for base pairs drawings, choosen from ["
430 + VARNAConfigLoader.LEONTIS_WESTHOF_BP_STYLE+ ","
431 + VARNAConfigLoader.LEONTIS_WESTHOF_BP_STYLE_ALT+ ","
432 + VARNAConfigLoader.NONE_BP_STYLE + ","
433 + VARNAConfigLoader.SIMPLE_BP_STYLE + ","
434 + VARNAConfigLoader.RNAVIZ_BP_STYLE + "]" },
435 { chemProbOpt, "", "" },
439 "Associates a list of numerical values (eg '0.2,0.4,0.6,0.8') with the RNA bases with respect to their natural order, and modifies the color used to fill these bases according to current color map style." },
440 { colorMapCaptionOpt, "String",
441 "Sets current color map caption." },
445 "Selects a specific color map style. It can be either one of the predefined styles (eg 'red', 'green', 'blue', 'bw', 'heat', 'energy') or a new one (eg '0:#FFFF00;1:#ffFFFF;6:#FF0000')." },
446 { colorMapMinOpt, "", "" },
447 { colorMapMaxOpt, "", "" },
448 { comparisonModeOpt, "boolean", "Activates comparison mode" },
449 { customBasesOpt, "", "" },
450 { customBPsOpt, "", "" },
451 { drawBackboneOpt, "boolean",
452 "True if the backbone must be drawn, false otherwise" },
453 { drawColorMapOpt, "", "" },
454 { drawNCOpt, "boolean",
455 "Toggles on/off display of non-canonical base-pairs" },
456 { drawBasesOpt, "boolean", "Shows/hide the outline of bases" },
457 { drawTertiaryOpt, "boolean",
458 "Toggles on/off display of tertiary interaction, ie pseudoknots" },
459 { errorOpt, "boolean", "Show errors" },
460 { fillBasesOpt, "boolean",
461 "Fills or leaves empty the inner portions of bases" },
462 { firstSequenceForComparisonOpt, "String",
463 "In comparison mode, sequence of first RNA" },
464 { firstStructureForComparisonOpt, "String",
465 "In comparison mode, structure of first RNA" },
466 { flatExteriorLoopOpt, "boolean",
467 "Toggles on/off (true/false) drawing exterior bases on a straight line" },
469 "Draws a set of exterior helices, identified by the argument string, in clockwise order (default drawing is counter-clockwise). The argument is a semicolon-separated list of helices, each identified by a base or a base-pair (eg. \"2;20-34\")." },
470 { gapsBaseColorOpt, "Color",
471 "Define and use custom color for gaps bases in comparison mode" },
472 { highlightRegionOpt, "string", "Highlight a set of contiguous regions" },
473 { modifiableOpt, "boolean", "Allows/prohibits modifications" },
474 { nonStandardColorOpt, "Color",
475 "Define and use custom color for non-standard bases in comparison mode" },
476 { numColumnsOpt, "int", "Sets number of columns" },
477 { numRowsOpt, "int", "Sets number of rows" },
481 "Sets the general orientation of an RNA, i.e. the deviation of the longest axis (defined by the most distant couple of bases) from the horizontal axis." },
482 { periodNumOpt, "int", "Periodicity of base-numbering" },
483 { secondSequenceForComparisonOpt, "String",
484 "In comparison mode, sequence of second RNA" },
485 { secondStructureForComparisonOpt, "String",
486 "In comparison mode, structure of second RNA" },
487 { sequenceOpt, "String", "Raw RNA sequence" },
488 { structureOpt, "String",
489 "RNA structure given in dot bracket notation (DBN)" },
493 "Rotates RNA after initial drawing (Ex: '20' for a 20 degree counter-clockwise rotation)" },
494 { titleOpt, "String", "RNA drawing title" },
495 { titleColorOpt, "Color", "Title color (Ex: #334455)" },
496 { titleSizeOpt, "int", "Title font size" },
497 { spaceBetweenBasesOpt, "float",
498 "Sets the space between consecutive bases" },
499 { warningOpt, "boolean", "Show warnings" },
500 { zoomOpt, "int", "Zoom coefficient" },
501 { zoomAmountOpt, "int", "Zoom increment on user interaction" } };
505 private void retrieveParametersValues() throws ExceptionParameterError {
509 _basesStyleList = new ArrayList<ModelBaseStyle>();
512 _numRows = Integer.parseInt(_optionProducer.getParameterValue(
513 numRowsOpt, "" + _numRows));
514 } catch (NumberFormatException e) {
515 throw new ExceptionParameterError(e.getMessage(), "'"
516 + _optionProducer.getParameterValue(numRowsOpt, ""
518 + "' is not a integer value for the number of rows !");
521 _numColumns = Integer.parseInt(_optionProducer.getParameterValue(
522 numColumnsOpt, "" + _numColumns));
523 } catch (NumberFormatException e) {
524 throw new ExceptionParameterError(e.getMessage(), "'"
525 + _optionProducer.getParameterValue(numColumnsOpt, ""
527 + "' is not a integer value for the number of columns !");
531 for (int i = 0; i < MAXSTYLE; i++) {
532 String opt = basesStyleOpt + i;
533 tmp = _optionProducer.getParameterValue(opt, null);
534 // System.out.println(opt+"->"+tmp);
536 ModelBaseStyle msb = new ModelBaseStyle();
538 msb.assignParameters(tmp);
539 } catch (ExceptionModeleStyleBaseSyntaxError e) {
540 VARNAPanel.emitWarningStatic(e, null);
542 _basesStyleList.add(msb);
544 _basesStyleList.add(null);
548 // _containerApplet.getLayout().
552 for (int i = 0; i < _numColumns; i++) {
553 for (int j = 0; j < _numRows; j++) {
556 x = 1 + j + i * _numRows;
558 if ((_numColumns == 1) && (_numRows == 1)) {
561 _useGapsColor = false;
562 _useNonStandardColor = false;
564 tmp = _optionProducer.getParameterValue(baseNameColorOpt
566 if (!tmp.equals("")) {
567 _useBaseNameColor = true;
568 _baseNameColor = getSafeColor(tmp, _baseNameColor);
570 tmp = _optionProducer.getParameterValue(baseNumbersColorOpt
572 if (!tmp.equals("")) {
573 _useBaseNumbersColor = true;
574 _baseNumColor = getSafeColor(tmp, _baseNumColor);
576 tmp = _optionProducer.getParameterValue(baseOutlineColorOpt
578 if (!tmp.equals("")) {
579 _useBaseOutlineColor = true;
580 _baseOutlineColor = getSafeColor(tmp, _baseOutlineColor);
582 tmp = _optionProducer.getParameterValue(baseInnerColorOpt
584 if (!tmp.equals("")) {
585 _useInnerBaseColor = true;
586 _baseInnerColor = getSafeColor(tmp, _baseInnerColor);
589 tmp = _optionProducer.getParameterValue(nonStandardColorOpt
591 if (!tmp.equals("")) {
592 _nonStandardColor = getSafeColor(tmp, _nonStandardColor);
593 _useNonStandardColor = true;
595 tmp = _optionProducer.getParameterValue(gapsBaseColorOpt
596 + n, _gapsColor.toString());
597 if (!tmp.equals("")) {
598 _gapsColor = getSafeColor(tmp, _gapsColor);
599 _useGapsColor = true;
602 _rotation = Double.parseDouble(_optionProducer
603 .getParameterValue(rotationOpt + n,
604 Double.toString(_rotation)));
605 } catch (NumberFormatException e) {
606 throw new ExceptionParameterError(e.getMessage(), "'"
607 + _optionProducer.getParameterValue(rotationOpt
609 + "' is not a valid float value for rotation!");
613 _colorMapMin = Double.parseDouble(_optionProducer
614 .getParameterValue(colorMapMinOpt + n,
615 Double.toString(this._colorMapMin)));
616 } catch (NumberFormatException e) {
617 throw new ExceptionParameterError(
620 + _optionProducer.getParameterValue(
621 colorMapMinOpt + n, ""
623 + "' is not a valid double value for min color map values range!");
627 _colorMapMax = Double.parseDouble(_optionProducer
628 .getParameterValue(colorMapMaxOpt + n,
629 Double.toString(this._colorMapMax)));
630 } catch (NumberFormatException e) {
631 throw new ExceptionParameterError(
634 + _optionProducer.getParameterValue(
635 colorMapMaxOpt + n, ""
637 + "' is not a valid double value for max color map values range!");
641 _bpIncrement = Double.parseDouble(_optionProducer
642 .getParameterValue(bpIncrementOpt + n,
643 Double.toString(_bpIncrement)));
644 } catch (NumberFormatException e) {
648 _periodResNum = Integer.parseInt(_optionProducer
649 .getParameterValue(periodNumOpt + n, ""
651 } catch (NumberFormatException e) {
652 throw new ExceptionParameterError(
655 + _optionProducer.getParameterValue(
658 + "' is not a valid integer value for the period of residue numbers!");
661 _titleSize = Integer.parseInt(_optionProducer
662 .getParameterValue(titleSizeOpt + n, ""
664 } catch (NumberFormatException e) {
665 throw new ExceptionParameterError(
668 + _optionProducer.getParameterValue(
671 + "' is not a valid integer value for the number of rows !");
675 _zoom = Double.parseDouble(_optionProducer
676 .getParameterValue(zoomOpt + n, "" + _zoom));
677 } catch (NumberFormatException e) {
678 throw new ExceptionParameterError(
681 + _optionProducer.getParameterValue(
682 zoomOpt + n, "" + _zoom)
683 + "' is not a valid integer value for the zoom !");
687 _zoomAmount = Double.parseDouble(_optionProducer
688 .getParameterValue(zoomAmountOpt + n, ""
690 } catch (NumberFormatException e) {
691 throw new ExceptionParameterError(
694 + _optionProducer.getParameterValue(
695 zoomAmountOpt + n, ""
697 + "' is not a valid integer value for the zoom amount!");
701 _spaceBetweenBases = Double.parseDouble(_optionProducer
702 .getParameterValue(spaceBetweenBasesOpt + n, ""
703 + _spaceBetweenBases));
704 } catch (NumberFormatException e) {
705 throw new ExceptionParameterError(
708 + _optionProducer.getParameterValue(
709 spaceBetweenBasesOpt + n, ""
710 + _spaceBetweenBases)
711 + "' is not a valid integer value for the base spacing!");
714 _drawBases = Boolean.parseBoolean(_optionProducer
715 .getParameterValue(drawBasesOpt + n, ""
717 _fillBases = Boolean.parseBoolean(_optionProducer
718 .getParameterValue(fillBasesOpt + n, ""
720 _autoHelices = Boolean.parseBoolean(_optionProducer
721 .getParameterValue(autoHelicesOpt + n, ""
723 _drawColorMap = Boolean.parseBoolean(_optionProducer
724 .getParameterValue(drawColorMapOpt + n, ""
726 _drawBackbone = Boolean.parseBoolean(_optionProducer
727 .getParameterValue(drawBackboneOpt + n, ""
729 _colorMapValues = _optionProducer.getParameterValue(
730 colorMapOpt + n, _colorMapValues);
731 _autoTerminalLoops = Boolean.parseBoolean(_optionProducer
732 .getParameterValue(autoTerminalLoopsOpt + n, ""
733 + _autoTerminalLoops));
734 _autoInteriorLoops = Boolean.parseBoolean(_optionProducer
735 .getParameterValue(autoInteriorLoopsOpt + n, ""
736 + _autoInteriorLoops));
737 _drawNC = Boolean.parseBoolean(_optionProducer
738 .getParameterValue(drawNCOpt + n, "" + _drawNC));
739 _flatExteriorLoop = Boolean.parseBoolean(_optionProducer
740 .getParameterValue(flatExteriorLoopOpt + n, ""
741 + _flatExteriorLoop));
742 _drawTertiary = Boolean.parseBoolean(_optionProducer
743 .getParameterValue(drawTertiaryOpt + n, ""
745 _warning = Boolean.parseBoolean(_optionProducer
746 .getParameterValue(warningOpt + n, "false"));
747 _error = Boolean.parseBoolean(_optionProducer
748 .getParameterValue(errorOpt + n, "true"));
749 _border = parseDimension(_optionProducer.getParameterValue(
750 borderOpt + n, "0X0"));
751 _comparisonMode = Boolean.parseBoolean(_optionProducer
752 .getParameterValue(comparisonModeOpt + n, "false"));
753 _firstSequence = _optionProducer.getParameterValue(
754 firstSequenceForComparisonOpt + n, _firstSequence);
755 _firstStructure = _optionProducer
756 .getParameterValue(firstStructureForComparisonOpt
757 + n, _firstStructure);
758 _secondSequence = _optionProducer
759 .getParameterValue(secondSequenceForComparisonOpt
760 + n, _secondSequence);
761 _secondStructure = _optionProducer.getParameterValue(
762 secondStructureForComparisonOpt + n,
764 _annotations = _optionProducer.getParameterValue(
765 annotationsOpt + n, _annotations);
766 _URL = _optionProducer.getParameterValue(URLOpt + n, _URL);
767 _algo = _optionProducer.getParameterValue(algoOpt + n,
769 _customBases = _optionProducer.getParameterValue(
770 customBasesOpt + n, _customBases);
771 _auxBPs = _optionProducer.getParameterValue(auxBPsOpt + n,
773 _highlightRegion = _optionProducer.getParameterValue(
774 highlightRegionOpt + n, _highlightRegion);
775 _chemProbs = _optionProducer.getParameterValue(chemProbOpt
777 _customBPs = _optionProducer.getParameterValue(customBPsOpt
779 _colorMapStyle = _optionProducer.getParameterValue(
780 colorMapDefOpt + n, _colorMapStyle);
781 _colorMapCaption = _optionProducer.getParameterValue(
782 colorMapCaptionOpt + n, _colorMapCaption);
783 _backboneColor = getSafeColor(
784 _optionProducer.getParameterValue(backboneColorOpt
785 + n, _backboneColor.toString()),
787 _backgroundColor = getSafeColor(
788 _optionProducer.getParameterValue(
789 backgroundColorOpt + n,
790 _backgroundColor.toString()),
792 _bondColor = getSafeColor(
793 _optionProducer.getParameterValue(bondColorOpt + n,
794 _bondColor.toString()), _bondColor);
795 _bpStyle = getSafeBPStyle(
796 _optionProducer.getParameterValue(bpStyleOpt + n,
798 _flip = _optionProducer.getParameterValue(
800 _orientation = _optionProducer.getParameterValue(
801 orientationOpt + n, _orientation);
802 _titleColor = getSafeColor(
803 _optionProducer.getParameterValue(
804 titleColorOpt + n, _titleColor.toString()),
809 if (!_URL.equals("")) {
814 _title = _optionProducer.getParameterValue(titleOpt + n, _title);
816 if (_comparisonMode && _firstSequence != null
817 && _firstStructure != null
818 && _secondSequence != null
819 && _secondStructure != null) {
821 _sseq = _optionProducer.getParameterValue(sequenceOpt
823 _sstruct = _optionProducer.getParameterValue(
824 structureOpt + n, _sstruct);
825 if (!_sseq.equals("") && !_sstruct.equals("")) {
828 _comparisonMode = false;
831 // applique les valeurs des parametres recuperees
833 } catch (ExceptionParameterError e) {
834 VARNAPanel.errorDialogStatic(e, _mainSurface);
835 } catch (ExceptionNonEqualLength e) {
836 VARNAPanel.errorDialogStatic(e, _mainSurface);
837 } catch (IOException e) {
838 VARNAPanel.errorDialogStatic(e, _mainSurface);
839 } catch (ExceptionFileFormatOrSyntax e) {
840 VARNAPanel.errorDialogStatic(e, _mainSurface);
841 } catch (ExceptionLoadingFailed e) {
842 VARNAPanel.errorDialogStatic(e, _mainSurface);
844 }// fin de boucle sur les lignes
845 }// fin de boucle sur les colonnes
848 private RNA _defaultRNA = new RNA();
850 public void setRNA(RNA r) {
854 public static final String ALGORITHM_CIRCULAR = "circular";
855 public static final String ALGORITHM_NAVIEW = "naview";
856 public static final String ALGORITHM_LINE = "line";
857 public static final String ALGORITHM_RADIATE = "radiate";
858 public static final String ALGORITHM_VARNA_VIEW = "varnaview";
859 public static final String ALGORITHM_MOTIF_VIEW = "motifview";
861 private void applyValues(String n) throws ExceptionParameterError,
862 ExceptionNonEqualLength, IOException, ExceptionFileFormatOrSyntax,
863 ExceptionLoadingFailed {
864 boolean applyOptions = true;
866 if (_algo.equals(ALGORITHM_CIRCULAR))
867 algoCode = RNA.DRAW_MODE_CIRCULAR;
868 else if (_algo.equals(ALGORITHM_NAVIEW))
869 algoCode = RNA.DRAW_MODE_NAVIEW;
870 else if (_algo.equals(ALGORITHM_LINE))
871 algoCode = RNA.DRAW_MODE_LINEAR;
872 else if (_algo.equals(ALGORITHM_RADIATE))
873 algoCode = RNA.DRAW_MODE_RADIATE;
874 else if (_algo.equals(ALGORITHM_VARNA_VIEW))
875 algoCode = RNA.DRAW_MODE_VARNA_VIEW;
876 else if (_algo.equals(ALGORITHM_MOTIF_VIEW))
877 algoCode = RNA.DRAW_MODE_MOTIFVIEW;
879 algoCode = RNA.DRAW_MODE_RADIATE;
881 if (_comparisonMode) {
882 _mainSurface = new VARNAPanel(_firstSequence, _firstStructure,
883 _secondSequence, _secondStructure, algoCode, "");
885 _mainSurface = new VARNAPanel();
888 _VARNAPanelList.add(_mainSurface);
889 _mainSurface.setSpaceBetweenBases(_spaceBetweenBases);
890 _mainSurface.setTitle(_title);
892 if (!_URL.equals("")) {
896 _mainSurface.setSpaceBetweenBases(_spaceBetweenBases);
899 URLConnection connexion = url.openConnection();
900 connexion.setUseCaches(false);
901 InputStream r = connexion.getInputStream();
902 InputStreamReader inr = new InputStreamReader(r);
904 if (_URL.toLowerCase().endsWith(
905 VARNAPanel.VARNA_SESSION_EXTENSION)) {
907 f = VARNAPanel.importSession(r, _URL);
908 _mainSurface.setConfig(f.config);
909 _mainSurface.showRNA(f.rna);
910 applyOptions = false;
912 Collection<RNA> rnas = RNAFactory.loadSecStr(
913 new BufferedReader(inr),
914 RNAFactory.guessFileTypeFromExtension(_URL));
915 if (rnas.isEmpty()) {
916 throw new ExceptionFileFormatOrSyntax(
917 "No RNA in file '" + _URL + "'.");
919 RNA rna = rnas.iterator().next();
920 rna.drawRNA(algoCode, _mainSurface.getConfig());
921 _mainSurface.drawRNA(rna, algoCode);
923 if (!_title.isEmpty())
925 _mainSurface.setTitle(_title);
927 } catch (ExceptionFileFormatOrSyntax e) {
929 e.setPath(url.getPath());
930 } catch (ExceptionDrawingAlgorithm e) {
931 _mainSurface.emitWarning(e.getMessage());
935 if (!_comparisonMode) {
936 if (!_sstruct.equals("")) {
937 _mainSurface.drawRNA(_sseq, _sstruct, algoCode);
940 System.err.println("Printing default RNA "+_defaultRNA);
941 _defaultRNA.drawRNA(algoCode, _mainSurface.getConfig());
942 } catch (ExceptionDrawingAlgorithm e) {
945 _mainSurface.drawRNA(_defaultRNA);
951 if (_useInnerBaseColor) {
952 _mainSurface.setBaseInnerColor(_baseInnerColor);
954 if (_useBaseOutlineColor) {
955 _mainSurface.setBaseOutlineColor(_baseOutlineColor);
957 if (_useBaseNameColor) {
958 _mainSurface.setBaseNameColor(_baseNameColor);
960 if (_useBaseNumbersColor) {
961 _mainSurface.setBaseNumbersColor(_baseNumColor);
964 _mainSurface.setBackground(_backgroundColor);
965 _mainSurface.setNumPeriod(_periodResNum);
966 _mainSurface.setBackboneColor(_backboneColor);
967 _mainSurface.setDefaultBPColor(_bondColor);
968 _mainSurface.setBPHeightIncrement(_bpIncrement);
969 _mainSurface.setBPStyle(_bpStyle);
970 _mainSurface.setDrawBackbone(_drawBackbone);
972 _mainSurface.setTitleFontColor(_titleColor);
973 _mainSurface.setTitleFontSize(_titleSize);
975 _mainSurface.getPopupMenu().get_itemShowWarnings()
977 _mainSurface.setErrorsOn(_error);
978 _mainSurface.setFlatExteriorLoop(_flatExteriorLoop);
979 _mainSurface.setZoom(_zoom);
980 _mainSurface.setZoomIncrement(_zoomAmount);
981 _mainSurface.setBorderSize(_border);
984 _mainSurface.setGapsBasesColor(this._gapsColor);
985 _mainSurface.setColorGapsBases(true);
988 if (_useNonStandardColor) {
989 _mainSurface.setNonStandardBasesColor(_nonStandardColor);
990 _mainSurface.setColorNonStandardBases(true);
993 _mainSurface.setShowNonPlanarBP(_drawTertiary);
994 _mainSurface.setShowNonCanonicalBP(_drawNC);
998 if (!_customBases.equals(""))
999 applyBasesCustomStyles(_mainSurface);
1001 if (!_highlightRegion.equals(""))
1002 applyHighlightRegion(_mainSurface);
1004 if (!_auxBPs.equals(""))
1005 applyAuxBPs(_mainSurface);
1007 if (!_chemProbs.equals(""))
1008 applyChemProbs(_mainSurface);
1010 if (!_customBPs.equals(""))
1011 applyBPsCustomStyles(_mainSurface);
1013 _mainSurface.setDrawOutlineBases(_drawBases);
1014 _mainSurface.setFillBases(_fillBases);
1015 _mainSurface.drawRNA();
1017 if (!_annotations.equals(""))
1018 applyAnnotations(_mainSurface);
1020 _mainSurface.getVARNAUI().UIAutoAnnotateHelices();
1021 if (_autoTerminalLoops)
1022 _mainSurface.getVARNAUI().UIAutoAnnotateTerminalLoops();
1023 if (_autoInteriorLoops)
1024 _mainSurface.getVARNAUI().UIAutoAnnotateInteriorLoops();
1026 if (!_orientation.equals("")) {
1028 double d = 360 * _mainSurface.getOrientation()
1030 _rotation = Double.parseDouble(_orientation) - d;
1031 } catch (NumberFormatException e) {
1032 // TODO : Add some code here...
1036 _mainSurface.globalRotation(_rotation);
1038 _mainSurface.setModifiable(_modifiable);
1040 _mainSurface.setColorMapCaption(_colorMapCaption);
1041 applyColorMapStyle(_mainSurface);
1042 applyFlips(_mainSurface);
1043 applyColorMapValues(_mainSurface);
1045 // if (!_drawColorMap)
1046 // _mainSurface.drawColorMap(_drawColorMap);
1048 // ajoute le VARNAPanel au conteneur
1051 private void applyBasesStyle(String n) throws ExceptionParameterError {
1053 for (int numStyle = 0; numStyle < _basesStyleList.size(); numStyle++) {
1054 if (_basesStyleList.get(numStyle) != null) {
1055 tmp = _optionProducer.getParameterValue(applyBasesStyleOpt
1056 + (numStyle) + "on" + n, null);
1058 ArrayList<Integer> indicesList = new ArrayList<Integer>();
1060 String[] basesList = tmp.split(",");
1061 for (int k = 0; k < basesList.length; k++) {
1062 String cand = basesList[k].trim();
1064 String[] args = cand.split("-");
1065 if (args.length == 1) {
1066 int baseNum = Integer.parseInt(cand);
1067 int index = _mainSurface.getRNA()
1068 .getIndexFromBaseNumber(baseNum);
1070 indicesList.add(index);
1072 } else if (args.length == 2) {
1073 int baseNumFrom = Integer.parseInt(args[0]
1075 int indexFrom = _mainSurface.getRNA()
1076 .getIndexFromBaseNumber(baseNumFrom);
1077 int baseNumTo = Integer
1078 .parseInt(args[1].trim());
1079 int indexTo = _mainSurface.getRNA()
1080 .getIndexFromBaseNumber(baseNumTo);
1081 if ((indexFrom != -1) && (indexTo != -1)) {
1082 for (int l = indexFrom; l <= indexTo; l++)
1086 } catch (NumberFormatException e) {
1087 throw new ExceptionParameterError(e.getMessage(),
1088 "Bad Base Index: " + basesList[k]);
1091 for (int k = 0; k < indicesList.size(); k++) {
1092 int index = indicesList.get(k);
1094 && (index < _mainSurface.getRNA()
1095 .get_listeBases().size())) {
1100 .setStyleBase(_basesStyleList.get(numStyle));
1105 }// fin de boucle sur les styles
1109 private void applyColorMapStyle(VARNAPanel vp) {
1110 if (_colorMapStyle.length() != 0) {
1111 vp.setColorMap(ModeleColorMap.parseColorMap(_colorMapStyle));
1115 private void applyColorMapValues(VARNAPanel vp) {
1116 if (!_colorMapValues.equals("")) {
1117 File f = new File(_colorMapValues);
1118 if(f.exists() && !f.isDirectory()) {
1120 vp.readValues(new FileReader(f));
1121 vp.drawColorMap(true);
1122 System.err.println("Loaded "+_colorMapValues);
1123 } catch (FileNotFoundException e) {
1124 e.printStackTrace();
1129 String[] values = _colorMapValues.split("[;,]");
1130 ArrayList<Double> vals = new ArrayList<Double>();
1131 for (int i = 0; i < values.length; i++) {
1133 vals.add(Double.parseDouble(values[i]));
1134 } catch (Exception e) {
1138 Double[] result = new Double[vals.size()];
1139 vals.toArray(result);
1140 vp.setColorMapValues(result);
1142 ModeleColorMap cm = vp.getColorMap();
1143 if (_colorMapMin != Double.MIN_VALUE) {
1144 // System.out.println("[A]"+_colorMapMin);
1145 cm.setMinValue(_colorMapMin);
1147 if (_colorMapMax != Double.MAX_VALUE) {
1148 cm.setMaxValue(_colorMapMax);
1150 _drawColorMap = true;
1154 private void applyBasesCustomStyles(VARNAPanel vp) {
1155 String[] baseStyles = _customBases.split(";");
1156 for (int i = 0; i < baseStyles.length; i++) {
1157 String thisStyle = baseStyles[i];
1158 String[] data = thisStyle.split(":");
1160 if (data.length == 2) {
1161 int baseNum = Integer.parseInt(data[0]);
1162 int index = _mainSurface.getRNA().getIndexFromBaseNumber(
1165 String style = data[1];
1166 ModelBaseStyle msb = vp.getRNA().get_listeBases()
1167 .get(index).getStyleBase().clone();
1168 msb.assignParameters(style);
1169 vp.getRNA().get_listeBases().get(index)
1173 } catch (Exception e) {
1174 System.err.println("ApplyBasesCustomStyle: " + e.toString());
1179 private void applyHighlightRegion(VARNAPanel vp) {
1180 String[] regions = _highlightRegion.split(";");
1181 for (int i = 0; i < regions.length; i++) {
1182 String region = regions[i];
1184 HighlightRegionAnnotation nt = HighlightRegionAnnotation
1185 .parseHighlightRegionAnnotation(region, vp);
1187 vp.addHighlightRegion(nt);
1189 } catch (Exception e) {
1190 System.err.println("Error in applyHighlightRegion: " + e.toString());
1195 private Dimension parseDimension(String s) {
1196 Dimension d = new Dimension(0, 0);
1198 s = s.toLowerCase();
1199 int i = s.indexOf('x');
1200 String w = s.substring(0, i);
1201 String h = s.substring(i + 1);
1202 d.width = Integer.parseInt(w);
1203 d.height = Integer.parseInt(h);
1204 } catch (NumberFormatException e) {
1209 private void applyBPsCustomStyles(VARNAPanel vp) {
1210 String[] baseStyles = _customBPs.split(";");
1211 for (int i = 0; i < baseStyles.length; i++) {
1212 String thisStyle = baseStyles[i];
1213 String[] data = thisStyle.split(":");
1215 if (data.length == 2) {
1216 String indices = data[0];
1217 String style = data[1];
1218 String[] data2 = indices.split(",");
1219 if (data2.length == 2) {
1220 String s1 = data2[0];
1221 String s2 = data2[1];
1222 if (s1.startsWith("(") && s2.endsWith(")")) {
1223 int a = Integer.parseInt(s1.substring(1));
1224 int b = Integer.parseInt(s2.substring(0,
1226 ModeleBP msbp = vp.getRNA().getBPStyle(a, b);
1228 msbp.assignParameters(style);
1233 } catch (Exception e) {
1234 System.err.println("ApplyBPsCustomStyle: " + e.toString());
1239 private void applyChemProbs(VARNAPanel vp) {
1240 String[] chemProbs = _chemProbs.split(";");
1241 for (int i = 0; i < chemProbs.length; i++) {
1242 String thisAnn = chemProbs[i];
1243 String[] data = thisAnn.split(":");
1245 if (data.length == 2) {
1246 String indices = data[0];
1247 String style = data[1];
1248 String[] data2 = indices.split("-");
1249 if (data2.length == 2) {
1250 int a = Integer.parseInt(data2[0]);
1251 int b = Integer.parseInt(data2[1]);
1252 int c = vp.getRNA().getIndexFromBaseNumber(a);
1253 int d = vp.getRNA().getIndexFromBaseNumber(b);
1254 ArrayList<ModeleBase> mbl = vp.getRNA()
1256 ChemProbAnnotation cpa = new ChemProbAnnotation(
1257 mbl.get(c), mbl.get(d), style);
1258 vp.getRNA().addChemProbAnnotation(cpa);
1261 } catch (Exception e) {
1262 System.err.println("ChempProbs: " + e.toString());
1267 private void applyAuxBPs(VARNAPanel vp) {
1268 String[] baseStyles = _auxBPs.split(";");
1270 for (int i = 0; i < baseStyles.length; i++) {
1271 String thisStyle = baseStyles[i];
1272 String[] data = thisStyle.split(":");
1274 if (data.length >= 1) {
1275 String indices = data[0];
1276 String[] data2 = indices.split(",");
1277 if (data2.length == 2) {
1278 String s1 = data2[0];
1279 String s2 = data2[1];
1280 if (s1.startsWith("(") && s2.endsWith(")")) {
1281 int a = Integer.parseInt(s1.substring(1));
1282 int b = Integer.parseInt(s2.substring(0,
1284 int c = vp.getRNA().getIndexFromBaseNumber(a);
1285 int d = vp.getRNA().getIndexFromBaseNumber(b);
1287 ModeleBP msbp = new ModeleBP(vp.getRNA()
1288 .get_listeBases().get(c), vp.getRNA()
1289 .get_listeBases().get(d));
1290 if (data.length >= 2) {
1291 String style = data[1];
1292 msbp.assignParameters(style);
1295 .addBPToStructureUsingNumbers(a, b, msbp);
1299 } catch (ExceptionModeleStyleBaseSyntaxError e1) {
1300 System.err.println("AuxApplyBPs: " + e1.toString());
1301 } catch (ExceptionParameterError e) {
1302 // TODO Auto-generated catch block
1303 e.printStackTrace();
1308 private void applyFlips(VARNAPanel vp) {
1309 String[] flips = _flip.split(";");
1310 for (String s: flips)
1315 String[] data = s.split("-");
1319 number = Integer.parseInt(data[0]);
1321 else if (data.length==2)
1323 number = Integer.parseInt(data[1]);
1327 int i = vp.getRNA().getIndexFromBaseNumber(number);
1328 Point h = vp.getRNA().getExteriorHelix(i);
1329 vp.getRNA().flipHelix(h);
1331 } catch (Exception e) {
1332 System.err.println("Flip Helices: " + e.toString());
1340 * string:[type=[H|B|L|P]|x=double|y=double|anchor=int|size=int|color
1345 private void applyAnnotations(VARNAPanel vp) {
1346 String[] annotations = _annotations.split(";");
1347 for (int i = 0; i < annotations.length; i++) {
1348 String thisAnn = annotations[i];
1349 TextAnnotation ann = TextAnnotation.parse(thisAnn, vp);
1350 vp.addAnnotation(ann);