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/>.
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
26 import javax.swing.event.*;
28 import java.awt.event.*;
31 import jalview.api.SequenceStructureBinding;
32 import jalview.bin.Cache;
33 import jalview.datamodel.*;
34 import jalview.gui.ViewSelectionMenu.ViewSetProvider;
35 import jalview.structure.*;
37 import jalview.schemes.*;
38 import fr.orsay.lri.varna.VARNAPanel;
39 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
40 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
41 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
42 import fr.orsay.lri.varna.interfaces.InterfaceVARNAListener;
43 import fr.orsay.lri.varna.models.VARNAConfig;
44 import fr.orsay.lri.varna.models.annotations.HighlightRegionAnnotation;
45 import fr.orsay.lri.varna.models.rna.ModeleBaseNucleotide;
46 import fr.orsay.lri.varna.models.rna.ModeleStyleBP;
47 import fr.orsay.lri.varna.models.rna.RNA;
50 public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,SecondaryStructureListener// implements Runnable,SequenceStructureBinding, ViewSetProvider
55 VARNAPanel varnaPanel;
59 public StructureSelectionManager ssm;
62 vab = new AppVarnaBinding();
68 public AppVarna(String seq,String struc,String name,AlignmentPanel ap){
69 ArrayList<RNA> rnaList = new ArrayList<RNA>();
70 RNA rna1 = new RNA(name);
72 rna1.setRNA(seq,replaceOddGaps(struc));
73 } catch (ExceptionUnmatchedClosingParentheses e2) {
75 } catch (ExceptionFileFormatOrSyntax e3) {
78 rnaList.add(trimRNA(rna1));
80 rna1.setName("consenus_"+rna1.getName());
83 vab = new AppVarnaBinding(rnaList);
84 //vab = new AppVarnaBinding(seq,struc);
85 //System.out.println("Hallo: "+name);
88 ssm = ap.getStructureSelectionManager();
89 ssm.addStructureViewerListener(this);
92 public void initVarna(){
93 //vab.setFinishedInit(false);
94 varnaPanel=vab.get_varnaPanel();
95 setBackground(Color.white);
96 JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,vab.getListPanel(),varnaPanel);
97 getContentPane().setLayout(new BorderLayout());
98 getContentPane().add(split, BorderLayout.CENTER);
99 //getContentPane().add(vab.getTools(), BorderLayout.NORTH);
100 varnaPanel.addVARNAListener(this);
101 jalview.gui.Desktop.addInternalFrame(this,"VARNA -"+name,getBounds().width, getBounds().height);
106 public String replaceOddGaps(String oldStr){
107 String patternStr = "[^([{<>}])]";
108 String replacementStr = ".";
109 Pattern pattern = Pattern.compile(patternStr);
110 Matcher matcher = pattern.matcher(oldStr);
111 String newStr=matcher.replaceAll(replacementStr);
115 public RNA trimRNA(RNA rna){
116 RNA rnaTrim = new RNA("trim_"+rna.getName());
118 rnaTrim.setRNA(rna.getSeq(),replaceOddGaps(rna.getStructDBN()));
119 } catch (ExceptionUnmatchedClosingParentheses e2) {
120 e2.printStackTrace();
121 } catch (ExceptionFileFormatOrSyntax e3) {
122 e3.printStackTrace();
125 StringBuffer seq=new StringBuffer(rnaTrim.getSeq());
126 StringBuffer struc=new StringBuffer(rnaTrim.getStructDBN());
127 for(int i=0;i<rnaTrim.getSeq().length();i++){
128 //TODO: Jalview utility for gap detection java.utils.isGap()
129 //TODO: Switch to jalview rna datamodel
130 if(seq.substring(i, i+1).compareTo("-")==0 || seq.substring(i, i+1).compareTo(".")==0){
131 if(!rnaTrim.findPair(i).isEmpty()){
132 int m=rnaTrim.findPair(i).get(1);
133 int l=rnaTrim.findPair(i).get(0);
135 struc.replace(m, m+1, "*");
136 struc.replace(l, l+1, "*");
138 struc.replace(i, i+1, "*");
143 String newSeq=rnaTrim.getSeq().replace("-", "");
144 rnaTrim.getSeq().replace(".", "");
145 String newStruc=struc.toString().replace("*", "");
148 rnaTrim.setRNA(newSeq,newStruc);
149 } catch (ExceptionUnmatchedClosingParentheses e) {
150 // TODO Auto-generated catch block
152 } catch (ExceptionFileFormatOrSyntax e) {
153 // TODO Auto-generated catch block
160 public void showPanel(boolean show){
161 this.setVisible(show);
164 private boolean _started = false;
172 } catch (OutOfMemoryError oomerror)
174 new OOMWarning("When trying to open the Varna viewer!", oomerror);
175 } catch (Exception ex)
177 Cache.log.error("Couldn't open Varna viewer!", ex);
182 public void onLayoutChanged() {
183 // TODO Auto-generated method stub
188 public void onUINewStructure(VARNAConfig v, RNA r) {
189 // TODO Auto-generated method stub
194 public void onWarningEmitted(String s) {
195 // TODO Auto-generated method stub
199 * If a mouseOver event from the AlignmentPanel
200 * is noticed the currently selected RNA in the
201 * VARNA window is highlighted at the specific position.
202 * To be able to remove it before the next highlight
203 * it is saved in _lastHighlight
205 private HighlightRegionAnnotation _lastHighlight;
207 public void mouseOverSequence(SequenceI sequence, int index) {
208 // TODO Auto-generated method stub
209 RNA rna=vab.getSelectedRNA();
210 rna.removeHighlightRegion(_lastHighlight);
212 HighlightRegionAnnotation highlight = new HighlightRegionAnnotation(rna.getBasesBetween(index,index));
213 rna.addHighlightRegion(highlight);
214 _lastHighlight=highlight;
215 vab.updateSelectedRNA(rna);
219 public void mouseOverStructure(int atomIndex, String strInfo) {
220 // TODO Auto-generated method stub