From 8f3cf5f09e970ac6e5d9032c03ec29f69fb4b356 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 1 Mar 2012 21:40:52 +0000 Subject: [PATCH] (JAL-842) ensure deletions are accounted for when highlighting mouseover in alignment panel on RNA structure, basic selected region highlighting, and broadcast of mouse position in varna window to associated sequence. --- src/jalview/gui/AppVarna.java | 181 +++++++++++++++++++++++++++++++--------- src/jalview/gui/PopupMenu.java | 4 +- 2 files changed, 142 insertions(+), 43 deletions(-) diff --git a/src/jalview/gui/AppVarna.java b/src/jalview/gui/AppVarna.java index 9054298..daa0bea 100644 --- a/src/jalview/gui/AppVarna.java +++ b/src/jalview/gui/AppVarna.java @@ -35,18 +35,23 @@ 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; +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; -public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,SecondaryStructureListener// implements Runnable,SequenceStructureBinding, ViewSetProvider +public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,SelectionListener, SecondaryStructureListener// implements Runnable,SequenceStructureBinding, ViewSetProvider +, InterfaceVARNASelectionListener, VamsasSource { AppVarnaBinding vab; @@ -63,30 +68,34 @@ public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,S }*/ - - public AppVarna(String seq,String struc,String name,AlignmentPanel ap){ - ArrayList rnaList = new ArrayList(); - RNA rna1 = new RNA(name); - try { - rna1.setRNA(seq,replaceOddGaps(struc)); - } catch (ExceptionUnmatchedClosingParentheses e2) { - e2.printStackTrace(); - } catch (ExceptionFileFormatOrSyntax e3) { - e3.printStackTrace(); - } - rnaList.add(trimRNA(rna1)); - rnaList.add(rna1); - rna1.setName("consenus_"+rna1.getName()); - - - vab = new AppVarnaBinding(rnaList); - //vab = new AppVarnaBinding(seq,struc); - //System.out.println("Hallo: "+name); - this.name=name; - initVarna(); - ssm = ap.getStructureSelectionManager(); - ssm.addStructureViewerListener(this); - } + public AppVarna(SequenceI seq,String strucseq, String struc,String name,AlignmentPanel ap){ + ArrayList rnaList = new ArrayList(); + RNA rna1 = new RNA(name); + try { + rna1.setRNA(strucseq,replaceOddGaps(struc)); + } catch (ExceptionUnmatchedClosingParentheses e2) { + e2.printStackTrace(); + } catch (ExceptionFileFormatOrSyntax e3) { + e3.printStackTrace(); + } + RNA trim=trimRNA(rna1); + rnaList.add(trim); + rnaList.add(rna1); + rna1.setName("consensus_"+rna1.getName()); + + { + this.seqs.put(trim, seq); + this.seqs.put(rna1, seq); + } + vab = new AppVarnaBinding(rnaList); + //vab = new AppVarnaBinding(seq,struc); + //System.out.println("Hallo: "+name); + this.name=name; + initVarna(); + ssm = ap.getStructureSelectionManager(); + ssm.addStructureViewerListener(this); + ssm.addSelectionListener(this); + } public void initVarna(){ //vab.setFinishedInit(false); @@ -97,6 +106,7 @@ public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,S getContentPane().add(split, BorderLayout.CENTER); //getContentPane().add(vab.getTools(), BorderLayout.NORTH); varnaPanel.addVARNAListener(this); + varnaPanel.addSelectionListener(this); jalview.gui.Desktop.addInternalFrame(this,"VARNA -"+name,getBounds().width, getBounds().height); this.pack(); showPanel(true); @@ -112,6 +122,7 @@ public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,S } public RNA trimRNA(RNA rna){ + ShiftList offset=new ShiftList(); RNA rnaTrim = new RNA("trim_"+rna.getName()); try { rnaTrim.setRNA(rna.getSeq(),replaceOddGaps(rna.getStructDBN())); @@ -123,10 +134,15 @@ public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,S StringBuffer seq=new StringBuffer(rnaTrim.getSeq()); StringBuffer struc=new StringBuffer(rnaTrim.getStructDBN()); - for(int i=0;i-1) + { + offset.addShift(ofstart, ofstart-i); + ofstart=-1; + } } - } - - String newSeq=rnaTrim.getSeq().replace("-", ""); + } + // final gap + if (ofstart>-1) + { + offset.addShift(ofstart, ofstart-sleng); + ofstart=-1; + } + String newSeq=rnaTrim.getSeq().replace("-", ""); rnaTrim.getSeq().replace(".", ""); String newStruc=struc.toString().replace("*", ""); try { rnaTrim.setRNA(newSeq,newStruc); + registerOffset(rnaTrim,offset); } catch (ExceptionUnmatchedClosingParentheses e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -152,9 +180,16 @@ public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,S // TODO Auto-generated catch block e.printStackTrace(); } - return rnaTrim; } + Map seqs=new Hashtable(); + Map offsets=new Hashtable(); + Map offsetsInv=new Hashtable(); + private void registerOffset(RNA rnaTrim, ShiftList offset) + { + offsets.put(rnaTrim, offset); + offsetsInv.put(rnaTrim,offset.getInverse()); + } public void showPanel(boolean show){ this.setVisible(show); @@ -179,8 +214,7 @@ public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,S @Override public void onUINewStructure(VARNAConfig v, RNA r) { - // TODO Auto-generated method stub - + } @Override @@ -188,6 +222,31 @@ public void onWarningEmitted(String s) { // TODO Auto-generated method stub } +private class VarnaHighlighter { + private HighlightRegionAnnotation _lastHighlight; + private RNA _lastRNAhighlighted=null; + public void highlightRegion(RNA rna, int start,int end) + { + if (_lastRNAhighlighted!=null) + { + _lastRNAhighlighted.removeHighlightRegion(_lastHighlight); + } + HighlightRegionAnnotation highlight = new HighlightRegionAnnotation(rna.getBasesBetween(start,end)); + rna.addHighlightRegion(highlight); + _lastHighlight=highlight; + _lastRNAhighlighted=rna; + + } + public HighlightRegionAnnotation getLastHighlight() { + return _lastHighlight; + } + public RNA getLastRNA() + { + return _lastRNAhighlighted; + } +} +VarnaHighlighter mouseOverHighlighter=new VarnaHighlighter(), +selectionHighlighter=new VarnaHighlighter(); /** * If a mouseOver event from the AlignmentPanel * is noticed the currently selected RNA in the @@ -195,16 +254,15 @@ public void onWarningEmitted(String s) { * To be able to remove it before the next highlight * it is saved in _lastHighlight */ -private HighlightRegionAnnotation _lastHighlight; @Override public void mouseOverSequence(SequenceI sequence, int index) { - // TODO Auto-generated method stub - RNA rna=vab.getSelectedRNA(); - rna.removeHighlightRegion(_lastHighlight); - - HighlightRegionAnnotation highlight = new HighlightRegionAnnotation(rna.getBasesBetween(index,index)); - rna.addHighlightRegion(highlight); - _lastHighlight=highlight; + RNA rna=vab.getSelectedRNA(); + ShiftList shift=offsets.get(rna); + if (shift!=null) + { + index=shift.shift(index); + } + mouseOverHighlighter.highlightRegion(rna, index, index); vab.updateSelectedRNA(rna); } @@ -221,5 +279,46 @@ public void onStructureRedrawn() } +@Override +public void selection(SequenceGroup seqsel, ColumnSelection colsel, + SelectionSource source) +{ + int start=seqsel.getStartRes(),end=seqsel.getEndRes(); + RNA rna=vab.getSelectedRNA(); + ShiftList shift=offsets.get(rna); + if (shift!=null) + { + start=shift.shift(start); + end=shift.shift(end); + } + selectionHighlighter.highlightRegion(rna, start, end); + selectionHighlighter.getLastHighlight().setOutlineColor(seqsel.getOutlineColour()); + vab.updateSelectedRNA(rna); +} + +@Override +public void onHoverChanged(ModeleBase arg0, ModeleBase arg1) +{ + RNA rna=vab.getSelectedRNA(); + ShiftList shift=offsetsInv.get(rna); + SequenceI seq=seqs.get(rna); + if (arg1!=null && seq!=null) + { + if (shift!=null) + { + ssm.mouseOverVamsasSequence(seq, seq.findIndex(arg1.getIndex()), this); + } else { + ssm.mouseOverVamsasSequence(seq, arg1.getIndex(), this); + } + } +} + +@Override +public void onSelectionChanged(BaseList arg0, BaseList arg1, BaseList arg2) +{ + // TODO Auto-generated method stub + +} + } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 23a5008..6139764 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -277,7 +277,7 @@ public class PopupMenu extends JPopupMenu { public void actionPerformed(ActionEvent e) { - new AppVarna(seq.getSequenceAsString(), rnastruc, seq + new AppVarna(seq, seq.getSequenceAsString(), rnastruc, seq .getName(), ap); } }); @@ -304,7 +304,7 @@ public class PopupMenu extends JPopupMenu public void actionPerformed(ActionEvent e) { // TODO: VARNA does'nt print gaps in the sequence - new AppVarna(seq.getSequenceAsString(), rnastruc, seq + new AppVarna(seq,seq.getSequenceAsString(), rnastruc, seq .getName(), ap); } }); -- 1.7.10.2