f62b187c2377d1bbbf0a1c92c4ae12af99524447
[jalview.git] / srcjar / fr / orsay / lri / varna / models / VARNAConfigLoader.java
1 /*
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
6
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.
10
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.
14
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.
17  */
18 package fr.orsay.lri.varna.models;
19
20 /*
21  * VARNA is a Java library for quick automated drawings RNA secondary structure
22  * Copyright (C) 2007 Yann Ponty
23  * 
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
27  * version.
28  * 
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
32  * details.
33  * 
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/>.
36  */
37
38 import java.awt.Color;
39 import java.awt.Dimension;
40 import java.awt.Font;
41 import java.awt.Point;
42 import java.awt.geom.Point2D;
43 import java.io.BufferedReader;
44 import java.io.File;
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;
50 import java.net.URL;
51 import java.net.URLConnection;
52 import java.util.ArrayList;
53 import java.util.Collection;
54
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;
73
74 /**
75  * An RNA 2d Panel demo applet
76  * 
77  * @author Yann Ponty
78  * 
79  */
80
81 public class VARNAConfigLoader {
82
83         private static final int MAXSTYLE = 50;
84
85         // Applet Options
86
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";
94
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";
106
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";
116
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";
122
123         public static String errorOpt = "error";
124
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";
130
131         public static String gapsBaseColorOpt = "gapsColor";
132
133         public static String highlightRegionOpt = "highlightRegion";
134
135         public static String nonStandardColorOpt = "nsBasesColor";
136         public static String numColumnsOpt = "rows";
137         public static String numRowsOpt = "columns";
138
139         public static String orientationOpt = "orientation";
140
141         public static String modifiableOpt = "modifiable";
142
143         public static String periodNumOpt = "periodNum";
144
145         public static String rotationOpt = "rotation";
146
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";
152
153         public static String titleOpt = "title";
154         public static String titleColorOpt = "titleColor";
155         public static String titleSizeOpt = "titleSize";
156
157         public static String URLOpt = "url";
158
159         public static String warningOpt = "warning";
160
161         public static String zoomOpt = "zoom";
162         public static String zoomAmountOpt = "zoomAmount";
163
164         // Applet assignable parameters
165         private String _algo;
166         public String _annotations;
167         public String _chemProbs;
168         private double _rotation;
169
170         private String _sseq;
171         private String _sstruct;
172
173         private int _numRows;
174         private int _numColumns;
175
176         private String _title;
177         private int _titleSize;
178         private Color _titleColor;
179
180         private String _auxBPs;
181         private String _highlightRegion;
182
183         private boolean _autoHelices;
184         private boolean _autoInteriorLoops;
185         private boolean _autoTerminalLoops;
186
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;
197
198         private boolean _flatExteriorLoop;
199         private String _flip;
200
201         private String _customBases;
202         private String _customBPs;
203
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;
209
210         private double _spaceBetweenBases = Double.MIN_VALUE;
211
212         private boolean _drawNC;
213         private boolean _drawBases;
214         private boolean _drawTertiary;
215         private boolean _drawColorMap;
216
217         private boolean _fillBases;
218
219         private int _periodResNum;
220         private Dimension _border;
221
222         private Color _backgroundColor;
223
224         private String _orientation;
225
226         private boolean _warning, _error;
227
228         private boolean _modifiable;
229
230         private double _zoom, _zoomAmount;
231
232         private ArrayList<ModelBaseStyle> _basesStyleList;
233
234         private boolean _comparisonMode;
235
236         private String _firstSequence;
237         private String _secondSequence;
238         private String _firstStructure;
239         private String _secondStructure;
240
241         private VARNAPanel _mainSurface;
242
243         private boolean _useNonStandardColor;
244         private boolean _useGapsColor;
245         private double _bpIncrement;
246
247         private boolean _useInnerBaseColor;
248         private boolean _useBaseNameColor;
249         private boolean _useBaseNumbersColor;
250         private boolean _useBaseOutlineColor;
251
252         private String _URL;
253
254         protected ArrayList<VARNAPanel> _VARNAPanelList = new ArrayList<VARNAPanel>();
255
256         InterfaceParameterLoader _optionProducer;
257
258         public VARNAConfigLoader(InterfaceParameterLoader il) {
259                 _optionProducer = il;
260         }
261
262         public ArrayList<VARNAPanel> createVARNAPanels()
263                         throws ExceptionParameterError,
264                         ExceptionModeleStyleBaseSyntaxError, ExceptionNonEqualLength,
265                         IOException, ExceptionFileFormatOrSyntax, ExceptionLoadingFailed {
266                 _VARNAPanelList.clear();
267                 retrieveParametersValues();
268                 return _VARNAPanelList;
269         }
270
271         public int getNbRows() {
272                 return this._numRows;
273         }
274
275         public int getNbColumns() {
276                 return this._numColumns;
277         }
278
279         private void initValues() {
280
281                 // Applet assignable parameters
282                 _algo = "radiate";
283                 _auxBPs = "";
284                 _autoHelices = false;
285                 _autoInteriorLoops = false;
286                 _autoTerminalLoops = false;
287                 _annotations = "";
288                 _backgroundColor = VARNAConfig.DEFAULT_BACKGROUND_COLOR;
289                 _customBases = "";
290                 _customBPs = "";
291                 _chemProbs = "";
292
293                 _colorMapStyle = "";
294                 _colorMapValues = "";
295                 _colorMapCaption = "";
296                 _drawColorMap = false;
297
298                 _drawBases = true;
299                 _fillBases = true;
300                 _drawNC = true;
301                 _drawTertiary = true;
302                 _border = new Dimension(0, 0);
303                 _sseq = "";// =
304                 // "CAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIA";
305                 _sstruct = "";// =
306                 // "..(((((...(((((...(((((...(((((.....)))))...))))).....(((((...(((((.....)))))...))))).....)))))...)))))..";
307                 _periodResNum = VARNAConfig.DEFAULT_PERIOD;
308                 _rotation = 0.0;
309                 _title = "";
310                 _titleSize = VARNAConfig.DEFAULT_TITLE_FONT.getSize();
311
312                 _backboneColor = VARNAConfig.DEFAULT_BACKBONE_COLOR;
313                 _drawBackbone = true;
314
315                 _bondColor = VARNAConfig.DEFAULT_BOND_COLOR;
316                 _bpStyle = VARNAConfig.DEFAULT_BP_STYLE;
317
318                 _highlightRegion = "";
319
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;
324
325                 _titleColor = VARNAConfig.DEFAULT_TITLE_COLOR;
326                 _warning = false;
327                 _error = true;
328                 _modifiable = true;
329                 _zoom = VARNAConfig.DEFAULT_ZOOM;
330                 _zoomAmount = VARNAConfig.DEFAULT_AMOUNT;
331
332                 _comparisonMode = false;
333                 _firstSequence = "";
334                 _firstStructure = "";
335                 _secondSequence = "";
336                 _secondStructure = "";
337
338                 _gapsColor = VARNAConfig.DEFAULT_DASH_BASE_COLOR;
339                 _useGapsColor = false;
340                 _nonStandardColor = VARNAConfig.DEFAULT_SPECIAL_BASE_COLOR;
341                 _useNonStandardColor = false;
342
343                 _useInnerBaseColor = false;
344                 _useBaseNameColor = false;
345                 _useBaseNumbersColor = false;
346                 _useBaseOutlineColor = false;
347
348                 _bpIncrement = VARNAConfig.DEFAULT_BP_INCREMENT;
349
350                 _URL = "";
351                 _flatExteriorLoop = true;
352                 _flip = "";
353                 _orientation = "";
354                 _spaceBetweenBases = VARNAConfig.DEFAULT_SPACE_BETWEEN_BASES;
355         }
356
357         public static Color getSafeColor(String col, Color def) {
358                 Color result;
359                 try {
360                         result = Color.decode(col);
361
362                 } catch (NumberFormatException e) {
363                         try {
364                                 result = Color.getColor(col, def);
365                         } catch (Exception e2) {
366                                 // Not a valid color
367                                 return def;
368                         }
369                 }
370                 return result;
371         }
372
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";
378
379         private VARNAConfig.BP_STYLE getSafeBPStyle(String opt,
380                         VARNAConfig.BP_STYLE def) {
381                 VARNAConfig.BP_STYLE b = VARNAConfig.BP_STYLE.getStyle(opt);
382                 if (b!= null)
383                 {
384                         return b;
385                 } else {
386                         return def;
387                 }
388         }
389
390         public static String[][] getParameterInfo() {
391                 String[][] info = {
392                                 // Parameter Name Kind of Value Description
393                                 {
394                                                 algoOpt,
395                                                 "String",
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" },
403                                 {
404                                                 auxBPsOpt,
405                                                 "String",
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" },
426                                 {
427                                                 bpStyleOpt,
428                                                 "String",
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, "", "" },
436                                 {
437                                                 colorMapOpt,
438                                                 "String",
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." },
442                                 {
443                                                 colorMapDefOpt,
444                                                 "String",
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" },
468                                 { flipOpt, "String",
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" },
478                                 {
479                                                 orientationOpt,
480                                                 "float",
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)" },
490                                 {
491                                                 rotationOpt,
492                                                 "float",
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" } };
502                 return info;
503         }
504
505         private void retrieveParametersValues() throws ExceptionParameterError {
506
507                 _numRows = 1;
508                 _numColumns = 1;
509                 _basesStyleList = new ArrayList<ModelBaseStyle>();
510
511                 try {
512                         _numRows = Integer.parseInt(_optionProducer.getParameterValue(
513                                         numRowsOpt, "" + _numRows));
514                 } catch (NumberFormatException e) {
515                         throw new ExceptionParameterError(e.getMessage(), "'"
516                                         + _optionProducer.getParameterValue(numRowsOpt, ""
517                                                         + _numRows)
518                                         + "' is not a integer value for the number of rows !");
519                 }
520                 try {
521                         _numColumns = Integer.parseInt(_optionProducer.getParameterValue(
522                                         numColumnsOpt, "" + _numColumns));
523                 } catch (NumberFormatException e) {
524                         throw new ExceptionParameterError(e.getMessage(), "'"
525                                         + _optionProducer.getParameterValue(numColumnsOpt, ""
526                                                         + _numColumns)
527                                         + "' is not a integer value for the number of columns !");
528                 }
529
530                 String tmp = null;
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);
535                         if (tmp != null) {
536                                 ModelBaseStyle msb = new ModelBaseStyle();
537                                 try {
538                                         msb.assignParameters(tmp);
539                                 } catch (ExceptionModeleStyleBaseSyntaxError e) {
540                                         VARNAPanel.emitWarningStatic(e, null);
541                                 }
542                                 _basesStyleList.add(msb);
543                         } else {
544                                 _basesStyleList.add(null);
545                         }
546                 }
547
548                 // _containerApplet.getLayout().
549                 int x;
550                 String n;
551                 initValues();
552                 for (int i = 0; i < _numColumns; i++) {
553                         for (int j = 0; j < _numRows; j++) {
554                                 try {
555                                         // initValues();
556                                         x = 1 + j + i * _numRows;
557                                         n = "" + x;
558                                         if ((_numColumns == 1) && (_numRows == 1)) {
559                                                 n = "";
560                                         }
561                                         _useGapsColor = false;
562                                         _useNonStandardColor = false;
563
564                                         tmp = _optionProducer.getParameterValue(baseNameColorOpt
565                                                         + n, "");
566                                         if (!tmp.equals("")) {
567                                                 _useBaseNameColor = true;
568                                                 _baseNameColor = getSafeColor(tmp, _baseNameColor);
569                                         }
570                                         tmp = _optionProducer.getParameterValue(baseNumbersColorOpt
571                                                         + n, "");
572                                         if (!tmp.equals("")) {
573                                                 _useBaseNumbersColor = true;
574                                                 _baseNumColor = getSafeColor(tmp, _baseNumColor);
575                                         }
576                                         tmp = _optionProducer.getParameterValue(baseOutlineColorOpt
577                                                         + n, "");
578                                         if (!tmp.equals("")) {
579                                                 _useBaseOutlineColor = true;
580                                                 _baseOutlineColor = getSafeColor(tmp, _baseOutlineColor);
581                                         }
582                                         tmp = _optionProducer.getParameterValue(baseInnerColorOpt
583                                                         + n, "");
584                                         if (!tmp.equals("")) {
585                                                 _useInnerBaseColor = true;
586                                                 _baseInnerColor = getSafeColor(tmp, _baseInnerColor);
587                                         }
588
589                                         tmp = _optionProducer.getParameterValue(nonStandardColorOpt
590                                                         + n, "");
591                                         if (!tmp.equals("")) {
592                                                 _nonStandardColor = getSafeColor(tmp, _nonStandardColor);
593                                                 _useNonStandardColor = true;
594                                         }
595                                         tmp = _optionProducer.getParameterValue(gapsBaseColorOpt
596                                                         + n, _gapsColor.toString());
597                                         if (!tmp.equals("")) {
598                                                 _gapsColor = getSafeColor(tmp, _gapsColor);
599                                                 _useGapsColor = true;
600                                         }
601                                         try {
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
608                                                                                 + n, "" + _rotation)
609                                                                 + "' is not a valid float value for rotation!");
610                                         }
611
612                                         try {
613                                                 _colorMapMin = Double.parseDouble(_optionProducer
614                                                                 .getParameterValue(colorMapMinOpt + n,
615                                                                                 Double.toString(this._colorMapMin)));
616                                         } catch (NumberFormatException e) {
617                                                 throw new ExceptionParameterError(
618                                                                 e.getMessage(),
619                                                                 "'"
620                                                                                 + _optionProducer.getParameterValue(
621                                                                                                 colorMapMinOpt + n, ""
622                                                                                                                 + _colorMapMin)
623                                                                                 + "' is not a valid double value for min color map values range!");
624                                         }
625
626                                         try {
627                                                 _colorMapMax = Double.parseDouble(_optionProducer
628                                                                 .getParameterValue(colorMapMaxOpt + n,
629                                                                                 Double.toString(this._colorMapMax)));
630                                         } catch (NumberFormatException e) {
631                                                 throw new ExceptionParameterError(
632                                                                 e.getMessage(),
633                                                                 "'"
634                                                                                 + _optionProducer.getParameterValue(
635                                                                                                 colorMapMaxOpt + n, ""
636                                                                                                                 + _colorMapMax)
637                                                                                 + "' is not a valid double value for max color map values range!");
638                                         }
639
640                                         try {
641                                                 _bpIncrement = Double.parseDouble(_optionProducer
642                                                                 .getParameterValue(bpIncrementOpt + n,
643                                                                                 Double.toString(_bpIncrement)));
644                                         } catch (NumberFormatException e) {
645                                         }
646
647                                         try {
648                                                 _periodResNum = Integer.parseInt(_optionProducer
649                                                                 .getParameterValue(periodNumOpt + n, ""
650                                                                                 + _periodResNum));
651                                         } catch (NumberFormatException e) {
652                                                 throw new ExceptionParameterError(
653                                                                 e.getMessage(),
654                                                                 "'"
655                                                                                 + _optionProducer.getParameterValue(
656                                                                                                 periodNumOpt + n, ""
657                                                                                                                 + _periodResNum)
658                                                                                 + "' is not a valid integer value for the period of residue numbers!");
659                                         }
660                                         try {
661                                                 _titleSize = Integer.parseInt(_optionProducer
662                                                                 .getParameterValue(titleSizeOpt + n, ""
663                                                                                 + _titleSize));
664                                         } catch (NumberFormatException e) {
665                                                 throw new ExceptionParameterError(
666                                                                 e.getMessage(),
667                                                                 "'"
668                                                                                 + _optionProducer.getParameterValue(
669                                                                                                 titleSizeOpt + n, ""
670                                                                                                                 + _titleSize)
671                                                                                 + "' is not a valid integer value for the number of rows !");
672                                         }
673
674                                         try {
675                                                 _zoom = Double.parseDouble(_optionProducer
676                                                                 .getParameterValue(zoomOpt + n, "" + _zoom));
677                                         } catch (NumberFormatException e) {
678                                                 throw new ExceptionParameterError(
679                                                                 e.getMessage(),
680                                                                 "'"
681                                                                                 + _optionProducer.getParameterValue(
682                                                                                                 zoomOpt + n, "" + _zoom)
683                                                                                 + "' is not a valid integer value for the zoom !");
684                                         }
685
686                                         try {
687                                                 _zoomAmount = Double.parseDouble(_optionProducer
688                                                                 .getParameterValue(zoomAmountOpt + n, ""
689                                                                                 + _zoomAmount));
690                                         } catch (NumberFormatException e) {
691                                                 throw new ExceptionParameterError(
692                                                                 e.getMessage(),
693                                                                 "'"
694                                                                                 + _optionProducer.getParameterValue(
695                                                                                                 zoomAmountOpt + n, ""
696                                                                                                                 + _zoomAmount)
697                                                                                 + "' is not a valid integer value for the zoom amount!");
698                                         }
699
700                                         try {
701                                                 _spaceBetweenBases = Double.parseDouble(_optionProducer
702                                                                 .getParameterValue(spaceBetweenBasesOpt + n, ""
703                                                                                 + _spaceBetweenBases));
704                                         } catch (NumberFormatException e) {
705                                                 throw new ExceptionParameterError(
706                                                                 e.getMessage(),
707                                                                 "'"
708                                                                                 + _optionProducer.getParameterValue(
709                                                                                                 spaceBetweenBasesOpt + n, ""
710                                                                                                                 + _spaceBetweenBases)
711                                                                                 + "' is not a valid integer value for the base spacing!");
712                                         }
713
714                                         _drawBases = Boolean.parseBoolean(_optionProducer
715                                                         .getParameterValue(drawBasesOpt + n, ""
716                                                                         + _drawBases));
717                                         _fillBases = Boolean.parseBoolean(_optionProducer
718                                                         .getParameterValue(fillBasesOpt + n, ""
719                                                                         + _fillBases));
720                                         _autoHelices = Boolean.parseBoolean(_optionProducer
721                                                         .getParameterValue(autoHelicesOpt + n, ""
722                                                                         + _autoHelices));
723                                         _drawColorMap = Boolean.parseBoolean(_optionProducer
724                                                         .getParameterValue(drawColorMapOpt + n, ""
725                                                                         + _drawColorMap));
726                                         _drawBackbone = Boolean.parseBoolean(_optionProducer
727                                                         .getParameterValue(drawBackboneOpt + n, ""
728                                                                         + _drawBackbone));
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, ""
744                                                                         + _drawTertiary));
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,
763                                                         _secondStructure);
764                                         _annotations = _optionProducer.getParameterValue(
765                                                         annotationsOpt + n, _annotations);
766                                         _URL = _optionProducer.getParameterValue(URLOpt + n, _URL);
767                                         _algo = _optionProducer.getParameterValue(algoOpt + n,
768                                                         _algo);
769                                         _customBases = _optionProducer.getParameterValue(
770                                                         customBasesOpt + n, _customBases);
771                                         _auxBPs = _optionProducer.getParameterValue(auxBPsOpt + n,
772                                                         _auxBPs);
773                                         _highlightRegion = _optionProducer.getParameterValue(
774                                                         highlightRegionOpt + n, _highlightRegion);
775                                         _chemProbs = _optionProducer.getParameterValue(chemProbOpt
776                                                         + n, _chemProbs);
777                                         _customBPs = _optionProducer.getParameterValue(customBPsOpt
778                                                         + n, _customBPs);
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()),
786                                                         _backboneColor);
787                                         _backgroundColor = getSafeColor(
788                                                         _optionProducer.getParameterValue(
789                                                                         backgroundColorOpt + n,
790                                                                         _backgroundColor.toString()),
791                                                         _backgroundColor);
792                                         _bondColor = getSafeColor(
793                                                         _optionProducer.getParameterValue(bondColorOpt + n,
794                                                                         _bondColor.toString()), _bondColor);
795                                         _bpStyle = getSafeBPStyle(
796                                                         _optionProducer.getParameterValue(bpStyleOpt + n,
797                                                                         ""), _bpStyle);
798                                         _flip = _optionProducer.getParameterValue(
799                                                         flipOpt + n, _flip);
800                                         _orientation = _optionProducer.getParameterValue(
801                                                         orientationOpt + n, _orientation);
802                                         _titleColor = getSafeColor(
803                                                         _optionProducer.getParameterValue(
804                                                                         titleColorOpt + n, _titleColor.toString()),
805                                                         _titleColor);
806
807                                         
808                                         
809                                         if (!_URL.equals("")) {
810                                                 _sstruct = "";
811                                                 _sseq = "";
812                                                 _title = "";
813                                         }
814                                         _title = _optionProducer.getParameterValue(titleOpt + n, _title);
815
816                                         if (_comparisonMode && _firstSequence != null
817                                                         && _firstStructure != null
818                                                         && _secondSequence != null
819                                                         && _secondStructure != null) {
820                                         } else {
821                                                 _sseq = _optionProducer.getParameterValue(sequenceOpt
822                                                                 + n, _sseq);
823                                                 _sstruct = _optionProducer.getParameterValue(
824                                                                 structureOpt + n, _sstruct);
825                                                 if (!_sseq.equals("") && !_sstruct.equals("")) {
826                                                         _URL = "";
827                                                 }
828                                                 _comparisonMode = false;
829                                         }
830
831                                         // applique les valeurs des parametres recuperees
832                                         applyValues(n);
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);
843                                 }
844                         }// fin de boucle sur les lignes
845                 }// fin de boucle sur les colonnes
846         }
847
848         private RNA _defaultRNA = new RNA();
849
850         public void setRNA(RNA r) {
851                 _defaultRNA = r;
852         }
853
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";
860
861         private void applyValues(String n) throws ExceptionParameterError,
862                         ExceptionNonEqualLength, IOException, ExceptionFileFormatOrSyntax,
863                         ExceptionLoadingFailed {
864                 boolean applyOptions = true;
865                 int algoCode;
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;
878                 else
879                         algoCode = RNA.DRAW_MODE_RADIATE;
880
881                 if (_comparisonMode) {
882                         _mainSurface = new VARNAPanel(_firstSequence, _firstStructure,
883                                         _secondSequence, _secondStructure, algoCode, "");
884                 } else {
885                         _mainSurface = new VARNAPanel();
886                 }
887
888                 _VARNAPanelList.add(_mainSurface);
889                 _mainSurface.setSpaceBetweenBases(_spaceBetweenBases);
890                 _mainSurface.setTitle(_title);
891
892                 if (!_URL.equals("")) {
893                         URL url = null;
894                         try {
895
896                                 _mainSurface.setSpaceBetweenBases(_spaceBetweenBases);
897
898                                 url = new URL(_URL);
899                                 URLConnection connexion = url.openConnection();
900                                 connexion.setUseCaches(false);
901                                 InputStream r = connexion.getInputStream();
902                                 InputStreamReader inr = new InputStreamReader(r);
903
904                                 if (_URL.toLowerCase().endsWith(
905                                                 VARNAPanel.VARNA_SESSION_EXTENSION)) {
906                                         FullBackup f;
907                                         f = VARNAPanel.importSession(r, _URL);
908                                         _mainSurface.setConfig(f.config);
909                                         _mainSurface.showRNA(f.rna);
910                                         applyOptions = false;
911                                 } else {
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 + "'.");
918                                         }
919                                         RNA rna = rnas.iterator().next();
920                                         rna.drawRNA(algoCode, _mainSurface.getConfig());
921                                         _mainSurface.drawRNA(rna, algoCode);
922                                 }
923                                 if (!_title.isEmpty())
924                                 {
925                                         _mainSurface.setTitle(_title);
926                                 }
927                         } catch (ExceptionFileFormatOrSyntax e) {
928                                 if (url != null)
929                                         e.setPath(url.getPath());
930                         } catch (ExceptionDrawingAlgorithm e) {
931                                 _mainSurface.emitWarning(e.getMessage());
932                         }
933
934                 } else {
935                         if (!_comparisonMode) {
936                                 if (!_sstruct.equals("")) {
937                                         _mainSurface.drawRNA(_sseq, _sstruct, algoCode);
938                                 } else {
939                                         try {
940                                                 System.err.println("Printing default RNA "+_defaultRNA);
941                                                 _defaultRNA.drawRNA(algoCode, _mainSurface.getConfig());
942                                         } catch (ExceptionDrawingAlgorithm e) {
943                                                 e.printStackTrace();
944                                         }
945                                         _mainSurface.drawRNA(_defaultRNA);
946                                 }
947                         }
948                 }
949                 if (applyOptions)
950                 {
951                         if (_useInnerBaseColor) {
952                                 _mainSurface.setBaseInnerColor(_baseInnerColor);
953                         }
954                         if (_useBaseOutlineColor) {
955                                 _mainSurface.setBaseOutlineColor(_baseOutlineColor);
956                         }
957                         if (_useBaseNameColor) {
958                                 _mainSurface.setBaseNameColor(_baseNameColor);
959                         }
960                         if (_useBaseNumbersColor) {
961                                 _mainSurface.setBaseNumbersColor(_baseNumColor);
962                         }
963
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);
971
972                         _mainSurface.setTitleFontColor(_titleColor);
973                         _mainSurface.setTitleFontSize(_titleSize);
974
975                         _mainSurface.getPopupMenu().get_itemShowWarnings()
976                                         .setState(_warning);
977                         _mainSurface.setErrorsOn(_error);
978                         _mainSurface.setFlatExteriorLoop(_flatExteriorLoop);
979                         _mainSurface.setZoom(_zoom);
980                         _mainSurface.setZoomIncrement(_zoomAmount);
981                         _mainSurface.setBorderSize(_border);
982
983                         if (_useGapsColor) {
984                                 _mainSurface.setGapsBasesColor(this._gapsColor);
985                                 _mainSurface.setColorGapsBases(true);
986                         }
987
988                         if (_useNonStandardColor) {
989                                 _mainSurface.setNonStandardBasesColor(_nonStandardColor);
990                                 _mainSurface.setColorNonStandardBases(true);
991                         }
992
993                         _mainSurface.setShowNonPlanarBP(_drawTertiary);
994                         _mainSurface.setShowNonCanonicalBP(_drawNC);
995
996                         applyBasesStyle(n);
997
998                         if (!_customBases.equals(""))
999                                 applyBasesCustomStyles(_mainSurface);
1000
1001                         if (!_highlightRegion.equals(""))
1002                                 applyHighlightRegion(_mainSurface);
1003
1004                         if (!_auxBPs.equals(""))
1005                                 applyAuxBPs(_mainSurface);
1006
1007                         if (!_chemProbs.equals(""))
1008                                 applyChemProbs(_mainSurface);
1009
1010                         if (!_customBPs.equals(""))
1011                                 applyBPsCustomStyles(_mainSurface);
1012
1013                         _mainSurface.setDrawOutlineBases(_drawBases);
1014                         _mainSurface.setFillBases(_fillBases);
1015                         _mainSurface.drawRNA();
1016
1017                         if (!_annotations.equals(""))
1018                                 applyAnnotations(_mainSurface);
1019                         if (_autoHelices)
1020                                 _mainSurface.getVARNAUI().UIAutoAnnotateHelices();
1021                         if (_autoTerminalLoops)
1022                                 _mainSurface.getVARNAUI().UIAutoAnnotateTerminalLoops();
1023                         if (_autoInteriorLoops)
1024                                 _mainSurface.getVARNAUI().UIAutoAnnotateInteriorLoops();
1025
1026                         if (!_orientation.equals("")) {
1027                                 try {
1028                                         double d = 360 * _mainSurface.getOrientation()
1029                                                         / (2. * Math.PI);
1030                                         _rotation = Double.parseDouble(_orientation) - d;
1031                                 } catch (NumberFormatException e) {
1032                                         // TODO : Add some code here...
1033                                 }
1034
1035                         }
1036                         _mainSurface.globalRotation(_rotation);
1037
1038                         _mainSurface.setModifiable(_modifiable);
1039
1040                         _mainSurface.setColorMapCaption(_colorMapCaption);
1041                         applyColorMapStyle(_mainSurface);
1042                         applyFlips(_mainSurface);
1043                         applyColorMapValues(_mainSurface);
1044                         
1045                         // if (!_drawColorMap)
1046                         // _mainSurface.drawColorMap(_drawColorMap);
1047                 }
1048                 // ajoute le VARNAPanel au conteneur
1049         }
1050
1051         private void applyBasesStyle(String n) throws ExceptionParameterError {
1052                 String tmp = null;
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);
1057
1058                                 ArrayList<Integer> indicesList = new ArrayList<Integer>();
1059                                 if (tmp != null) {
1060                                         String[] basesList = tmp.split(",");
1061                                         for (int k = 0; k < basesList.length; k++) {
1062                                                 String cand = basesList[k].trim();
1063                                                 try {
1064                                                         String[] args = cand.split("-");
1065                                                         if (args.length == 1) {
1066                                                                 int baseNum = Integer.parseInt(cand);
1067                                                                 int index = _mainSurface.getRNA()
1068                                                                                 .getIndexFromBaseNumber(baseNum);
1069                                                                 if (index != -1) {
1070                                                                         indicesList.add(index);
1071                                                                 }
1072                                                         } else if (args.length == 2) {
1073                                                                 int baseNumFrom = Integer.parseInt(args[0]
1074                                                                                 .trim());
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++)
1083                                                                                 indicesList.add(l);
1084                                                                 }
1085                                                         }
1086                                                 } catch (NumberFormatException e) {
1087                                                         throw new ExceptionParameterError(e.getMessage(),
1088                                                                         "Bad Base Index: " + basesList[k]);
1089                                                 }
1090                                         }
1091                                         for (int k = 0; k < indicesList.size(); k++) {
1092                                                 int index = indicesList.get(k);
1093                                                 if ((index >= 0)
1094                                                                 && (index < _mainSurface.getRNA()
1095                                                                                 .get_listeBases().size())) {
1096                                                         _mainSurface
1097                                                                         .getRNA()
1098                                                                         .get_listeBases()
1099                                                                         .get(index)
1100                                                                         .setStyleBase(_basesStyleList.get(numStyle));
1101                                                 }
1102                                         }
1103                                 }
1104                         }
1105                 }// fin de boucle sur les styles
1106
1107         }
1108
1109         private void applyColorMapStyle(VARNAPanel vp) {
1110                 if (_colorMapStyle.length() != 0) {
1111                         vp.setColorMap(ModeleColorMap.parseColorMap(_colorMapStyle));
1112                 }
1113         }
1114
1115         private void applyColorMapValues(VARNAPanel vp) {
1116                 if (!_colorMapValues.equals("")) {
1117                         File f = new File(_colorMapValues);
1118                         if(f.exists() && !f.isDirectory()) { 
1119                                 try {
1120                                         vp.readValues(new FileReader(f));
1121                                         vp.drawColorMap(true);
1122                                         System.err.println("Loaded "+_colorMapValues);
1123                                 } catch (FileNotFoundException e) {
1124                                         e.printStackTrace();
1125                                 }
1126                         }
1127                         else
1128                         {
1129                                 String[] values = _colorMapValues.split("[;,]");
1130                                 ArrayList<Double> vals = new ArrayList<Double>();
1131                                 for (int i = 0; i < values.length; i++) {
1132                                         try {
1133                                                 vals.add(Double.parseDouble(values[i]));
1134                                         } catch (Exception e) {
1135         
1136                                         }
1137                                 }
1138                                 Double[] result = new Double[vals.size()];
1139                                 vals.toArray(result);
1140                                 vp.setColorMapValues(result);
1141                         }
1142                         ModeleColorMap cm = vp.getColorMap();
1143                         if (_colorMapMin != Double.MIN_VALUE) {
1144                                 // System.out.println("[A]"+_colorMapMin);
1145                                 cm.setMinValue(_colorMapMin);
1146                         }
1147                         if (_colorMapMax != Double.MAX_VALUE) {
1148                                 cm.setMaxValue(_colorMapMax);
1149                         }
1150                         _drawColorMap = true;
1151                 }
1152         }
1153
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(":");
1159                         try {
1160                                 if (data.length == 2) {
1161                                         int baseNum = Integer.parseInt(data[0]);
1162                                         int index = _mainSurface.getRNA().getIndexFromBaseNumber(
1163                                                         baseNum);
1164                                         if (index != -1) {
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)
1170                                                                 .setStyleBase(msb);
1171                                         }
1172                                 }
1173                         } catch (Exception e) {
1174                                 System.err.println("ApplyBasesCustomStyle: " + e.toString());
1175                         }
1176                 }
1177         }
1178
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];
1183                         try {
1184                                 HighlightRegionAnnotation nt = HighlightRegionAnnotation
1185                                                 .parseHighlightRegionAnnotation(region, vp);
1186                                 if (nt != null) {
1187                                         vp.addHighlightRegion(nt);
1188                                 }
1189                         } catch (Exception e) {
1190                                 System.err.println("Error in applyHighlightRegion: " + e.toString());
1191                         }
1192                 }
1193         }
1194
1195         private Dimension parseDimension(String s) {
1196                 Dimension d = new Dimension(0, 0);
1197                 try {
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) {
1205                 }
1206                 return d;
1207         }
1208
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(":");
1214                         try {
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,
1225                                                                         s2.length() - 1));
1226                                                         ModeleBP msbp = vp.getRNA().getBPStyle(a, b);
1227                                                         if (msbp != null) {
1228                                                                 msbp.assignParameters(style);
1229                                                         }
1230                                                 }
1231                                         }
1232                                 }
1233                         } catch (Exception e) {
1234                                 System.err.println("ApplyBPsCustomStyle: " + e.toString());
1235                         }
1236                 }
1237         }
1238
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(":");
1244                         try {
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()
1255                                                                 .get_listeBases();
1256                                                 ChemProbAnnotation cpa = new ChemProbAnnotation(
1257                                                                 mbl.get(c), mbl.get(d), style);
1258                                                 vp.getRNA().addChemProbAnnotation(cpa);
1259                                         }
1260                                 }
1261                         } catch (Exception e) {
1262                                 System.err.println("ChempProbs: " + e.toString());
1263                         }
1264                 }
1265         }
1266
1267         private void applyAuxBPs(VARNAPanel vp) {
1268                 String[] baseStyles = _auxBPs.split(";");
1269
1270                 for (int i = 0; i < baseStyles.length; i++) {
1271                         String thisStyle = baseStyles[i];
1272                         String[] data = thisStyle.split(":");
1273                         try {
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,
1283                                                                         s2.length() - 1));
1284                                                         int c = vp.getRNA().getIndexFromBaseNumber(a);
1285                                                         int d = vp.getRNA().getIndexFromBaseNumber(b);
1286
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);
1293                                                         }
1294                                                         vp.getRNA()
1295                                                                         .addBPToStructureUsingNumbers(a, b, msbp);
1296                                                 }
1297                                         }
1298                                 }
1299                         } catch (ExceptionModeleStyleBaseSyntaxError e1) {
1300                                 System.err.println("AuxApplyBPs: " + e1.toString());
1301                         } catch (ExceptionParameterError e) {
1302                                 // TODO Auto-generated catch block
1303                                 e.printStackTrace();
1304                         }
1305                 }
1306         }
1307
1308         private void applyFlips(VARNAPanel vp) {
1309                 String[] flips = _flip.split(";");
1310                 for (String s: flips)
1311                 {
1312                         if (!s.isEmpty())
1313                         {
1314                                 try{
1315                                         String[] data = s.split("-");
1316                                         int number = -1;
1317                                         if (data.length==1)
1318                                         {
1319                                                 number = Integer.parseInt(data[0]);                                     
1320                                         }
1321                                         else if (data.length==2)
1322                                         {
1323                                                 number = Integer.parseInt(data[1]);
1324                                         }
1325                                         if (number!=-1)
1326                                         {
1327                                                 int i = vp.getRNA().getIndexFromBaseNumber(number);
1328                                                 Point h = vp.getRNA().getExteriorHelix(i);
1329                                                 vp.getRNA().flipHelix(h);
1330                                         }
1331                                 } catch (Exception e) {
1332                                         System.err.println("Flip Helices: " + e.toString());
1333                                 }
1334                         }
1335                 }
1336         }
1337         
1338         /**
1339          * Format:
1340          * string:[type=[H|B|L|P]|x=double|y=double|anchor=int|size=int|color
1341          * =Color];
1342          * 
1343          * @param vp
1344          */
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);
1351                 }
1352         }
1353
1354
1355 }
1356
1357