From: jprocter Date: Fri, 9 Dec 2005 16:02:40 +0000 (+0000) Subject: fixed pdbentry creation and multiple uniprot or pdb entry retrieval. X-Git-Tag: Release_2_07~15 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2a22b216be40ead9c5a44c0d5e94ce90ccd92d03;p=jalview.git fixed pdbentry creation and multiple uniprot or pdb entry retrieval. --- diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 50a4a36..f0b37df 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -1,558 +1,575 @@ -/* - * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle - * - * This program 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ -package MCview; - -import javax.swing.*; -import java.awt.event.*; -import jalview.datamodel.*; -import jalview.schemes.*; -import jalview.gui.*; -import jalview.io.EBIFetchClient; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; - -public class PDBViewer extends JInternalFrame implements Runnable -{ - PDBEntry pdb; - Sequence sequence; - PDBCanvas pdbcanvas; - - - public PDBViewer(PDBEntry entry, - Sequence seq, - SeqCanvas seqcanvas) - { - /*Uncomment this to modify in Jbuilder - try - { - jbInit(); - } - catch (Exception ex) - { - ex.printStackTrace(); - }*/ - - - pdb = entry; - sequence = seq; - - Thread worker = new Thread(this); - worker.start(); - - pdbcanvas = new PDBCanvas(seqcanvas, seq); - - setContentPane(pdbcanvas); - StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId()); - if(pdb.getProperty()!=null) - { - title.append( " Method: " ); - title.append(pdb.getProperty().get("method")); - title.append( " Chain:" ); - title.append( pdb.getProperty().get("chains")); - } - - Desktop.addInternalFrame(this,title.toString(),400, 400); - } - - public void run() - { - try - { - EBIFetchClient ebi = new EBIFetchClient(); - String[] result = ebi.fetchData("pdb:" + pdb.getId(), "default","raw"); - - PDBfile pdbfile = new PDBfile(result); - - pdbcanvas.setPDBFile(pdbfile); - - try - { - jbInit(); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - private void jbInit() - throws Exception - { - this.addKeyListener(new KeyAdapter() - { - public void keyPressed(KeyEvent evt) - { - pdbcanvas.keyPressed(evt); - } - }); - - this.setJMenuBar(jMenuBar1); - fileMenu.setText("File"); - coloursMenu.setText("Colours"); - saveMenu.setActionCommand("Save Image"); - saveMenu.setText("Save As"); - png.setText("PNG"); - png.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - png_actionPerformed(e); - } - }); - eps.setText("EPS"); - eps.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - eps_actionPerformed(e); - } - }); - mapping.setText("View Mapping"); - mapping.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - mapping_actionPerformed(e); - } - }); - wire.setText("Wireframe"); - wire.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - wire_actionPerformed(e); - } - }); - depth.setSelected(true); - depth.setText("Depthcue"); - depth.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - depth_actionPerformed(e); - } - }); - zbuffer.setSelected(true); - zbuffer.setText("Z Buffering"); - zbuffer.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - zbuffer_actionPerformed(e); - } - }); - charge.setText("Charge & Cysteine"); - charge.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - charge_actionPerformed(e); - } - }); - chain.setText("By Chain"); - chain.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - chain_actionPerformed(e); - } - }); - seqButton.setSelected(true); - seqButton.setText("By Sequence"); - seqButton.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - seqButton_actionPerformed(e); - } - }); - allchains.setSelected(true); - allchains.setText("Show All Chains"); - allchains.addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - allchains_itemStateChanged(e); - } - }); - zappo.setText("Zappo"); - zappo.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - zappo_actionPerformed(e); - } - }); - taylor.setText("Taylor"); - taylor.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - taylor_actionPerformed(e); - } - }); - hydro.setText("Hydro"); - hydro.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - hydro_actionPerformed(e); - } - }); - helix.setText("Helix"); - helix.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - helix_actionPerformed(e); - } - }); - strand.setText("Strand"); - strand.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - strand_actionPerformed(e); - } - }); - turn.setText("Turn"); - turn.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - turn_actionPerformed(e); - } - }); - buried.setText("Buried"); - buried.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - buried_actionPerformed(e); - } - }); - user.setText("User Defined..."); - user.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - user_actionPerformed(e); - } - }); - viewMenu.setText("View"); - jMenuBar1.add(fileMenu); - jMenuBar1.add(coloursMenu); - jMenuBar1.add(viewMenu); - fileMenu.add(saveMenu); - fileMenu.add(mapping); - saveMenu.add(png); - saveMenu.add(eps); - coloursMenu.add(seqButton); - coloursMenu.add(chain); - coloursMenu.add(charge); - coloursMenu.add(zappo); - coloursMenu.add(taylor); - coloursMenu.add(hydro); - coloursMenu.add(helix); - coloursMenu.add(strand); - coloursMenu.add(turn); - coloursMenu.add(buried); - coloursMenu.add(user); - ButtonGroup bg = new ButtonGroup(); - bg.add(seqButton); - bg.add(chain); - bg.add(charge); - bg.add(zappo); - bg.add(taylor); - bg.add(hydro); - bg.add(helix); - bg.add(strand); - bg.add(turn); - bg.add(buried); - bg.add(user); - - - if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null) - { - java.util.Enumeration userColours = jalview.gui.UserDefinedColours. - getUserColourSchemes().keys(); - - while (userColours.hasMoreElements()) - { - final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours. - nextElement().toString()); - radioItem.setName("USER_DEFINED"); - radioItem.addMouseListener(new MouseAdapter() - { - public void mousePressed(MouseEvent evt) - { - if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt)) - { - radioItem.removeActionListener(radioItem.getActionListeners()[0]); - - int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop, - "Remove from default list?", - "Remove user defined colour", - JOptionPane.YES_NO_OPTION); - if(option == JOptionPane.YES_OPTION) - { - jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText()); - coloursMenu.remove(radioItem); - } - else - radioItem.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - user_actionPerformed(evt); - } - }); - } - } - }); - radioItem.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent evt) - { - user_actionPerformed(evt); - } - }); - coloursMenu.add(radioItem); - bg.add(radioItem); - } - } - - viewMenu.add(wire); - viewMenu.add(depth); - viewMenu.add(zbuffer); - viewMenu.add(allchains); - } - - JMenuBar jMenuBar1 = new JMenuBar(); - JMenu fileMenu = new JMenu(); - JMenu coloursMenu = new JMenu(); - JMenu saveMenu = new JMenu(); - JMenuItem png = new JMenuItem(); - JMenuItem eps = new JMenuItem(); - JMenuItem mapping = new JMenuItem(); - JCheckBoxMenuItem wire = new JCheckBoxMenuItem(); - JCheckBoxMenuItem depth = new JCheckBoxMenuItem(); - JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem(); - JCheckBoxMenuItem allchains = new JCheckBoxMenuItem(); - - JRadioButtonMenuItem charge = new JRadioButtonMenuItem(); - JRadioButtonMenuItem chain = new JRadioButtonMenuItem(); - JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem(); - JRadioButtonMenuItem hydro = new JRadioButtonMenuItem(); - JRadioButtonMenuItem taylor = new JRadioButtonMenuItem(); - JRadioButtonMenuItem zappo = new JRadioButtonMenuItem(); - JRadioButtonMenuItem user = new JRadioButtonMenuItem(); - JRadioButtonMenuItem buried = new JRadioButtonMenuItem(); - JRadioButtonMenuItem turn = new JRadioButtonMenuItem(); - JRadioButtonMenuItem strand = new JRadioButtonMenuItem(); - JRadioButtonMenuItem helix = new JRadioButtonMenuItem(); - JMenu viewMenu = new JMenu(); - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void eps_actionPerformed(ActionEvent e) - { - makePDBImage(jalview.util.ImageMaker.EPS); - } - - /** - * DOCUMENT ME! - * - * @param e DOCUMENT ME! - */ - public void png_actionPerformed(ActionEvent e) - { - makePDBImage(jalview.util.ImageMaker.PNG); - } - - void makePDBImage(int type) - { - int width = pdbcanvas.getWidth(); - int height = pdbcanvas.getHeight(); - - jalview.util.ImageMaker im; - - if (type == jalview.util.ImageMaker.PNG) - 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()); - - if (im.getGraphics() != null) - { - pdbcanvas.drawAll(im.getGraphics(), width, height); - im.writeImage(); - } - } - public void charge_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setChargeColours(); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void hydro_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setColours(new HydrophobicColourScheme()); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void chain_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setChainColours(); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void zbuffer_actionPerformed(ActionEvent e) - { - pdbcanvas.zbuffer = ! pdbcanvas.zbuffer; - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void molecule_actionPerformed(ActionEvent e) - { - pdbcanvas.bymolecule = ! pdbcanvas.bymolecule; - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void depth_actionPerformed(ActionEvent e) - { - pdbcanvas.depthcue = ! pdbcanvas.depthcue; - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void wire_actionPerformed(ActionEvent e) - { - pdbcanvas.wire = ! pdbcanvas.wire; - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void seqButton_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = true; - pdbcanvas.updateSeqColours(); - } - - - public void mapping_actionPerformed(ActionEvent e) - { - jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); - Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600); - cap.setText(pdbcanvas.mappingDetails.toString()); - } - - public void allchains_itemStateChanged(ItemEvent e) - { - pdbcanvas.setAllchainsVisible(allchains.getState()); - } - - public void zappo_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setColours(new ZappoColourScheme()); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void taylor_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setColours(new TaylorColourScheme()); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void helix_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setColours(new HelixColourScheme()); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void strand_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setColours(new StrandColourScheme()); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void turn_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setColours(new TurnColourScheme()); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void buried_actionPerformed(ActionEvent e) - { - pdbcanvas.bysequence = false; - pdbcanvas.pdb.setColours(new BuriedColourScheme()); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - - public void user_actionPerformed(ActionEvent e) - { - if (e.getActionCommand().equals("User Defined...")) - { - new UserDefinedColours(pdbcanvas, null); - } - else - { - UserColourScheme udc = (UserColourScheme) UserDefinedColours. - getUserColourSchemes().get(e.getActionCommand()); - - pdbcanvas.pdb.setColours(udc); - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - } -} +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program 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 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ +package MCview; + +import javax.swing.*; +import java.awt.event.*; +import jalview.datamodel.*; +import jalview.schemes.*; +import jalview.gui.*; +import jalview.io.EBIFetchClient; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class PDBViewer extends JInternalFrame implements Runnable +{ + PDBEntry pdb; + Sequence sequence; + PDBCanvas pdbcanvas; + + + public PDBViewer(PDBEntry entry, + Sequence seq, + SeqCanvas seqcanvas) + { + /*Uncomment this to modify in Jbuilder + try + { + jbInit(); + } + catch (Exception ex) + { + ex.printStackTrace(); + }*/ + + if (entry==null) + return; + pdb = entry; + sequence = seq; + + Thread worker = new Thread(this); + worker.start(); + + pdbcanvas = new PDBCanvas(seqcanvas, seq); + + setContentPane(pdbcanvas); + StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId()); + if(pdb.getProperty()!=null) + { + if (pdb.getProperty().get("method")!=null) + { + title.append(" Method: "); + title.append(pdb.getProperty().get("method")); + } + if (pdb.getProperty().get("chains") != null) + { + title.append(" Chain:"); + title.append(pdb.getProperty().get("chains")); + } + } + Desktop.addInternalFrame(this,title.toString(),400, 400); + } + + public void run() + { + try + { + EBIFetchClient ebi = new EBIFetchClient(); + String query = "pdb:" + pdb.getId(); + String[] result = ebi.fetchData(query, "default","raw"); + if (result!=null) { + PDBfile pdbfile = new PDBfile(result); + pdbcanvas.setPDBFile(pdbfile); + } else { + throw new Exception("Empty result for WSDbFetch Query: "+query); + } + + try + { + jbInit(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + catch (Exception ex) + { + ex.printStackTrace(); + showErrorMessage("Failed to retrieve PDB structure."); +// this.dispose(); + } + } + + private void jbInit() + throws Exception + { + this.addKeyListener(new KeyAdapter() + { + public void keyPressed(KeyEvent evt) + { + pdbcanvas.keyPressed(evt); + } + }); + + this.setJMenuBar(jMenuBar1); + fileMenu.setText("File"); + coloursMenu.setText("Colours"); + saveMenu.setActionCommand("Save Image"); + saveMenu.setText("Save As"); + png.setText("PNG"); + png.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + png_actionPerformed(e); + } + }); + eps.setText("EPS"); + eps.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + eps_actionPerformed(e); + } + }); + mapping.setText("View Mapping"); + mapping.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + mapping_actionPerformed(e); + } + }); + wire.setText("Wireframe"); + wire.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + wire_actionPerformed(e); + } + }); + depth.setSelected(true); + depth.setText("Depthcue"); + depth.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + depth_actionPerformed(e); + } + }); + zbuffer.setSelected(true); + zbuffer.setText("Z Buffering"); + zbuffer.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + zbuffer_actionPerformed(e); + } + }); + charge.setText("Charge & Cysteine"); + charge.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + charge_actionPerformed(e); + } + }); + chain.setText("By Chain"); + chain.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + chain_actionPerformed(e); + } + }); + seqButton.setSelected(true); + seqButton.setText("By Sequence"); + seqButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + seqButton_actionPerformed(e); + } + }); + allchains.setSelected(true); + allchains.setText("Show All Chains"); + allchains.addItemListener(new ItemListener() + { + public void itemStateChanged(ItemEvent e) + { + allchains_itemStateChanged(e); + } + }); + zappo.setText("Zappo"); + zappo.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + zappo_actionPerformed(e); + } + }); + taylor.setText("Taylor"); + taylor.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + taylor_actionPerformed(e); + } + }); + hydro.setText("Hydro"); + hydro.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + hydro_actionPerformed(e); + } + }); + helix.setText("Helix"); + helix.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + helix_actionPerformed(e); + } + }); + strand.setText("Strand"); + strand.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + strand_actionPerformed(e); + } + }); + turn.setText("Turn"); + turn.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + turn_actionPerformed(e); + } + }); + buried.setText("Buried"); + buried.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + buried_actionPerformed(e); + } + }); + user.setText("User Defined..."); + user.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + user_actionPerformed(e); + } + }); + viewMenu.setText("View"); + jMenuBar1.add(fileMenu); + jMenuBar1.add(coloursMenu); + jMenuBar1.add(viewMenu); + fileMenu.add(saveMenu); + fileMenu.add(mapping); + saveMenu.add(png); + saveMenu.add(eps); + coloursMenu.add(seqButton); + coloursMenu.add(chain); + coloursMenu.add(charge); + coloursMenu.add(zappo); + coloursMenu.add(taylor); + coloursMenu.add(hydro); + coloursMenu.add(helix); + coloursMenu.add(strand); + coloursMenu.add(turn); + coloursMenu.add(buried); + coloursMenu.add(user); + ButtonGroup bg = new ButtonGroup(); + bg.add(seqButton); + bg.add(chain); + bg.add(charge); + bg.add(zappo); + bg.add(taylor); + bg.add(hydro); + bg.add(helix); + bg.add(strand); + bg.add(turn); + bg.add(buried); + bg.add(user); + + + if(jalview.gui.UserDefinedColours.getUserColourSchemes()!=null) + { + java.util.Enumeration userColours = jalview.gui.UserDefinedColours. + getUserColourSchemes().keys(); + + while (userColours.hasMoreElements()) + { + final JRadioButtonMenuItem radioItem = new JRadioButtonMenuItem(userColours. + nextElement().toString()); + radioItem.setName("USER_DEFINED"); + radioItem.addMouseListener(new MouseAdapter() + { + public void mousePressed(MouseEvent evt) + { + if(evt.isControlDown() || SwingUtilities.isRightMouseButton(evt)) + { + radioItem.removeActionListener(radioItem.getActionListeners()[0]); + + int option = JOptionPane.showInternalConfirmDialog(jalview.gui.Desktop.desktop, + "Remove from default list?", + "Remove user defined colour", + JOptionPane.YES_NO_OPTION); + if(option == JOptionPane.YES_OPTION) + { + jalview.gui.UserDefinedColours.removeColourFromDefaults(radioItem.getText()); + coloursMenu.remove(radioItem); + } + else + radioItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + user_actionPerformed(evt); + } + }); + } + } + }); + radioItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent evt) + { + user_actionPerformed(evt); + } + }); + coloursMenu.add(radioItem); + bg.add(radioItem); + } + } + + viewMenu.add(wire); + viewMenu.add(depth); + viewMenu.add(zbuffer); + viewMenu.add(allchains); + } + + JMenuBar jMenuBar1 = new JMenuBar(); + JMenu fileMenu = new JMenu(); + JMenu coloursMenu = new JMenu(); + JMenu saveMenu = new JMenu(); + JMenuItem png = new JMenuItem(); + JMenuItem eps = new JMenuItem(); + JMenuItem mapping = new JMenuItem(); + JCheckBoxMenuItem wire = new JCheckBoxMenuItem(); + JCheckBoxMenuItem depth = new JCheckBoxMenuItem(); + JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem(); + JCheckBoxMenuItem allchains = new JCheckBoxMenuItem(); + + JRadioButtonMenuItem charge = new JRadioButtonMenuItem(); + JRadioButtonMenuItem chain = new JRadioButtonMenuItem(); + JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem(); + JRadioButtonMenuItem hydro = new JRadioButtonMenuItem(); + JRadioButtonMenuItem taylor = new JRadioButtonMenuItem(); + JRadioButtonMenuItem zappo = new JRadioButtonMenuItem(); + JRadioButtonMenuItem user = new JRadioButtonMenuItem(); + JRadioButtonMenuItem buried = new JRadioButtonMenuItem(); + JRadioButtonMenuItem turn = new JRadioButtonMenuItem(); + JRadioButtonMenuItem strand = new JRadioButtonMenuItem(); + JRadioButtonMenuItem helix = new JRadioButtonMenuItem(); + JMenu viewMenu = new JMenu(); + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void eps_actionPerformed(ActionEvent e) + { + makePDBImage(jalview.util.ImageMaker.EPS); + } + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void png_actionPerformed(ActionEvent e) + { + makePDBImage(jalview.util.ImageMaker.PNG); + } + + void makePDBImage(int type) + { + int width = pdbcanvas.getWidth(); + int height = pdbcanvas.getHeight(); + + jalview.util.ImageMaker im; + + if (type == jalview.util.ImageMaker.PNG) + 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()); + + if (im.getGraphics() != null) + { + pdbcanvas.drawAll(im.getGraphics(), width, height); + im.writeImage(); + } + } + public void charge_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setChargeColours(); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void hydro_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new HydrophobicColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void chain_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setChainColours(); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void zbuffer_actionPerformed(ActionEvent e) + { + pdbcanvas.zbuffer = ! pdbcanvas.zbuffer; + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void molecule_actionPerformed(ActionEvent e) + { + pdbcanvas.bymolecule = ! pdbcanvas.bymolecule; + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void depth_actionPerformed(ActionEvent e) + { + pdbcanvas.depthcue = ! pdbcanvas.depthcue; + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void wire_actionPerformed(ActionEvent e) + { + pdbcanvas.wire = ! pdbcanvas.wire; + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void seqButton_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = true; + pdbcanvas.updateSeqColours(); + } + + + public void mapping_actionPerformed(ActionEvent e) + { + jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); + Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600); + cap.setText(pdbcanvas.mappingDetails.toString()); + } + + public void allchains_itemStateChanged(ItemEvent e) + { + pdbcanvas.setAllchainsVisible(allchains.getState()); + } + void showErrorMessage(String error) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + error, "PDB Viewer Error", JOptionPane.WARNING_MESSAGE); + } + + + public void zappo_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new ZappoColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void taylor_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new TaylorColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void helix_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new HelixColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void strand_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new StrandColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void turn_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new TurnColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void buried_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = false; + pdbcanvas.pdb.setColours(new BuriedColourScheme()); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void user_actionPerformed(ActionEvent e) + { + if (e.getActionCommand().equals("User Defined...")) + { + new UserDefinedColours(pdbcanvas, null); + } + else + { + UserColourScheme udc = (UserColourScheme) UserDefinedColours. + getUserColourSchemes().get(e.getActionCommand()); + + pdbcanvas.pdb.setColours(udc); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + } +} diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index aa494f5..b3ccf5e 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -29,7 +29,6 @@ import java.io.File; import jalview.io.*; import java.util.*; - public class SequenceFetcher extends JPanel implements Runnable { @@ -57,12 +56,16 @@ public class SequenceFetcher frame = new JInternalFrame(); frame.setContentPane(this); - if(System.getProperty("os.name").startsWith("Mac")) - Desktop.addInternalFrame(frame, ((af==null) ? - "New " : "Additional ")+"Sequence Fetcher (WSDBfetch@EBI)", 400, 140); + if (System.getProperty("os.name").startsWith("Mac")) + Desktop.addInternalFrame(frame, getFrameTitle(), 400, 140); else - Desktop.addInternalFrame(frame, ((af==null) ? - "New " : "Additional ")+"Sequence Fetcher (WSDBfetch@EBI)", 400, 125); + Desktop.addInternalFrame(frame, getFrameTitle(), 400, 125); + } + + private String getFrameTitle() + { + return ( (alignFrame == null) ? "New " : "Additional ") + + "Sequence Fetcher (WSDBfetch@EBI)"; } private void jbInit() @@ -149,12 +152,13 @@ public class SequenceFetcher worker.start(); } - private void resetDialog() { + private void resetDialog() + { database.setEnabled(true); textfield.setEnabled(true); ok.setEnabled(true); cancel.setEnabled(true); - frame.setTitle("Sequence Fetcher (WSDBfetch@EBI)"); + frame.setTitle(getFrameTitle()); } public void run() @@ -162,23 +166,24 @@ public class SequenceFetcher String error = ""; if (database.getSelectedItem().equals(noDbSelected)) error += "Please select the source database\n"; - com.stevesoft.pat.Regex empty=new com.stevesoft.pat.Regex("\\s+",""); + com.stevesoft.pat.Regex empty = new com.stevesoft.pat.Regex("\\s+", ""); textfield.setText(empty.replaceAll(textfield.getText())); - if (textfield.getText().length()==0) - error+="Please enter a (semi-colon separated list of) database id(s)"; - if (error.length()>0) { + if (textfield.getText().length() == 0) + error += "Please enter a (semi-colon separated list of) database id(s)"; + if (error.length() > 0) + { showErrorMessage(error); resetDialog(); return; } - result = new StringBuffer(); + result = new StringBuffer(); if (database.getSelectedItem().equals("Uniprot")) { getUniprotFile(textfield.getText()); } else if (database.getSelectedItem().equals("EMBL") - || database.getSelectedItem().equals("EMBLCDS")) + || database.getSelectedItem().equals("EMBLCDS")) { EBIFetchClient dbFetch = new EBIFetchClient(); String[] reply = dbFetch.fetchData( @@ -193,12 +198,19 @@ public class SequenceFetcher } else if (database.getSelectedItem().equals("PDB")) { - result = getPDBFile(textfield.getText().toUpperCase()); - if (result!=null) + StringTokenizer qset = new StringTokenizer(textfield.getText(), ";"); + String query; + while (qset.hasMoreTokens() && ((query = qset.nextToken())!=null)) + { + StringBuffer respart = getPDBFile(query.toUpperCase()); + result.append(respart); + + } + + if (result != null) parseResult(result.toString()); } - if (result == null || result.length() == 0) showErrorMessage("Error retrieving " + textfield.getText() + " from " + database.getSelectedItem()); @@ -210,41 +222,42 @@ public class SequenceFetcher void getUniprotFile(String id) { EBIFetchClient ebi = new EBIFetchClient(); - File file = ebi.fetchDataAsFile("uniprot:"+id,"xml", null); + File file = ebi.fetchDataAsFile("uniprot:" + id, "xml", null); SequenceFeatureFetcher sff = new SequenceFeatureFetcher(); Vector entries = sff.getUniprotEntries(file); - if(entries!=null) + if (entries != null) { //First, make the new sequences Enumeration en = entries.elements(); while (en.hasMoreElements()) { UniprotEntry entry = (UniprotEntry) en.nextElement(); - StringBuffer name = new StringBuffer( ">Uniprot/Swiss-Prot" ); + StringBuffer name = new StringBuffer(">Uniprot/Swiss-Prot"); Enumeration en2 = entry.getAccession().elements(); - while(en2.hasMoreElements()) + while (en2.hasMoreElements()) { name.append("|"); name.append(en2.nextElement()); } en2 = entry.getName().elements(); - while(en2.hasMoreElements()) + while (en2.hasMoreElements()) { name.append("|"); name.append(en2.nextElement()); } - if(entry.getProteinName()!=null) - name.append(" "+entry.getProteinName().elementAt(0)); + if (entry.getProteinName() != null) + name.append(" " + entry.getProteinName().elementAt(0)); - result.append(name +"\n"+entry.getUniprotSequence().getContent()); + result.append(name + "\n" + entry.getUniprotSequence().getContent() + + "\n"); } //Then read in the features and apply them to the dataset - SequenceI [] sequence = parseResult(result.toString()); - for(int i=0; i -1) { - StringBuffer result = new StringBuffer(); - String chain = null; - if (id.indexOf(":") > -1) - { - chain = id.substring(id.indexOf(":") + 1); - id = id.substring(0, id.indexOf(":")); - } + chain = id.substring(id.indexOf(":") + 1); + id = id.substring(0, id.indexOf(":")); + } - EBIFetchClient ebi = new EBIFetchClient(); - String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw"); - if (reply==null) - return null; - try - { - PDBfile pdbfile = new PDBfile(reply); - for (int i = 0; i < pdbfile.chains.size(); i++) - { - if (chain == null || - ( (PDBChain) pdbfile.chains.elementAt(i)).id. - toUpperCase().equals(chain)) - result.append("\n>PDB|" + id + "|" + - ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. - getName() + - "\n" - + - ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. - getSequence()); - } - } - catch (Exception ex) // Problem parsing PDB file + EBIFetchClient ebi = new EBIFetchClient(); + String[] reply = ebi.fetchData("pdb:" + id, "pdb", "raw"); + if (reply == null) + return null; + try + { + PDBfile pdbfile = new PDBfile(reply); + for (int i = 0; i < pdbfile.chains.size(); i++) { - jalview.bin.Cache.log.warn("Exception when retrieving " + textfield.getText() + " from " + - database.getSelectedItem(), ex); - return null; + if (chain == null || + ( (PDBChain) pdbfile.chains.elementAt(i)).id. + toUpperCase().equals(chain)) + result.append("\n>PDB|" + id + "|" + + ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. + getName() + + "\n" + + + ( (PDBChain) pdbfile.chains.elementAt(i)).sequence. + getSequence()); } - - return result; } - - SequenceI[] parseResult(String result) + catch (Exception ex) // Problem parsing PDB file { - String format = IdentifyFile.Identify(result, "Paste"); - SequenceI[] sequences = null; + jalview.bin.Cache.log.warn("Exception when retrieving " + + textfield.getText() + " from " + + database.getSelectedItem(), ex); + return null; + } - if (FormatAdapter.formats.contains(format)) + return result; + } + + SequenceI[] parseResult(String result) + { + String format = IdentifyFile.Identify(result, "Paste"); + SequenceI[] sequences = null; + + if (FormatAdapter.formats.contains(format)) + { + sequences = new FormatAdapter().readFile(result.toString(), "Paste", + format); + if (sequences != null && sequences.length > 0) { - sequences = new FormatAdapter().readFile(result.toString(), "Paste", format); - if (sequences != null && sequences.length>0) + if (alignFrame == null) { - if(alignFrame==null) + AlignFrame af = new AlignFrame(new Alignment(sequences)); + af.currentFileFormat = format; + Desktop.addInternalFrame(af, + "Retrieved from " + database.getSelectedItem(), + AlignFrame.NEW_WINDOW_WIDTH, + AlignFrame.NEW_WINDOW_HEIGHT); + af.statusBar.setText("Successfully pasted alignment file"); + try { - AlignFrame af = new AlignFrame(new Alignment(sequences)); - af.currentFileFormat = format; - Desktop.addInternalFrame(af, "Retrieved from "+database.getSelectedItem(), - AlignFrame.NEW_WINDOW_WIDTH, - AlignFrame.NEW_WINDOW_HEIGHT); - af.statusBar.setText("Successfully pasted alignment file"); - try - { - af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); - } - catch (Exception ex) - {} + af.setMaximum(jalview.bin.Cache.getDefault("SHOW_FULLSCREEN", false)); } - else + catch (Exception ex) + {} + } + else + { + for (int i = 0; i < sequences.length; i++) { - for (int i = 0; i < sequences.length; i++) - { - alignFrame.viewport.alignment.addSequence(sequences[i]); - - //////////////////////////// - //Datset needs extension; - ///////////////////////////// - Sequence ds = new Sequence(sequences[i].getName(), - AlignSeq.extractGaps("-. ", - sequences[i].getSequence()), - sequences[i].getStart(), - sequences[i].getEnd()); - sequences[i].setDatasetSequence(ds); - alignFrame.viewport.alignment.getDataset().addSequence(ds); - } - alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment. - getHeight()); - alignFrame.viewport.alignment.getWidth(); - alignFrame.viewport.firePropertyChange("alignment", null, - alignFrame.viewport.getAlignment().getSequences()); - + alignFrame.viewport.alignment.addSequence(sequences[i]); + + //////////////////////////// + //Datset needs extension; + ///////////////////////////// + Sequence ds = new Sequence(sequences[i].getName(), + AlignSeq.extractGaps("-. ", + sequences[i].getSequence()), + sequences[i].getStart(), + sequences[i].getEnd()); + sequences[i].setDatasetSequence(ds); + alignFrame.viewport.alignment.getDataset().addSequence(ds); } + alignFrame.viewport.setEndSeq(alignFrame.viewport.alignment. + getHeight()); + alignFrame.viewport.alignment.getWidth(); + alignFrame.viewport.firePropertyChange("alignment", null, + alignFrame.viewport. + getAlignment().getSequences()); - if (database.getSelectedItem().equals("PDB")) + } + + if (database.getSelectedItem().equals("PDB")) + { + // Parse out the ids from the structured names + boolean errors = false; + for (int i = 0; i < sequences.length; i++) { - for (int i = 0; i < sequences.length; i++) + PDBEntry entry = new PDBEntry(); + com.stevesoft.pat.Regex idbits = new com.stevesoft.pat.Regex( + "PDB\\|([0-9A-z]{4})\\|(.)"); + if (idbits.search(sequences[i].getName())) { - PDBEntry entry = new PDBEntry(); - entry.setId(textfield.getText()); + String pdbid = idbits.substring(1); + String pdbccode = idbits.substring(2); + // Construct the PDBEntry + entry.setId(pdbid); + if (entry.getProperty() == null) + entry.setProperty(new Hashtable()); + entry.getProperty().put("chains", + pdbccode + + "=" + sequences[i].getStart() + + "-" + sequences[i].getEnd()); sequences[i].getDatasetSequence().addPDBId(entry); } + else + { + // don't add an entry for this chain, but this is probably a bug + // that the user should know about. + jalview.bin.Cache.log.warn( + "No PDBEntry constructed for sequence " + i + " : " + + sequences[i].getName()); + errors = true; + } } - + if (errors) + jalview.bin.Cache.log.warn( + "Query string that resulted in PDBEntry construction failure was :\n" + + textfield.getText()); } - else - showErrorMessage( "Error retrieving "+textfield.getText() - +" from "+database.getSelectedItem()); + } + else + showErrorMessage("Error retrieving " + textfield.getText() + + " from " + database.getSelectedItem()); + } - return sequences; + return sequences; } void showErrorMessage(String error) { JOptionPane.showInternalMessageDialog(Desktop.desktop, - error, "Error Retrieving Data", JOptionPane.WARNING_MESSAGE); + error, "Error Retrieving Data", + JOptionPane.WARNING_MESSAGE); } } - - -