();
+
+ private void registerOffset(RNA rnaTrim, ShiftList offset)
{
- Vector toshow = new Vector();
- String lbl;
- int mlength, p, mnum;
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
- if (item.isSelected())
- {
- toshow.addElement(item.getText());
- }
- }
- }
- jmb.centerViewer(toshow);
+ offsets.put(rnaTrim, offset);
+ offsetsInv.put(rnaTrim, offset.getInverse());
}
- void closeViewer()
+ public void showPanel(boolean show)
{
- jmb.closeViewer();
- ap = null;
- _aps.clear();
- _alignwith.clear();
- _colourwith.clear();
- // TODO: check for memory leaks where instance isn't finalised because jmb
- // holds a reference to the window
- jmb = null;
+ this.setVisible(show);
}
- /**
- * state flag for PDB retrieval thread
- */
private boolean _started = false;
public void run()
{
_started = true;
- String pdbid = "";
- // todo - record which pdbids were successfuly imported.
- StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
+
try
{
- String[] curfiles = jmb.getPdbFile(); // files currently in viewer
- // TODO: replace with reference fetching/transfer code (validate PDBentry
- // as a DBRef?)
- jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
- for (int pi = 0; pi < jmb.pdbentry.length; pi++)
- {
- String file = jmb.pdbentry[pi].getFile();
- if (file == null)
- {
- // retrieve the pdb and store it locally
- AlignmentI pdbseq = null;
- pdbid = jmb.pdbentry[pi].getId();
- long hdl = pdbid.hashCode() - System.currentTimeMillis();
- if (progressBar != null)
- {
- progressBar.setProgressBar("Fetching PDB " + pdbid, hdl);
- }
- try
- {
- pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
- .getId());
- } catch (OutOfMemoryError oomerror)
- {
- new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
- } catch (Exception ex)
- {
- ex.printStackTrace();
- errormsgs.append("'" + pdbid + "'");
- }
- if (progressBar != null)
- {
- progressBar.setProgressBar("Finished.", hdl);
- }
- if (pdbseq != null)
- {
- // just transfer the file name from the first sequence's first
- // PDBEntry
- jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq
- .getSequenceAt(0).getPDBId().elementAt(0)).getFile());
- files.append(" \"" + file + "\"");
- }
- else
- {
- errormsgs.append("'" + pdbid + "' ");
- }
- }
- else
- {
- if (curfiles != null && curfiles.length > 0)
- {
- addingStructures = true; // already files loaded.
- for (int c = 0; c < curfiles.length; c++)
- {
- if (curfiles[c].equals(file))
- {
- file = null;
- break;
- }
- }
- }
- if (file != null)
- {
- files.append(" \"" + file + "\"");
- }
- }
- }
+ initVarna();
} catch (OutOfMemoryError oomerror)
{
- new OOMWarning("Retrieving PDB files: " + pdbid, oomerror);
+ new OOMWarning("When trying to open the Varna viewer!", oomerror);
} catch (Exception ex)
{
- ex.printStackTrace();
- errormsgs.append("When retrieving pdbfiles : current was: '" + pdbid
- + "'");
+ Cache.log.error("Couldn't open Varna viewer!", ex);
}
- if (errormsgs.length() > 0)
- {
-
- JOptionPane.showInternalMessageDialog(Desktop.desktop,
- "The following pdb entries could not be retrieved from the PDB:\n"
- + errormsgs.toString()
- + "\nPlease try downloading them manually.",
- "Couldn't load file", JOptionPane.ERROR_MESSAGE);
-
- }
- if (files.length() > 0)
- {
- if (!addingStructures)
- {
-
- try
- {
- initJmol("load FILES " + files.toString());
- } catch (OutOfMemoryError oomerror)
- {
- new OOMWarning("When trying to open the Jmol viewer!", oomerror);
- Cache.log.debug("File locations are " + files);
- } catch (Exception ex)
- {
- Cache.log.error("Couldn't open Jmol viewer!", ex);
- }
- }
- else
- {
- StringBuffer cmd = new StringBuffer();
- cmd.append("loadingJalviewdata=true\nload APPEND ");
- cmd.append(files.toString());
- cmd.append("\nloadingJalviewdata=null");
- final String command = cmd.toString();
- cmd = null;
- long lastnotify = jmb.getLoadNotifiesHandled();
- try
- {
- jmb.evalStateCommand(command);
- } catch (OutOfMemoryError oomerror)
- {
- new OOMWarning(
- "When trying to add structures to the Jmol viewer!",
- oomerror);
- Cache.log.debug("File locations are " + files);
- } catch (Exception ex)
- {
- Cache.log.error("Couldn't add files to Jmol viewer!", ex);
- }
- // need to wait around until script has finished
- while (lastnotify >= jmb.getLoadNotifiesHandled())
- ;
- {
- try
- {
- Thread.sleep(35);
- } catch (Exception e)
- {
- }
- }
- // refresh the sequence colours for the new structure(s)
- for (AlignmentPanel ap : _colourwith)
- {
- jmb.updateColours(ap);
- }
- // do superposition if asked to
- if (alignAddedStructures)
- {
- javax.swing.SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- alignStructs_withAllAlignPanels();
- // jmb.superposeStructures(ap.av.getAlignment(), -1, null);
- }
- });
- alignAddedStructures = false;
- }
- addingStructures = false;
- }
- }
- _started = false;
- worker = null;
}
- public void pdbFile_actionPerformed(ActionEvent actionEvent)
+ @Override
+ public void onUINewStructure(VARNAConfig v, RNA r)
{
- JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
-
- chooser.setFileView(new JalviewFileView());
- chooser.setDialogTitle("Save PDB File");
- chooser.setToolTipText("Save");
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- try
- {
- // TODO: cope with multiple PDB files in view
- BufferedReader in = new BufferedReader(new FileReader(
- jmb.getPdbFile()[0]));
- File outFile = chooser.getSelectedFile();
-
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
- String data;
- while ((data = in.readLine()) != null)
- {
- if (!(data.indexOf("") > -1 || data.indexOf("
") > -1))
- {
- out.println(data);
- }
- }
- out.close();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- }
- public void viewMapping_actionPerformed(ActionEvent actionEvent)
- {
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- try
- {
- for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++)
- {
- cap.appendText(jmb.printMapping(
- jmb.pdbentry[pdbe].getFile()));
- cap.appendText("\n");
- }
- } catch (OutOfMemoryError e)
- {
- new OOMWarning(
- "composing sequence-structure alignments for display in text box.",
- e);
- cap.dispose();
- return;
- }
- jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
- 550, 600);
}
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- public void eps_actionPerformed(ActionEvent e)
+ @Override
+ public void onWarningEmitted(String s)
{
- makePDBImage(jalview.util.ImageMaker.EPS);
- }
+ // TODO Auto-generated method stub
- /**
- * DOCUMENT ME!
- *
- * @param e
- * DOCUMENT ME!
- */
- public void png_actionPerformed(ActionEvent e)
- {
- makePDBImage(jalview.util.ImageMaker.PNG);
}
- void makePDBImage(int type)
+ private class VarnaHighlighter
{
- int width = getWidth();
- int height = getHeight();
+ private HighlightRegionAnnotation _lastHighlight;
- jalview.util.ImageMaker im;
+ private RNA _lastRNAhighlighted = null;
- if (type == jalview.util.ImageMaker.PNG)
+ public void highlightRegion(RNA rna, int start, int end)
{
- im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.PNG,
- "Make PNG image from view", width, height, null, null);
- }
- else
- {
- im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS,
- "Make EPS file from view", width, height, null,
- this.getTitle());
- }
+ clearSelection(null);
+ HighlightRegionAnnotation highlight = new HighlightRegionAnnotation(
+ rna.getBasesBetween(start, end));
+ rna.addHighlightRegion(highlight);
+ _lastHighlight = highlight;
+ _lastRNAhighlighted = rna;
- if (im.getGraphics() != null)
- {
- Rectangle rect = new Rectangle(width, height);
- jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
- im.writeImage();
- }
- }
- public void jmolColour_actionPerformed(ActionEvent actionEvent)
- {
- if (jmolColour.isSelected()) {
- // disable automatic sequence colouring.
- jmb.setColourBySequence(false);
- }
- }
- public void seqColour_actionPerformed(ActionEvent actionEvent)
- {
- jmb.setColourBySequence(seqColour.isSelected());
- if (_colourwith == null)
- {
- _colourwith = new Vector();
}
- if (jmb.isColourBySequence())
- {
- if (!jmb.isLoadingFromArchive())
- {
- if (_colourwith.size()==0 && ap!=null) {
- // Make the currently displayed alignment panel the associated view
- _colourwith.add(ap.alignFrame.alignPanel);
- }
- }
- // Set the colour using the current view for the associated alignframe
- for (AlignmentPanel ap : _colourwith)
- {
- jmb.colourBySequence(ap.av.showSequenceFeatures, ap);
- }
- }
- }
-
- public void chainColour_actionPerformed(ActionEvent actionEvent)
- {
- chainColour.setSelected(true);
- jmb.colourByChain();
- }
-
- public void chargeColour_actionPerformed(ActionEvent actionEvent)
- {
- chargeColour.setSelected(true);
- jmb.colourByCharge();
- }
-
- public void zappoColour_actionPerformed(ActionEvent actionEvent)
- {
- zappoColour.setSelected(true);
- jmb.setJalviewColourScheme(new ZappoColourScheme());
- }
-
- public void taylorColour_actionPerformed(ActionEvent actionEvent)
- {
- taylorColour.setSelected(true);
- jmb.setJalviewColourScheme(new TaylorColourScheme());
- }
-
- public void hydroColour_actionPerformed(ActionEvent actionEvent)
- {
- hydroColour.setSelected(true);
- jmb.setJalviewColourScheme(new HydrophobicColourScheme());
- }
-
- public void helixColour_actionPerformed(ActionEvent actionEvent)
- {
- helixColour.setSelected(true);
- jmb.setJalviewColourScheme(new HelixColourScheme());
- }
-
- public void strandColour_actionPerformed(ActionEvent actionEvent)
- {
- strandColour.setSelected(true);
- jmb.setJalviewColourScheme(new StrandColourScheme());
- }
-
- public void turnColour_actionPerformed(ActionEvent actionEvent)
- {
- turnColour.setSelected(true);
- jmb.setJalviewColourScheme(new TurnColourScheme());
- }
- public void buriedColour_actionPerformed(ActionEvent actionEvent)
- {
- buriedColour.setSelected(true);
- jmb.setJalviewColourScheme(new BuriedColourScheme());
- }
-
- public void purinePyrimidineColour_actionPerformed(ActionEvent actionEvent)
- {
- setJalviewColourScheme(new PurinePyrimidineColourScheme());
- }
-
- public void userColour_actionPerformed(ActionEvent actionEvent)
- {
- userColour.setSelected(true);
- new UserDefinedColours(this, null);
- }
-
- public void backGround_actionPerformed(ActionEvent actionEvent)
- {
- java.awt.Color col = JColorChooser.showDialog(this,
- "Select Background Colour", null);
- if (col != null)
- {
- jmb.setBackgroundColour(col);
- }
- }
-
- public void jmolHelp_actionPerformed(ActionEvent actionEvent)
- {
- try
- {
- jalview.util.BrowserLauncher
- .openURL("http://jmol.sourceforge.net/docs/JmolUserGuide/");
- } catch (Exception ex)
+ public HighlightRegionAnnotation getLastHighlight()
{
+ return _lastHighlight;
}
- }
-
- public void showConsole(boolean showConsole)
- {
-
- if (showConsole)
- {
- if (splitPane == null)
- {
- splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
- splitPane.setTopComponent(renderPanel);
- splitPane.setBottomComponent(scriptWindow);
- this.getContentPane().add(splitPane, BorderLayout.CENTER);
- splitPane.setDividerLocation(getHeight() - 200);
- scriptWindow.setVisible(true);
- scriptWindow.validate();
- splitPane.validate();
- }
- }
- else
+ public RNA getLastRNA()
{
- if (splitPane != null)
- {
- splitPane.setVisible(false);
- }
-
- splitPane = null;
-
- this.getContentPane().add(renderPanel, BorderLayout.CENTER);
+ return _lastRNAhighlighted;
}
- validate();
- }
-
- class RenderPanel extends JPanel
- {
- final Dimension currentSize = new Dimension();
-
- final Rectangle rectClip = new Rectangle();
-
- public void paintComponent(Graphics g)
+ public void clearSelection(AppVarnaBinding vab)
{
- getSize(currentSize);
- g.getClipBounds(rectClip);
-
- if (jmb.fileLoadingError != null)
+ if (_lastRNAhighlighted != null)
{
- g.setColor(Color.black);
- g.fillRect(0, 0, currentSize.width, currentSize.height);
- g.setColor(Color.white);
- g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Error loading file...", 20, currentSize.height / 2);
- StringBuffer sb = new StringBuffer();
- int lines = 0;
- for (int e = 0; e < jmb.pdbentry.length; e++)
+ _lastRNAhighlighted.removeHighlightRegion(_lastHighlight);
+ if (vab != null)
{
- sb.append(jmb.pdbentry[e].getId());
- if (e < jmb.pdbentry.length - 1)
- {
- sb.append(",");
- }
-
- if (e == jmb.pdbentry.length - 1 || sb.length() > 20)
- {
- lines++;
- g.drawString(sb.toString(), 20, currentSize.height / 2 - lines
- * g.getFontMetrics().getHeight());
- }
+ vab.updateSelectedRNA(_lastRNAhighlighted);
}
- }
- else if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
- {
- g.setColor(Color.black);
- g.fillRect(0, 0, currentSize.width, currentSize.height);
- g.setColor(Color.white);
- g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
- }
- else
- {
- jmb.viewer.renderScreenImage(g, currentSize, rectClip);
+ _lastRNAhighlighted = null;
+ _lastHighlight = null;
+
}
}
}
- String viewId = null;
+ VarnaHighlighter mouseOverHighlighter = new VarnaHighlighter(),
+ selectionHighlighter = new VarnaHighlighter();
- public String getViewId()
+ /**
+ * If a mouseOver event from the AlignmentPanel is noticed the currently
+ * selected RNA in the VARNA window is highlighted at the specific position.
+ * To be able to remove it before the next highlight it is saved in
+ * _lastHighlight
+ */
+ @Override
+ public void mouseOverSequence(SequenceI sequence, int index)
{
- if (viewId == null)
+ RNA rna = vab.getSelectedRNA();
+ if (seqs.get(rna) == sequence)
{
- viewId = System.currentTimeMillis() + "." + this.hashCode();
+ 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);
}
- return viewId;
}
- public void updateTitleAndMenus()
+ @Override
+ public void onStructureRedrawn()
{
- if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
- {
- repaint();
- return;
- }
- setChainMenuItems(jmb.chainNames);
+ // TODO Auto-generated method stub
- this.setTitle(jmb.getViewerTitle());
- if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1)
- {
- jmolActionMenu.setVisible(true);
- }
- if (!jmb.isLoadingFromArchive())
- {
- seqColour_actionPerformed(null);
- }
}
- protected void buildJmolActionMenu()
+ @Override
+ public void selection(SequenceGroup seqsel, ColumnSelection colsel,
+ SelectionSource source)
{
- if (_alignwith == null)
- {
- _alignwith = new Vector();
- }
- if (_alignwith.size() == 0 && ap != null)
+ if (source != ap.av)
{
- _alignwith.add(ap);
+ // ignore events from anything but our parent alignpanel
+ // TODO - reuse many-one panel-view system in jmol viewer
+ return;
}
- ;
- for (Component c : jmolActionMenu.getMenuComponents())
+ if (seqsel != null && seqsel.getSize() > 0)
{
- if (c != alignStructs)
+ int start = seqsel.getStartRes(), end = seqsel.getEndRes();
+ RNA rna = vab.getSelectedRNA();
+ ShiftList shift = offsets.get(rna);
+ if (shift != null)
{
- jmolActionMenu.remove((JMenuItem) c);
+ start = shift.shift(start);
+ end = shift.shift(end);
}
+ selectionHighlighter.highlightRegion(rna, start, end);
+ selectionHighlighter.getLastHighlight().setOutlineColor(
+ seqsel.getOutlineColour());
+ // TODO - translate column markings to positions on structure if present.
+ vab.updateSelectedRNA(rna);
+ }
+ else
+ {
+ selectionHighlighter.clearSelection(vab);
}
- final ItemListener handler;
}
- /*
- * (non-Javadoc)
- *
- * @see
- * jalview.jbgui.GStructureViewer#alignStructs_actionPerformed(java.awt.event
- * .ActionEvent)
- */
@Override
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
+ public void onHoverChanged(ModeleBase arg0, ModeleBase arg1)
{
- alignStructs_withAllAlignPanels();
- }
-
- private void alignStructs_withAllAlignPanels()
- {
- if (ap == null)
- {
- return;
- }
- ;
- if (_alignwith.size() == 0)
+ RNA rna = vab.getSelectedRNA();
+ ShiftList shift = offsetsInv.get(rna);
+ SequenceI seq = seqs.get(rna);
+ if (arg1 != null && seq != null)
{
- _alignwith.add(ap);
- }
- ;
- try
- {
- AlignmentI[] als = new Alignment[_alignwith.size()];
- ColumnSelection[] alc = new ColumnSelection[_alignwith.size()];
- int[] alm = new int[_alignwith.size()];
- int a = 0;
-
- for (AlignmentPanel ap : _alignwith)
+ if (shift != null)
{
- als[a] = ap.av.getAlignment();
- alm[a] = -1;
- alc[a++] = ap.av.getColumnSelection();
+ int i = shift.shift(arg1.getIndex());
+ // System.err.println("shifted "+(arg1.getIndex())+" to "+i);
+ ssm.mouseOverVamsasSequence(seq, i, this);
}
- jmb.superposeStructures(als, alm, alc);
- } catch (Exception e)
- {
- StringBuffer sp = new StringBuffer();
- for (AlignmentPanel ap : _alignwith)
+ else
{
- sp.append("'" + ap.alignFrame.getTitle() + "' ");
+ ssm.mouseOverVamsasSequence(seq, arg1.getIndex(), this);
}
- Cache.log.info("Couldn't align structures with the " + sp.toString()
- + "associated alignment panels.", e);
-
}
-
}
- public void setJalviewColourScheme(ColourSchemeI ucs)
+ @Override
+ public void onSelectionChanged(BaseList arg0, BaseList arg1, BaseList arg2)
{
- jmb.setJalviewColourScheme(ucs);
+ // TODO translate selected regions in VARNA to a selection on the
+ // alignpanel.
}
- /**
- *
- * @param alignment
- * @return first alignment panel displaying given alignment, or the default
- * alignment panel
- */
- public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment)
+ @Override
+ public void onTranslationChanged()
{
- for (AlignmentPanel ap : getAllAlignmentPanels())
- {
- if (ap.av.getAlignment() == alignment)
- {
- return ap;
- }
- }
- return ap;
- }
+ // TODO Auto-generated method stub
- /**
- *
- * @param ap2
- * @return true if this Jmol instance is linked with the given alignPanel
- */
- public boolean isLinkedWith(AlignmentPanel ap2)
- {
- return _aps.contains(ap2.av.getSequenceSetId());
}
- public boolean isUsedforaligment(AlignmentPanel ap2)
+ @Override
+ public void onZoomLevelChanged()
{
+ // TODO Auto-generated method stub
- return (_alignwith != null) && _alignwith.contains(ap2);
- }
-
- public boolean isUsedforcolourby(AlignmentPanel ap2)
- {
- return (_colourwith != null) && _colourwith.contains(ap2);
}
- /**
- *
- * @return TRUE if the view is NOT being coloured by sequence associations.
- */
- public boolean isColouredByJmol()
- {
- return !jmb.isColourBySequence();
- }
-
-
}