2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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("consenus_"+rna1.getName());
82 vab = new AppVarnaBinding(rnaList);
83 //vab = new AppVarnaBinding(seq,struc);
84 //System.out.println("Hallo: "+name);
87 ssm = ap.getStructureSelectionManager();
88 ssm.addStructureViewerListener(this);
91 public void initVarna(){
92 //vab.setFinishedInit(false);
93 varnaPanel=vab.get_varnaPanel();
94 setBackground(Color.white);
95 JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,vab.getListPanel(),varnaPanel);
96 getContentPane().setLayout(new BorderLayout());
97 getContentPane().add(split, BorderLayout.CENTER);
98 //getContentPane().add(vab.getTools(), BorderLayout.NORTH);
99 varnaPanel.addVARNAListener(this);
100 jalview.gui.Desktop.addInternalFrame(this,"VARNA -"+name,getBounds().width, getBounds().height);
105 public String replaceOddGaps(String oldStr){
106 String patternStr = "[^([{<>}])]";
107 String replacementStr = ".";
108 Pattern pattern = Pattern.compile(patternStr);
109 Matcher matcher = pattern.matcher(oldStr);
110 String newStr=matcher.replaceAll(replacementStr);
114 public RNA trimRNA(RNA rna){
115 RNA rnaTrim = new RNA("trim_"+rna.getName());
117 rnaTrim.setRNA(rna.getSeq(),replaceOddGaps(rna.getStructDBN()));
118 } catch (ExceptionUnmatchedClosingParentheses e2) {
119 e2.printStackTrace();
120 } catch (ExceptionFileFormatOrSyntax e3) {
121 e3.printStackTrace();
124 StringBuffer seq=new StringBuffer(rnaTrim.getSeq());
125 StringBuffer struc=new StringBuffer(rnaTrim.getStructDBN());
126 for(int i=0;i<rnaTrim.getSeq().length();i++){
127 //TODO: Jalview utility for gap detection java.utils.isGap()
128 //TODO: Switch to jalview rna datamodel
129 if(seq.substring(i, i+1).compareTo("-")==0 || seq.substring(i, i+1).compareTo(".")==0){
130 if(!rnaTrim.findPair(i).isEmpty()){
131 int m=rnaTrim.findPair(i).get(1);
132 int l=rnaTrim.findPair(i).get(0);
134 struc.replace(m, m+1, "*");
135 struc.replace(l, l+1, "*");
137 struc.replace(i, i+1, "*");
142 String newSeq=rnaTrim.getSeq().replace("-", "");
143 rnaTrim.getSeq().replace(".", "");
144 String newStruc=struc.toString().replace("*", "");
147 rnaTrim.setRNA(newSeq,newStruc);
148 } catch (ExceptionUnmatchedClosingParentheses e) {
149 // TODO Auto-generated catch block
151 } catch (ExceptionFileFormatOrSyntax e) {
152 // TODO Auto-generated catch block
159 public void showPanel(boolean show){
160 this.setVisible(show);
163 private boolean _started = false;
171 } catch (OutOfMemoryError oomerror)
173 new OOMWarning("When trying to open the Varna viewer!", oomerror);
174 } catch (Exception ex)
176 Cache.log.error("Couldn't open Varna viewer!", ex);
181 public void onUINewStructure(VARNAConfig v, RNA r) {
182 // TODO Auto-generated method stub
187 public void onWarningEmitted(String s) {
188 // TODO Auto-generated method stub
192 * If a mouseOver event from the AlignmentPanel
193 * is noticed the currently selected RNA in the
194 * VARNA window is highlighted at the specific position.
195 * To be able to remove it before the next highlight
196 * it is saved in _lastHighlight
198 private HighlightRegionAnnotation _lastHighlight;
200 public void mouseOverSequence(SequenceI sequence, int index) {
201 // TODO Auto-generated method stub
202 RNA rna=vab.getSelectedRNA();
203 rna.removeHighlightRegion(_lastHighlight);
205 HighlightRegionAnnotation highlight = new HighlightRegionAnnotation(rna.getBasesBetween(index,index));
206 rna.addHighlightRegion(highlight);
207 _lastHighlight=highlight;
208 vab.updateSelectedRNA(rna);
212 public void mouseOverStructure(int atomIndex, String strInfo) {
213 // TODO Auto-generated method stub
218 public void onStructureRedrawn()
220 // TODO Auto-generated method stub