2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * 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 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
24 import javax.swing.event.*;
26 import java.awt.event.*;
29 import jalview.api.SequenceStructureBinding;
30 import jalview.bin.Cache;
31 import jalview.datamodel.*;
32 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
33 import jalview.structure.*;
35 import jalview.schemes.*;
36 import fr.orsay.lri.varna.VARNAPanel;
37 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
38 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
39 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
40 import fr.orsay.lri.varna.interfaces.InterfaceVARNAListener;
41 import fr.orsay.lri.varna.models.VARNAConfig;
42 import fr.orsay.lri.varna.models.annotations.HighlightRegionAnnotation;
43 import fr.orsay.lri.varna.models.rna.ModeleBaseNucleotide;
44 import fr.orsay.lri.varna.models.rna.ModeleStyleBP;
45 import fr.orsay.lri.varna.models.rna.RNA;
48 public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,SecondaryStructureListener// implements Runnable,SequenceStructureBinding, ViewSetProvider
53 VARNAPanel varnaPanel;
57 public StructureSelectionManager ssm;
60 vab = new AppVarnaBinding();
64 public AppVarna(String seq,String struc,String name,AlignmentPanel ap){
65 ArrayList<RNA> rnaList = new ArrayList<RNA>();
66 RNA rna1 = new RNA(name);
68 rna1.setRNA(seq,struc);
69 } catch (ExceptionUnmatchedClosingParentheses e2) {
71 } catch (ExceptionFileFormatOrSyntax e3) {
74 rnaList.add(trimRNA(rna1));
76 rna1.setName("consenus_"+rna1.getName());
79 vab = new AppVarnaBinding(rnaList);
80 //vab = new AppVarnaBinding(seq,struc);
81 //System.out.println("Hallo: "+name);
84 ssm = ap.getStructureSelectionManager();
85 ssm.addStructureViewerListener(this);
88 public void initVarna(){
89 //vab.setFinishedInit(false);
90 varnaPanel=vab.get_varnaPanel();
91 setBackground(Color.white);
92 JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,vab.getListPanel(),varnaPanel);
93 getContentPane().setLayout(new BorderLayout());
94 getContentPane().add(split, BorderLayout.CENTER);
95 getContentPane().add(vab.getTools(), BorderLayout.NORTH);
96 varnaPanel.addVARNAListener(this);
97 jalview.gui.Desktop.addInternalFrame(this,"VARNA -"+name,getBounds().width, getBounds().height);
102 public RNA trimRNA(RNA rna){
103 RNA rnaTrim = new RNA("trim_"+rna.getName());
105 rnaTrim.setRNA(rna.getSeq(),rna.getStructDBN());
106 } catch (ExceptionUnmatchedClosingParentheses e2) {
107 e2.printStackTrace();
108 } catch (ExceptionFileFormatOrSyntax e3) {
109 e3.printStackTrace();
112 StringBuffer seq=new StringBuffer(rnaTrim.getSeq());
113 StringBuffer struc=new StringBuffer(rnaTrim.getStructDBN());
114 for(int i=0;i<rnaTrim.getSeq().length();i++){
115 //TODO: Jalview utility for gap detection java.utils.isGap()
116 //TODO: Switch to jalview rna datamodel
117 if(seq.substring(i, i+1).compareTo("-")==0 || seq.substring(i, i+1).compareTo(".")==0){
118 if(!rnaTrim.findPair(i).isEmpty()){
119 int m=rnaTrim.findPair(i).get(1);
120 int l=rnaTrim.findPair(i).get(0);
122 struc.replace(m, m+1, "*");
123 struc.replace(l, l+1, "*");
125 struc.replace(i, i+1, "*");
130 String newSeq=rnaTrim.getSeq().replace("-", "");
131 rnaTrim.getSeq().replace(".", "");
132 String newStruc=struc.toString().replace("*", "");
135 rnaTrim.setRNA(newSeq,newStruc);
136 } catch (ExceptionUnmatchedClosingParentheses e) {
137 // TODO Auto-generated catch block
139 } catch (ExceptionFileFormatOrSyntax e) {
140 // TODO Auto-generated catch block
147 public void showPanel(boolean show){
148 this.setVisible(show);
151 private boolean _started = false;
159 } catch (OutOfMemoryError oomerror)
161 new OOMWarning("When trying to open the Varna viewer!", oomerror);
162 } catch (Exception ex)
164 Cache.log.error("Couldn't open Varna viewer!", ex);
169 public void onLayoutChanged() {
170 // TODO Auto-generated method stub
175 public void onUINewStructure(VARNAConfig v, RNA r) {
176 // TODO Auto-generated method stub
181 public void onWarningEmitted(String s) {
182 // TODO Auto-generated method stub
186 * If a mouseOver event from the AlignmentPanel
187 * is noticed the currently selected RNA in the
188 * VARNA window is highlighted at the specific position.
189 * To be able to remove it before the next highlight
190 * it is saved in _lastHighlight
192 private HighlightRegionAnnotation _lastHighlight;
194 public void mouseOverSequence(SequenceI sequence, int index) {
195 // TODO Auto-generated method stub
196 RNA rna=vab.getSelectedRNA();
197 rna.removeHighlightRegion(_lastHighlight);
199 HighlightRegionAnnotation highlight = new HighlightRegionAnnotation(rna.getBasesBetween(index,index));
200 rna.addHighlightRegion(highlight);
201 _lastHighlight=highlight;
202 vab.updateSelectedRNA(rna);
206 public void mouseOverStructure(int atomIndex, String strInfo) {
207 // TODO Auto-generated method stub