X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAppVarna.java;h=5c3785a3d6b050bec34250482770efd615f54aaa;hb=93d63f3c608771bb48b5ac18f761194a1ea28554;hp=06de21fbe0233a7e4c083fa11bbfb2657e6f6995;hpb=a98cc981f4aaa91a8684fc551762ed1b5d69f625;p=jalview.git diff --git a/src/jalview/gui/AppVarna.java b/src/jalview/gui/AppVarna.java index 06de21f..5c3785a 100644 --- a/src/jalview/gui/AppVarna.java +++ b/src/jalview/gui/AppVarna.java @@ -1,46 +1,40 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) - * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.gui; -import java.util.*; +import java.awt.BorderLayout; +import java.awt.Color; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.awt.*; - -import javax.swing.*; -import javax.swing.event.*; -import java.awt.event.*; -import java.io.*; +import javax.swing.JInternalFrame; +import javax.swing.JSplitPane; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; -import jalview.api.AlignViewportI; -import jalview.api.AlignmentViewPanel; -import jalview.api.SequenceStructureBinding; -import jalview.bin.Cache; -import jalview.datamodel.*; -import jalview.gui.ViewSelectionMenu.ViewSetProvider; -import jalview.structure.*; -import jalview.io.*; -import jalview.schemes.*; -import jalview.util.ShiftList; import fr.orsay.lri.varna.VARNAPanel; import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax; -import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength; import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses; import fr.orsay.lri.varna.interfaces.InterfaceVARNAListener; import fr.orsay.lri.varna.interfaces.InterfaceVARNASelectionListener; @@ -48,9 +42,20 @@ import fr.orsay.lri.varna.models.BaseList; import fr.orsay.lri.varna.models.VARNAConfig; import fr.orsay.lri.varna.models.annotations.HighlightRegionAnnotation; import fr.orsay.lri.varna.models.rna.ModeleBase; -import fr.orsay.lri.varna.models.rna.ModeleBaseNucleotide; import fr.orsay.lri.varna.models.rna.RNA; +import jalview.bin.Cache; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.structure.SecondaryStructureListener; +import jalview.structure.SelectionListener; +import jalview.structure.SelectionSource; +import jalview.structure.StructureSelectionManager; +import jalview.structure.VamsasSource; +import jalview.util.MessageManager; +import jalview.util.ShiftList; + public class AppVarna extends JInternalFrame implements InterfaceVARNAListener, SelectionListener, SecondaryStructureListener// implements @@ -73,15 +78,26 @@ public class AppVarna extends JInternalFrame implements AlignmentPanel ap; - public AppVarna(SequenceI seq, String strucseq, String struc, - String name, AlignmentPanel ap) + public AppVarna(String sname, SequenceI seq, String strucseq, + String struc, String name, AlignmentPanel ap) { - this.ap=ap; + + // System.out.println("1:"+sname); + // System.out.println("2:"+seq); + // System.out.println("3:"+strucseq); + // System.out.println("4:"+struc); + // System.out.println("5:"+name); + // System.out.println("6:"+ap); + this.ap = ap; ArrayList rnaList = new ArrayList(); RNA rna1 = new RNA(name); try { + rna1.setRNA(strucseq, replaceOddGaps(struc)); + // System.out.println("The sequence is :"+rna1.getSeq()); + // System.out.println("The sequence is:"+struc); + // System.out.println("The sequence is:"+replaceOddGaps(struc).toString()); } catch (ExceptionUnmatchedClosingParentheses e2) { e2.printStackTrace(); @@ -89,12 +105,13 @@ public class AppVarna extends JInternalFrame implements { e3.printStackTrace(); } - RNA trim = trimRNA(rna1); + RNA trim = trimRNA(rna1, "trimmed " + sname); rnaList.add(trim); rnaList.add(rna1); + rnas.put(seq, rna1); rnas.put(seq, trim); - rna1.setName("consensus_" + rna1.getName()); + rna1.setName(sname + " (with gaps)"); { seqs.put(trim, seq); @@ -109,16 +126,27 @@ public class AppVarna extends JInternalFrame implements } vab = new AppVarnaBinding(rnaList); // vab = new AppVarnaBinding(seq,struc); - // System.out.println("Hallo: "+name); - this.name = name; + this.name = sname + " trimmed to " + name; initVarna(); + ssm = ap.getStructureSelectionManager(); + // System.out.println(ssm.toString()); ssm.addStructureViewerListener(this); ssm.addSelectionListener(this); + addInternalFrameListener(new InternalFrameAdapter() + { + @Override + public void internalFrameClosed(InternalFrameEvent evt) + { + close(); + } + }); + } public void initVarna() { + // vab.setFinishedInit(false); varnaPanel = vab.get_varnaPanel(); setBackground(Color.white); @@ -129,10 +157,12 @@ public class AppVarna extends JInternalFrame implements // getContentPane().add(vab.getTools(), BorderLayout.NORTH); varnaPanel.addVARNAListener(this); varnaPanel.addSelectionListener(this); - jalview.gui.Desktop.addInternalFrame(this, "VARNA -" + name, - getBounds().width, getBounds().height); + jalview.gui.Desktop.addInternalFrame(this, + MessageManager.formatMessage("label.varna_params", new String[] + { name }), getBounds().width, getBounds().height); this.pack(); showPanel(true); + } public String replaceOddGaps(String oldStr) @@ -145,10 +175,11 @@ public class AppVarna extends JInternalFrame implements return newStr; } - public RNA trimRNA(RNA rna) + public RNA trimRNA(RNA rna, String name) { ShiftList offset = new ShiftList(); - RNA rnaTrim = new RNA("trim_" + rna.getName()); + + RNA rnaTrim = new RNA(name); try { rnaTrim.setRNA(rna.getSeq(), replaceOddGaps(rna.getStructDBN())); @@ -190,7 +221,7 @@ public class AppVarna extends JInternalFrame implements { if (ofstart > -1) { - offset.addShift(ofstart, ofstart - i); + offset.addShift(offset.shift(ofstart), ofstart - i); ofstart = -1; } } @@ -198,7 +229,7 @@ public class AppVarna extends JInternalFrame implements // final gap if (ofstart > -1) { - offset.addShift(ofstart, ofstart - sleng); + offset.addShift(offset.shift(ofstart), ofstart - sleng); ofstart = -1; } String newSeq = rnaTrim.getSeq().replace("-", ""); @@ -304,12 +335,13 @@ public class AppVarna extends JInternalFrame implements if (_lastRNAhighlighted != null) { _lastRNAhighlighted.removeHighlightRegion(_lastHighlight); - if (vab!=null) { + if (vab != null) + { vab.updateSelectedRNA(_lastRNAhighlighted); } _lastRNAhighlighted = null; _lastHighlight = null; - + } } } @@ -327,12 +359,14 @@ public class AppVarna extends JInternalFrame implements public void mouseOverSequence(SequenceI sequence, int index) { RNA rna = vab.getSelectedRNA(); - if (rnas.get(sequence) == rna) + if (seqs.get(rna) == sequence) { ShiftList shift = offsets.get(rna); if (shift != null) { + // System.err.print("Orig pos:"+index); index = shift.shift(index); + // System.err.println("\nFinal pos:"+index); } mouseOverHighlighter.highlightRegion(rna, index, index); vab.updateSelectedRNA(rna); @@ -388,9 +422,9 @@ public class AppVarna extends JInternalFrame implements { if (shift != null) { - int i=shift.shift(arg1.getIndex()); - ssm.mouseOverVamsasSequence(seq, - i, this); + int i = shift.shift(arg1.getIndex()); + // System.err.println("shifted "+(arg1.getIndex())+" to "+i); + ssm.mouseOverVamsasSequence(seq, i, this); } else { @@ -402,8 +436,38 @@ public class AppVarna extends JInternalFrame implements @Override public void onSelectionChanged(BaseList arg0, BaseList arg1, BaseList arg2) { - // TODO translate selected regions in VARNA to a selection on the alignpanel. - + // TODO translate selected regions in VARNA to a selection on the + // alignpanel. + + } + + @Override + public void onTranslationChanged() + { + // TODO Auto-generated method stub + + } + + @Override + public void onZoomLevelChanged() + { + // TODO Auto-generated method stub + + } + + /** + * Tidy up as necessary when the viewer panel is closed + */ + protected void close() + { + /* + * Deregister as a listener, to free references to this object + */ + if (ssm != null) + { + ssm.removeStructureViewerListener(AppVarna.this, null); + ssm.removeSelectionListener(AppVarna.this); + } } }