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.RNA;
49 public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,SecondaryStructureListener// implements Runnable,SequenceStructureBinding, ViewSetProvider
54 VARNAPanel varnaPanel;
58 public StructureSelectionManager ssm;
61 vab = new AppVarnaBinding();
67 public AppVarna(String seq,String struc,String name,AlignmentPanel ap){
68 ArrayList<RNA> rnaList = new ArrayList<RNA>();
69 RNA rna1 = new RNA(name);
71 rna1.setRNA(seq,replaceOddGaps(struc));
72 } catch (ExceptionUnmatchedClosingParentheses e2) {
74 } catch (ExceptionFileFormatOrSyntax e3) {
77 rnaList.add(trimRNA(rna1));
79 //rna1.setName("consensus_"+rna1.getName());
82 vab = new AppVarnaBinding(rnaList);
85 ssm = ap.getStructureSelectionManager();
86 ssm.addStructureViewerListener(this);
89 public void initVarna(){
90 //vab.setFinishedInit(false);
91 varnaPanel=vab.get_varnaPanel();
92 setBackground(Color.white);
93 JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,vab.getListPanel(),varnaPanel);
94 getContentPane().setLayout(new BorderLayout());
95 getContentPane().add(split, BorderLayout.CENTER);
96 //getContentPane().add(vab.getTools(), BorderLayout.NORTH);
97 varnaPanel.addVARNAListener(this);
98 jalview.gui.Desktop.addInternalFrame(this,"VARNA -"+name,getBounds().width, getBounds().height);
103 public String replaceOddGaps(String oldStr){
104 String patternStr = "[^([{<>}])]";
105 String replacementStr = ".";
106 Pattern pattern = Pattern.compile(patternStr);
107 Matcher matcher = pattern.matcher(oldStr);
108 String newStr=matcher.replaceAll(replacementStr);
112 public RNA trimRNA(RNA rna){
113 RNA rnaTrim = new RNA("trim_"+rna.getName());
115 rnaTrim.setRNA(rna.getSeq(),replaceOddGaps(rna.getStructDBN()));
116 } catch (ExceptionUnmatchedClosingParentheses e2) {
117 e2.printStackTrace();
118 } catch (ExceptionFileFormatOrSyntax e3) {
119 e3.printStackTrace();
122 StringBuffer seq=new StringBuffer(rnaTrim.getSeq());
123 StringBuffer struc=new StringBuffer(rnaTrim.getStructDBN());
124 for(int i=0;i<rnaTrim.getSeq().length();i++){
125 //TODO: Jalview utility for gap detection java.utils.isGap()
126 //TODO: Switch to jalview rna datamodel
127 if(seq.substring(i, i+1).compareTo("-")==0 || seq.substring(i, i+1).compareTo(".")==0){
128 if(!rnaTrim.findPair(i).isEmpty()){
129 int m=rnaTrim.findPair(i).get(1);
130 int l=rnaTrim.findPair(i).get(0);
132 struc.replace(m, m+1, "*");
133 struc.replace(l, l+1, "*");
135 struc.replace(i, i+1, "*");
140 String newSeq=rnaTrim.getSeq().replace("-", "");
141 rnaTrim.getSeq().replace(".", "");
142 String newStruc=struc.toString().replace("*", "");
145 rnaTrim.setRNA(newSeq,newStruc);
146 } catch (ExceptionUnmatchedClosingParentheses e) {
147 // TODO Auto-generated catch block
149 } catch (ExceptionFileFormatOrSyntax e) {
150 // TODO Auto-generated catch block
157 public void showPanel(boolean show){
158 this.setVisible(show);
161 private boolean _started = false;
169 } catch (OutOfMemoryError oomerror)
171 new OOMWarning("When trying to open the Varna viewer!", oomerror);
172 } catch (Exception ex)
174 Cache.log.error("Couldn't open Varna viewer!", ex);
179 public void onUINewStructure(VARNAConfig v, RNA r) {
180 // TODO Auto-generated method stub
185 public void onWarningEmitted(String s) {
186 // TODO Auto-generated method stub
190 * If a mouseOver event from the AlignmentPanel
191 * is noticed the currently selected RNA in the
192 * VARNA window is highlighted at the specific position.
193 * To be able to remove it before the next highlight
194 * it is saved in _lastHighlight
196 private HighlightRegionAnnotation _lastHighlight;
198 public void mouseOverSequence(SequenceI sequence, int index) {
199 // TODO Auto-generated method stub
200 RNA rna=vab.getSelectedRNA();
201 rna.removeHighlightRegion(_lastHighlight);
203 HighlightRegionAnnotation highlight = new HighlightRegionAnnotation(rna.getBasesBetween(index,index));
204 rna.addHighlightRegion(highlight);
205 _lastHighlight=highlight;
206 vab.updateSelectedRNA(rna);
210 public void mouseOverStructure(int atomIndex, String strInfo) {
211 // TODO Auto-generated method stub
216 public void onStructureRedrawn()
218 // TODO Auto-generated method stub