-/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
-*/\r
-package MCview;\r
-\r
-import jalview.analysis.AlignSeq;\r
-\r
-import jalview.datamodel.*;\r
-\r
-// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-import java.io.*;\r
-\r
-import java.util.*;\r
-\r
-\r
-\r
-public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener\r
-{\r
-\r
- MCMatrix idmat = new MCMatrix(3, 3);\r
- MCMatrix objmat = new MCMatrix(3, 3);\r
- boolean redrawneeded = true;\r
- int omx = 0;\r
- int mx = 0;\r
- int omy = 0;\r
- int my = 0;\r
- public PDBfile pdb;\r
- int bsize;\r
- Image img;\r
- Graphics ig;\r
- Dimension prefsize;\r
- float[] centre = new float[3];\r
- float[] width = new float[3];\r
- float maxwidth;\r
- float scale;\r
- String inStr;\r
- String inType;\r
- boolean bysequence = true;\r
- boolean depthcue = true;\r
- boolean wire = false;\r
- boolean bymolecule = false;\r
- boolean zbuffer = true;\r
- boolean dragging;\r
- int xstart;\r
- int xend;\r
- int ystart;\r
- int yend;\r
- int xmid;\r
- int ymid;\r
- Font font = new Font("Helvetica", Font.PLAIN, 10);\r
- jalview.appletgui.SeqCanvas seqcanvas;\r
- public Sequence sequence;\r
- final StringBuffer mappingDetails = new StringBuffer();\r
- String appletToolTip = null;\r
- int toolx, tooly;\r
- PDBChain mainchain;\r
- Vector highlightRes;\r
- boolean pdbAction = false;\r
- Bond highlightBond1, highlightBond2;\r
- boolean errorLoading = false;\r
- boolean seqColoursReady = false;\r
- jalview.appletgui.FeatureRenderer fr;\r
-\r
- public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq)\r
- {\r
- this.seqcanvas = seqcanvas;\r
- this.sequence = seq;\r
-\r
- seqcanvas.setPDBCanvas(this);\r
- addKeyListener(new KeyAdapter()\r
- {\r
-\r
- public void keyPressed(KeyEvent evt)\r
- {\r
- doKeyPressed(evt);\r
- }\r
- });\r
- }\r
-\r
-\r
- public void setPDBFile(PDBfile pdb)\r
- {\r
- int max = -10;\r
- int maxchain = -1;\r
- int pdbstart = 0;\r
- int pdbend = 0;\r
- int seqstart = 0;\r
- int seqend = 0;\r
- AlignSeq maxAlignseq = null;;\r
-\r
- for (int i = 0; i < pdb.chains.size(); i++)\r
- {\r
-\r
- mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence());\r
- mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\n\n");\r
-\r
- // Now lets compare the sequences to get\r
- // the start and end points.\r
- // Align the sequence to the pdb\r
- AlignSeq as = new AlignSeq(sequence,\r
- ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");\r
- as.calcScoreMatrix();\r
- as.traceAlignment();\r
- PrintStream ps = new PrintStream(System.out)\r
- {\r
- public void print(String x) {\r
- mappingDetails.append(x);\r
- }\r
- public void println()\r
- {\r
- mappingDetails.append("\n");\r
- }\r
- };\r
-\r
- as.printAlignment(ps);\r
-\r
- if (as.maxscore > max) {\r
- max = as.maxscore;\r
- maxchain = i;\r
-\r
- pdbstart = as.seq2start;\r
- pdbend = as.seq2end;\r
- seqstart = as.seq1start + sequence.getStart()-1;\r
- seqend = as.seq1end + sequence.getEnd()-1;\r
- maxAlignseq = as;\r
- }\r
-\r
- mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);\r
- mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);\r
- }\r
-\r
- mainchain = (PDBChain) pdb.chains.elementAt(maxchain);\r
-\r
- mainchain.pdbstart = pdbstart;\r
- mainchain.pdbend = pdbend;\r
- mainchain.seqstart = seqstart;\r
- mainchain.seqend = seqend;\r
- mainchain.isVisible = true;\r
- mainchain.makeExactMapping(maxAlignseq, sequence);\r
-\r
- this.pdb = pdb;\r
- this.prefsize = new Dimension(getSize().width, getSize().height);\r
-\r
- //Initialize the matrices to identity\r
- for (int i = 0; i < 3; i++) {\r
- for (int j = 0; j < 3; j++) {\r
- if (i != j) {\r
- idmat.addElement(i, j, 0);\r
- objmat.addElement(i, j, 0);\r
- } else {\r
- idmat.addElement(i, j, 1);\r
- objmat.addElement(i, j, 1);\r
- }\r
- }\r
- }\r
-\r
- addMouseMotionListener(this);\r
- addMouseListener(this);\r
-\r
-\r
- findCentre();\r
- findWidth();\r
-\r
- setupBonds();\r
-\r
- scale = findScale();\r
- }\r
-\r
-\r
- Vector visiblebonds;\r
- void setupBonds()\r
- {\r
- seqColoursReady = false;\r
- // Sort the bonds by z coord\r
- visiblebonds = new Vector();\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)\r
- {\r
- Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < tmp.size(); i++)\r
- {\r
- visiblebonds.addElement(tmp.elementAt(i));\r
- }\r
- }\r
- }\r
- updateSeqColours();\r
- seqColoursReady = true;\r
- redrawneeded = true;\r
- repaint();\r
- }\r
-\r
-\r
- public void findWidth() {\r
- float[] max = new float[3];\r
- float[] min = new float[3];\r
-\r
- max[0] = (float) -1e30;\r
- max[1] = (float) -1e30;\r
- max[2] = (float) -1e30;\r
-\r
- min[0] = (float) 1e30;\r
- min[1] = (float) 1e30;\r
- min[2] = (float) 1e30;\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\r
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < bonds.size(); i++) {\r
- Bond tmp = (Bond) bonds.elementAt(i);\r
-\r
- if (tmp.start[0] >= max[0]) {\r
- max[0] = tmp.start[0];\r
- }\r
-\r
- if (tmp.start[1] >= max[1]) {\r
- max[1] = tmp.start[1];\r
- }\r
-\r
- if (tmp.start[2] >= max[2]) {\r
- max[2] = tmp.start[2];\r
- }\r
-\r
- if (tmp.start[0] <= min[0]) {\r
- min[0] = tmp.start[0];\r
- }\r
-\r
- if (tmp.start[1] <= min[1]) {\r
- min[1] = tmp.start[1];\r
- }\r
-\r
- if (tmp.start[2] <= min[2]) {\r
- min[2] = tmp.start[2];\r
- }\r
-\r
- if (tmp.end[0] >= max[0]) {\r
- max[0] = tmp.end[0];\r
- }\r
-\r
- if (tmp.end[1] >= max[1]) {\r
- max[1] = tmp.end[1];\r
- }\r
-\r
- if (tmp.end[2] >= max[2]) {\r
- max[2] = tmp.end[2];\r
- }\r
-\r
- if (tmp.end[0] <= min[0]) {\r
- min[0] = tmp.end[0];\r
- }\r
-\r
- if (tmp.end[1] <= min[1]) {\r
- min[1] = tmp.end[1];\r
- }\r
-\r
- if (tmp.end[2] <= min[2]) {\r
- min[2] = tmp.end[2];\r
- }\r
- }\r
- }\r
- }\r
-\r
- width[0] = (float) Math.abs(max[0] - min[0]);\r
- width[1] = (float) Math.abs(max[1] - min[1]);\r
- width[2] = (float) Math.abs(max[2] - min[2]);\r
-\r
- maxwidth = width[0];\r
-\r
- if (width[1] > width[0]) {\r
- maxwidth = width[1];\r
- }\r
-\r
- if (width[2] > width[1]) {\r
- maxwidth = width[2];\r
- }\r
-\r
- // System.out.println("Maxwidth = " + maxwidth);\r
- }\r
-\r
- public float findScale() {\r
- int dim;\r
- int width;\r
- int height;\r
-\r
- if (getSize().width != 0) {\r
- width = getSize().width;\r
- height = getSize().height;\r
- } else {\r
- width = prefsize.width;\r
- height = prefsize.height;\r
- }\r
-\r
- if (width < height) {\r
- dim = width;\r
- } else {\r
- dim = height;\r
- }\r
-\r
- return (float) (dim / (1.5d * maxwidth));\r
- }\r
-\r
- public void findCentre() {\r
- float xtot = 0;\r
- float ytot = 0;\r
- float ztot = 0;\r
-\r
- int bsize = 0;\r
-\r
- //Find centre coordinate\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\r
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- bsize += bonds.size();\r
-\r
- for (int i = 0; i < bonds.size(); i++) {\r
- xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +\r
- ((Bond) bonds.elementAt(i)).end[0];\r
-\r
- ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +\r
- ((Bond) bonds.elementAt(i)).end[1];\r
-\r
- ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +\r
- ((Bond) bonds.elementAt(i)).end[2];\r
- }\r
- }\r
- }\r
-\r
- centre[0] = xtot / (2 * (float) bsize);\r
- centre[1] = ytot / (2 * (float) bsize);\r
- centre[2] = ztot / (2 * (float) bsize);\r
- }\r
-\r
- public void paint(Graphics g)\r
- {\r
-\r
- if(errorLoading)\r
- {\r
- g.setColor(Color.white);\r
- g.fillRect(0,0,getSize().width, getSize().height);\r
- g.setColor(Color.black);\r
- g.setFont(new Font("Verdana", Font.BOLD, 14));\r
- g.drawString("Error loading PDB data!!", 50, getSize().height/2);\r
- return;\r
- }\r
-\r
- if( !seqColoursReady )\r
- {\r
- g.setColor(Color.black);\r
- g.setFont(new Font("Verdana", Font.BOLD, 14));\r
- g.drawString("Fetching PDB data...", 50, getSize().height/2);\r
- return;\r
- }\r
-\r
-\r
-\r
- //Only create the image at the beginning -\r
- //this saves much memory usage\r
- if ((img == null) || (prefsize.width != getSize().width) ||\r
- (prefsize.height != getSize().height)) {\r
-\r
- try{ prefsize.width = getSize().width;\r
- prefsize.height = getSize().height;\r
-\r
- scale = findScale();\r
- img = createImage(prefsize.width, prefsize.height);\r
- ig = img.getGraphics();\r
-\r
- redrawneeded = true;\r
- }catch(Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
- }\r
-\r
-\r
- if (redrawneeded)\r
- {\r
- drawAll(ig, prefsize.width, prefsize.height);\r
- redrawneeded = false;\r
- }\r
- if(appletToolTip!=null)\r
- {\r
- ig.setColor(Color.red);\r
- ig.drawString(appletToolTip, toolx, tooly);\r
- }\r
-\r
- g.drawImage(img, 0, 0, this);\r
-\r
- pdbAction = false;\r
- }\r
-\r
- public void drawAll(Graphics g, int width, int height)\r
- {\r
- ig.setColor(Color.black);\r
- ig.fillRect(0, 0, width, height);\r
- drawScene(ig);\r
- drawLabels(ig);\r
- }\r
-\r
- void setColours(jalview.schemes.ColourSchemeI cs)\r
- {\r
- bysequence = false;\r
- pdb.setColours(cs);\r
- redrawneeded = true;\r
- repaint();\r
- }\r
- public void updateSeqColours()\r
- {\r
- if (pdbAction)\r
- {\r
- return;\r
- }\r
-\r
- if(bysequence && pdb!=null)\r
- {\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- colourBySequence((PDBChain) pdb.chains.elementAt(ii));\r
- }\r
- }\r
-\r
- redrawneeded=true;\r
- repaint();\r
- }\r
-\r
-\r
- int findTrueIndex(int pos)\r
- {\r
- // returns the alignment position for a residue\r
- int j = sequence.getStart();\r
- int i = 0;\r
-\r
- while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))\r
- {\r
- if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))\r
- {\r
- j++;\r
- }\r
-\r
- i++;\r
- }\r
-\r
- if(i>1)\r
- i--;\r
-\r
- if ( (j == sequence.getEnd()) && (j < pos))\r
- {\r
- return sequence.getEnd() + 1;\r
- }\r
- else\r
- {\r
- return i;\r
- }\r
- }\r
-\r
-\r
- // This method has been taken out of PDBChain to allow\r
- // Applet and Application specific sequence renderers to be used\r
- void colourBySequence(PDBChain chain)\r
- {\r
- boolean showFeatures = false;\r
-\r
- if(seqcanvas.getViewport().getShowSequenceFeatures())\r
- {\r
- if(fr==null)\r
- {\r
- fr = new jalview.appletgui.FeatureRenderer(seqcanvas.getViewport());\r
- }\r
- fr.transferSettings( seqcanvas.getFeatureRenderer());\r
- showFeatures = true;\r
- }\r
-\r
- for (int i = 0; i < chain.bonds.size(); i++)\r
- {\r
- Bond tmp = (Bond) chain.bonds.elementAt(i);\r
- tmp.startCol = Color.lightGray;\r
- tmp.endCol = Color.lightGray;\r
- if(chain!=mainchain)\r
- continue;\r
-\r
- if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
- (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))\r
- {\r
-\r
- int index = findTrueIndex(tmp.at1.alignmentMapping);\r
- //sequence.findIndex(tmp.at1.alignmentMapping);\r
- if (index != -1)\r
- {\r
- tmp.startCol = seqcanvas.getSequenceRenderer().\r
- getResidueBoxColour( sequence, index);\r
-\r
- if(showFeatures)\r
- tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);\r
- }\r
- }\r
-\r
- int index = findTrueIndex(tmp.at2.alignmentMapping);\r
- //sequence.findIndex( tmp.at2.alignmentMapping );\r
- if (index != -1)\r
- {\r
- tmp.endCol = seqcanvas.getSequenceRenderer().\r
- getResidueBoxColour( sequence, index);\r
-\r
- if(showFeatures)\r
- tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);\r
- }\r
- }\r
- }\r
-\r
-\r
- Zsort zsort;\r
- public void drawScene(Graphics g)\r
- {\r
- if (zbuffer)\r
- {\r
- if(zsort ==null)\r
- zsort = new Zsort();\r
-\r
- zsort.Zsort(visiblebonds);\r
- }\r
-\r
-\r
- Bond tmpBond=null;\r
- for (int i = 0; i < visiblebonds.size(); i++)\r
- {\r
- tmpBond = (Bond) visiblebonds.elementAt(i);\r
-\r
-\r
- xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) +\r
- (getSize().width / 2));\r
- ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
- (getSize().height / 2));\r
-\r
- xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +\r
- (getSize().width / 2));\r
- yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +\r
- (getSize().height / 2));\r
-\r
- xmid = (xend + xstart) / 2;\r
- ymid = (yend + ystart) / 2;\r
-\r
- if (depthcue && !bymolecule)\r
- {\r
- if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {\r
- g.setColor(tmpBond.startCol.darker().darker());\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
- g.setColor(tmpBond.endCol.darker().darker());\r
- drawLine(g, xmid, ymid, xend, yend);\r
- } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {\r
- g.setColor(tmpBond.startCol.darker());\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
- g.setColor(tmpBond.endCol.darker());\r
- drawLine(g, xmid, ymid, xend, yend);\r
- } else {\r
- g.setColor(tmpBond.startCol);\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
- g.setColor(tmpBond.endCol);\r
- drawLine(g, xmid, ymid, xend, yend);\r
- }\r
-\r
- } else if (depthcue && bymolecule) {\r
- if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {\r
- g.setColor(Color.green.darker().darker());\r
- drawLine(g, xstart, ystart, xend, yend);\r
- } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {\r
- g.setColor(Color.green.darker());\r
- drawLine(g, xstart, ystart, xend, yend);\r
- } else {\r
- g.setColor(Color.green);\r
- drawLine(g, xstart, ystart, xend, yend);\r
- }\r
- } else if (!depthcue && !bymolecule) {\r
- g.setColor(tmpBond.startCol);\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
- g.setColor(tmpBond.endCol);\r
- drawLine(g, xmid, ymid, xend, yend);\r
- } else {\r
- drawLine(g, xstart, ystart, xend, yend);\r
- }\r
-\r
- if(highlightBond1!=null && highlightBond1==tmpBond)\r
- {\r
- g.setColor(Color.white);\r
- drawLine(g, xmid, ymid, xend, yend);\r
- }\r
-\r
- if(highlightBond2!=null && highlightBond2==tmpBond)\r
- {\r
- g.setColor(Color.white);\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
- }\r
-\r
- }\r
- }\r
-\r
- public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {\r
- if (!wire) {\r
- if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {\r
- g.drawLine(x1, y1, x2, y2);\r
- g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);\r
- g.drawLine(x1, y1 - 1, x2, y2 - 1);\r
- } else {\r
- g.setColor(g.getColor().brighter());\r
- g.drawLine(x1, y1, x2, y2);\r
- g.drawLine(x1 + 1, y1, x2 + 1, y2);\r
- g.drawLine(x1 - 1, y1, x2 - 1, y2);\r
- }\r
- } else {\r
- g.drawLine(x1, y1, x2, y2);\r
- }\r
- }\r
-\r
- public Dimension minimumsize() {\r
- return prefsize;\r
- }\r
-\r
- public Dimension preferredsize() {\r
- return prefsize;\r
- }\r
-\r
- public void doKeyPressed(KeyEvent evt)\r
- {\r
- if (evt.getKeyCode() == KeyEvent.VK_UP)\r
- {\r
- scale = (float) (scale * 1.1);\r
- redrawneeded = true;\r
- repaint();\r
- }\r
- else if (evt.getKeyCode() == KeyEvent.VK_DOWN)\r
- {\r
- scale = (float) (scale * 0.9);\r
- redrawneeded = true;\r
- repaint();\r
- }\r
- }\r
-\r
- public void mousePressed(MouseEvent e) {\r
- pdbAction = true;\r
- Atom fatom = findAtom(e.getX(), e.getY());\r
- if(fatom!=null)\r
- {\r
- fatom.isSelected = !fatom.isSelected;\r
-\r
- redrawneeded = true;\r
- repaint();\r
- if (foundchain != -1)\r
- {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
- if (chain == mainchain)\r
- {\r
- if (fatom.alignmentMapping != -1)\r
- {\r
- if (highlightRes == null)\r
- highlightRes = new Vector();\r
-\r
- if (highlightRes.contains(fatom.alignmentMapping+"" + ""))\r
- highlightRes.removeElement(fatom.alignmentMapping + "");\r
- else\r
- highlightRes.addElement(fatom.alignmentMapping + "");\r
- }\r
- }\r
- }\r
-\r
- }\r
- mx = e.getX();\r
- my = e.getY();\r
- omx = mx;\r
- omy = my;\r
- dragging = false;\r
- }\r
-\r
- public void mouseMoved(MouseEvent e) {\r
- pdbAction = true;\r
- if(highlightBond1!=null)\r
- {\r
- highlightBond1.at2.isSelected = false;\r
- highlightBond2.at1.isSelected = false;\r
- highlightBond1 = null;\r
- highlightBond2 = null;\r
- }\r
-\r
- Atom fatom = findAtom(e.getX(), e.getY());\r
-\r
- PDBChain chain = null;\r
- if(foundchain!=-1)\r
- {\r
- chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
- if(chain == mainchain)\r
- {\r
- highlightSeqcanvas( fatom.alignmentMapping );\r
- }\r
- }\r
-\r
- if (fatom != null) {\r
- toolx = e.getX();\r
- tooly = e.getY();\r
-\r
- appletToolTip = chain.id+":"+ fatom.resNumber+" "+ fatom.resName;\r
- redrawneeded = true;\r
- repaint();\r
- } else {\r
- highlightSeqcanvas( -1);\r
- appletToolTip = null;\r
- redrawneeded = true;\r
- repaint();\r
- }\r
- }\r
-\r
-\r
- void highlightSeqcanvas(int pos)\r
- {\r
- SearchResults searchResults = new SearchResults();\r
- if(highlightRes!=null)\r
- {\r
- for (int i = 0; i < highlightRes.size(); i++)\r
- {\r
- int a = Integer.parseInt(highlightRes.elementAt(\r
- i).toString())+1;\r
-\r
- searchResults.addResult(sequence, a, a);\r
- }\r
- }\r
-\r
- if(pos!=-1)\r
- {\r
- searchResults.addResult(sequence, pos+1, pos+1);\r
- }\r
-\r
- seqcanvas.highlightSearchResults(searchResults);\r
- }\r
-\r
-\r
- public void mouseClicked(MouseEvent e) {\r
- }\r
-\r
- public void mouseEntered(MouseEvent e) {\r
- }\r
-\r
- public void mouseExited(MouseEvent e) {\r
- }\r
-\r
- public void mouseDragged(MouseEvent evt) {\r
- int x = evt.getX();\r
- int y = evt.getY();\r
- mx = x;\r
- my = y;\r
-\r
- MCMatrix objmat = new MCMatrix(3, 3);\r
- objmat.setIdentity();\r
-\r
- if ((evt.getModifiers() & Event.META_MASK) != 0) {\r
- objmat.rotatez((float) ((mx - omx)));\r
- } else {\r
- objmat.rotatex((float) ((my - omy)));\r
- objmat.rotatey((float) ((omx - mx)));\r
- }\r
-\r
- //Alter the bonds\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < bonds.size(); i++) {\r
- Bond tmpBond = (Bond) bonds.elementAt(i);\r
-\r
- //Translate the bond so the centre is 0,0,0\r
- tmpBond.translate(-centre[0], -centre[1], -centre[2]);\r
-\r
- //Now apply the rotation matrix\r
- tmpBond.start = objmat.vectorMultiply(tmpBond.start);\r
- tmpBond.end = objmat.vectorMultiply(tmpBond.end);\r
-\r
- //Now translate back again\r
- tmpBond.translate(centre[0], centre[1], centre[2]);\r
- }\r
- }\r
-\r
- objmat = null;\r
-\r
- omx = mx;\r
- omy = my;\r
-\r
- dragging = true;\r
-\r
- redrawneeded = true;\r
-\r
- repaint();\r
- }\r
-\r
- public void mouseReleased(MouseEvent evt) {\r
- dragging = false;\r
- return;\r
- }\r
-\r
- void drawLabels(Graphics g) {\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
-\r
- if (chain.isVisible)\r
- {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < bonds.size(); i++)\r
- {\r
- Bond tmpBond = (Bond) bonds.elementAt(i);\r
-\r
- if (tmpBond.at1.isSelected)\r
- {\r
- labelAtom(g, tmpBond, 1);\r
- }\r
-\r
- if (tmpBond.at2.isSelected)\r
- {\r
-\r
- labelAtom(g, tmpBond, 2);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- public void labelAtom(Graphics g, Bond b, int n) {\r
- g.setFont(font);\r
-\r
- if (n == 1) {\r
- int xstart = (int) (((b.start[0] - centre[0]) * scale) +\r
- (getSize().width / 2));\r
- int ystart = (int) (((b.start[1] - centre[1]) * scale) +\r
- (getSize().height / 2));\r
-\r
- g.setColor(Color.red);\r
- g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);\r
- }\r
-\r
- if (n == 2) {\r
- int xstart = (int) (((b.end[0] - centre[0]) * scale) +\r
- (getSize().width / 2));\r
- int ystart = (int) (((b.end[1] - centre[1]) * scale) +\r
- (getSize().height / 2));\r
-\r
- g.setColor(Color.red);\r
- g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);\r
- }\r
- }\r
-\r
- int foundchain = -1;\r
- public Atom findAtom(int x, int y) {\r
- Atom fatom = null;\r
-\r
- foundchain = -1;\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
- int truex;\r
- Bond tmpBond=null;\r
-\r
- if (chain.isVisible)\r
- {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < bonds.size(); i++)\r
- {\r
- tmpBond = (Bond) bonds.elementAt(i);\r
-\r
- truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +\r
- (getSize().width / 2));\r
-\r
- if (Math.abs(truex - x) <= 2)\r
- {\r
- int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
- (getSize().height / 2));\r
-\r
- if (Math.abs(truey - y) <= 2)\r
- {\r
- fatom = tmpBond.at1;\r
- foundchain = ii;\r
- break;\r
- }\r
- }\r
- }\r
-\r
- // Still here? Maybe its the last bond\r
-\r
- truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +\r
- (getSize().width / 2));\r
-\r
- if (Math.abs(truex - x) <= 2)\r
- {\r
- int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +\r
- (getSize().height / 2));\r
-\r
- if (Math.abs(truey - y) <= 2)\r
- {\r
- fatom = tmpBond.at2;\r
- foundchain = ii;\r
- break;\r
- }\r
- }\r
-\r
- }\r
-\r
- if (fatom != null) //)&& chain.ds != null)\r
- {\r
- chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
- }\r
- }\r
-\r
- return fatom;\r
- }\r
-\r
- public void update(Graphics g)\r
- {\r
- paint(g);\r
- }\r
-\r
- public void highlightRes(int ii)\r
- {\r
- if(!seqColoursReady)\r
- return;\r
-\r
- if (highlightRes != null\r
- && highlightRes.contains((ii-1) + ""))\r
- {\r
- return;\r
- }\r
-\r
- int index = -1;\r
- Bond tmpBond;\r
- for(index=0; index<mainchain.bonds.size(); index++)\r
- {\r
- tmpBond = (Bond) mainchain.bonds.elementAt(index);\r
- if (tmpBond.at1.alignmentMapping == ii - 1)\r
- {\r
- if (highlightBond1 != null)\r
- highlightBond1.at2.isSelected = false;\r
-\r
- if (highlightBond2 != null)\r
- highlightBond2.at1.isSelected = false;\r
-\r
- highlightBond1 = null;\r
- highlightBond2 = null;\r
-\r
- if (index > 0)\r
- {\r
- highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);\r
- highlightBond1.at2.isSelected = true;\r
- }\r
-\r
- if (index != mainchain.bonds.size())\r
- {\r
- highlightBond2 = (Bond) mainchain.bonds.elementAt(index);\r
- highlightBond2.at1.isSelected = true;\r
- }\r
-\r
- break;\r
- }\r
- }\r
-\r
- redrawneeded = true;\r
- repaint();\r
- }\r
-\r
-\r
- public void setAllchainsVisible(boolean b)\r
- {\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
- chain.isVisible = b;\r
- }\r
- mainchain.isVisible = true;\r
- findCentre();\r
- setupBonds();\r
- }\r
-\r
-}\r
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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 jalview.analysis.AlignSeq;
+
+import jalview.datamodel.*;
+
+// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
+import java.awt.*;
+import java.awt.event.*;
+
+import java.io.*;
+
+import java.util.*;
+
+
+
+public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener
+{
+
+ MCMatrix idmat = new MCMatrix(3, 3);
+ MCMatrix objmat = new MCMatrix(3, 3);
+ boolean redrawneeded = true;
+ int omx = 0;
+ int mx = 0;
+ int omy = 0;
+ int my = 0;
+ public PDBfile pdb;
+ int bsize;
+ Image img;
+ Graphics ig;
+ Dimension prefsize;
+ float[] centre = new float[3];
+ float[] width = new float[3];
+ float maxwidth;
+ float scale;
+ String inStr;
+ String inType;
+ boolean bysequence = true;
+ boolean depthcue = true;
+ boolean wire = false;
+ boolean bymolecule = false;
+ boolean zbuffer = true;
+ boolean dragging;
+ int xstart;
+ int xend;
+ int ystart;
+ int yend;
+ int xmid;
+ int ymid;
+ Font font = new Font("Helvetica", Font.PLAIN, 10);
+ jalview.appletgui.SeqCanvas seqcanvas;
+ public Sequence sequence;
+ final StringBuffer mappingDetails = new StringBuffer();
+ String appletToolTip = null;
+ int toolx, tooly;
+ PDBChain mainchain;
+ Vector highlightRes;
+ boolean pdbAction = false;
+ Bond highlightBond1, highlightBond2;
+ boolean errorLoading = false;
+ boolean seqColoursReady = false;
+ jalview.appletgui.FeatureRenderer fr;
+
+ public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq)
+ {
+ this.seqcanvas = seqcanvas;
+ this.sequence = seq;
+
+ seqcanvas.setPDBCanvas(this);
+ addKeyListener(new KeyAdapter()
+ {
+
+ public void keyPressed(KeyEvent evt)
+ {
+ doKeyPressed(evt);
+ }
+ });
+ }
+
+
+ public void setPDBFile(PDBfile pdb)
+ {
+ int max = -10;
+ int maxchain = -1;
+ int pdbstart = 0;
+ int pdbend = 0;
+ int seqstart = 0;
+ int seqend = 0;
+ AlignSeq maxAlignseq = null;;
+
+ for (int i = 0; i < pdb.chains.size(); i++)
+ {
+
+ mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequenceAsString());
+ mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\n\n");
+
+ // Now lets compare the sequences to get
+ // the start and end points.
+ // Align the sequence to the pdb
+ AlignSeq as = new AlignSeq(sequence,
+ ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");
+ as.calcScoreMatrix();
+ as.traceAlignment();
+ PrintStream ps = new PrintStream(System.out)
+ {
+ public void print(String x) {
+ mappingDetails.append(x);
+ }
+ public void println()
+ {
+ mappingDetails.append("\n");
+ }
+ };
+
+ as.printAlignment(ps);
+
+ if (as.maxscore > max) {
+ max = as.maxscore;
+ maxchain = i;
+
+ pdbstart = as.seq2start;
+ pdbend = as.seq2end;
+ seqstart = as.seq1start + sequence.getStart()-1;
+ seqend = as.seq1end + sequence.getEnd()-1;
+ maxAlignseq = as;
+ }
+
+ mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
+ mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);
+ }
+
+ mainchain = (PDBChain) pdb.chains.elementAt(maxchain);
+
+ mainchain.pdbstart = pdbstart;
+ mainchain.pdbend = pdbend;
+ mainchain.seqstart = seqstart;
+ mainchain.seqend = seqend;
+ mainchain.isVisible = true;
+ mainchain.makeExactMapping(maxAlignseq, sequence);
+
+ this.pdb = pdb;
+ this.prefsize = new Dimension(getSize().width, getSize().height);
+
+ //Initialize the matrices to identity
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ if (i != j) {
+ idmat.addElement(i, j, 0);
+ objmat.addElement(i, j, 0);
+ } else {
+ idmat.addElement(i, j, 1);
+ objmat.addElement(i, j, 1);
+ }
+ }
+ }
+
+ addMouseMotionListener(this);
+ addMouseListener(this);
+
+
+ findCentre();
+ findWidth();
+
+ setupBonds();
+
+ scale = findScale();
+ }
+
+
+ Vector visiblebonds;
+ void setupBonds()
+ {
+ seqColoursReady = false;
+ // Sort the bonds by z coord
+ visiblebonds = new Vector();
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)
+ {
+ Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < tmp.size(); i++)
+ {
+ visiblebonds.addElement(tmp.elementAt(i));
+ }
+ }
+ }
+ updateSeqColours();
+ seqColoursReady = true;
+ redrawneeded = true;
+ repaint();
+ }
+
+
+ public void findWidth() {
+ float[] max = new float[3];
+ float[] min = new float[3];
+
+ max[0] = (float) -1e30;
+ max[1] = (float) -1e30;
+ max[2] = (float) -1e30;
+
+ min[0] = (float) 1e30;
+ min[1] = (float) 1e30;
+ min[2] = (float) 1e30;
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++) {
+ Bond tmp = (Bond) bonds.elementAt(i);
+
+ if (tmp.start[0] >= max[0]) {
+ max[0] = tmp.start[0];
+ }
+
+ if (tmp.start[1] >= max[1]) {
+ max[1] = tmp.start[1];
+ }
+
+ if (tmp.start[2] >= max[2]) {
+ max[2] = tmp.start[2];
+ }
+
+ if (tmp.start[0] <= min[0]) {
+ min[0] = tmp.start[0];
+ }
+
+ if (tmp.start[1] <= min[1]) {
+ min[1] = tmp.start[1];
+ }
+
+ if (tmp.start[2] <= min[2]) {
+ min[2] = tmp.start[2];
+ }
+
+ if (tmp.end[0] >= max[0]) {
+ max[0] = tmp.end[0];
+ }
+
+ if (tmp.end[1] >= max[1]) {
+ max[1] = tmp.end[1];
+ }
+
+ if (tmp.end[2] >= max[2]) {
+ max[2] = tmp.end[2];
+ }
+
+ if (tmp.end[0] <= min[0]) {
+ min[0] = tmp.end[0];
+ }
+
+ if (tmp.end[1] <= min[1]) {
+ min[1] = tmp.end[1];
+ }
+
+ if (tmp.end[2] <= min[2]) {
+ min[2] = tmp.end[2];
+ }
+ }
+ }
+ }
+
+ width[0] = (float) Math.abs(max[0] - min[0]);
+ width[1] = (float) Math.abs(max[1] - min[1]);
+ width[2] = (float) Math.abs(max[2] - min[2]);
+
+ maxwidth = width[0];
+
+ if (width[1] > width[0]) {
+ maxwidth = width[1];
+ }
+
+ if (width[2] > width[1]) {
+ maxwidth = width[2];
+ }
+
+ // System.out.println("Maxwidth = " + maxwidth);
+ }
+
+ public float findScale() {
+ int dim;
+ int width;
+ int height;
+
+ if (getSize().width != 0) {
+ width = getSize().width;
+ height = getSize().height;
+ } else {
+ width = prefsize.width;
+ height = prefsize.height;
+ }
+
+ if (width < height) {
+ dim = width;
+ } else {
+ dim = height;
+ }
+
+ return (float) (dim / (1.5d * maxwidth));
+ }
+
+ public void findCentre() {
+ float xtot = 0;
+ float ytot = 0;
+ float ztot = 0;
+
+ int bsize = 0;
+
+ //Find centre coordinate
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ bsize += bonds.size();
+
+ for (int i = 0; i < bonds.size(); i++) {
+ xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +
+ ((Bond) bonds.elementAt(i)).end[0];
+
+ ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +
+ ((Bond) bonds.elementAt(i)).end[1];
+
+ ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +
+ ((Bond) bonds.elementAt(i)).end[2];
+ }
+ }
+ }
+
+ centre[0] = xtot / (2 * (float) bsize);
+ centre[1] = ytot / (2 * (float) bsize);
+ centre[2] = ztot / (2 * (float) bsize);
+ }
+
+ public void paint(Graphics g)
+ {
+
+ if(errorLoading)
+ {
+ g.setColor(Color.white);
+ g.fillRect(0,0,getSize().width, getSize().height);
+ g.setColor(Color.black);
+ g.setFont(new Font("Verdana", Font.BOLD, 14));
+ g.drawString("Error loading PDB data!!", 50, getSize().height/2);
+ return;
+ }
+
+ if( !seqColoursReady )
+ {
+ g.setColor(Color.black);
+ g.setFont(new Font("Verdana", Font.BOLD, 14));
+ g.drawString("Fetching PDB data...", 50, getSize().height/2);
+ return;
+ }
+
+
+
+ //Only create the image at the beginning -
+ //this saves much memory usage
+ if ((img == null) || (prefsize.width != getSize().width) ||
+ (prefsize.height != getSize().height)) {
+
+ try{ prefsize.width = getSize().width;
+ prefsize.height = getSize().height;
+
+ scale = findScale();
+ img = createImage(prefsize.width, prefsize.height);
+ ig = img.getGraphics();
+
+ redrawneeded = true;
+ }catch(Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+
+ if (redrawneeded)
+ {
+ drawAll(ig, prefsize.width, prefsize.height);
+ redrawneeded = false;
+ }
+ if(appletToolTip!=null)
+ {
+ ig.setColor(Color.red);
+ ig.drawString(appletToolTip, toolx, tooly);
+ }
+
+ g.drawImage(img, 0, 0, this);
+
+ pdbAction = false;
+ }
+
+ public void drawAll(Graphics g, int width, int height)
+ {
+ ig.setColor(Color.black);
+ ig.fillRect(0, 0, width, height);
+ drawScene(ig);
+ drawLabels(ig);
+ }
+
+ void setColours(jalview.schemes.ColourSchemeI cs)
+ {
+ bysequence = false;
+ pdb.setColours(cs);
+ redrawneeded = true;
+ repaint();
+ }
+ public void updateSeqColours()
+ {
+ if (pdbAction)
+ {
+ return;
+ }
+
+ if(bysequence && pdb!=null)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ colourBySequence((PDBChain) pdb.chains.elementAt(ii));
+ }
+ }
+
+ redrawneeded=true;
+ repaint();
+ }
+
+
+ int findTrueIndex(int pos)
+ {
+ // returns the alignment position for a residue
+ int j = sequence.getStart();
+ int i = 0;
+
+ while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))
+ {
+ if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))
+ {
+ j++;
+ }
+
+ i++;
+ }
+
+ if(i>1)
+ i--;
+
+ if ( (j == sequence.getEnd()) && (j < pos))
+ {
+ return sequence.getEnd() + 1;
+ }
+ else
+ {
+ return i;
+ }
+ }
+
+
+ // This method has been taken out of PDBChain to allow
+ // Applet and Application specific sequence renderers to be used
+ void colourBySequence(PDBChain chain)
+ {
+ boolean showFeatures = false;
+
+ if(seqcanvas.getViewport().getShowSequenceFeatures())
+ {
+ if(fr==null)
+ {
+ fr = new jalview.appletgui.FeatureRenderer(seqcanvas.getViewport());
+ }
+ fr.transferSettings( seqcanvas.getFeatureRenderer());
+ showFeatures = true;
+ }
+
+ for (int i = 0; i < chain.bonds.size(); i++)
+ {
+ Bond tmp = (Bond) chain.bonds.elementAt(i);
+ tmp.startCol = Color.lightGray;
+ tmp.endCol = Color.lightGray;
+ if(chain!=mainchain)
+ continue;
+
+ if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
+ (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))
+ {
+
+ int index = findTrueIndex(tmp.at1.alignmentMapping);
+ //sequence.findIndex(tmp.at1.alignmentMapping);
+ if (index != -1)
+ {
+ tmp.startCol = seqcanvas.getSequenceRenderer().
+ getResidueBoxColour( sequence, index);
+
+ if(showFeatures)
+ tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
+ }
+ }
+
+ int index = findTrueIndex(tmp.at2.alignmentMapping);
+ //sequence.findIndex( tmp.at2.alignmentMapping );
+ if (index != -1)
+ {
+ tmp.endCol = seqcanvas.getSequenceRenderer().
+ getResidueBoxColour( sequence, index);
+
+ if(showFeatures)
+ tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);
+ }
+ }
+ }
+
+
+ Zsort zsort;
+ public void drawScene(Graphics g)
+ {
+ if (zbuffer)
+ {
+ if(zsort ==null)
+ zsort = new Zsort();
+
+ zsort.Zsort(visiblebonds);
+ }
+
+
+ Bond tmpBond=null;
+ for (int i = 0; i < visiblebonds.size(); i++)
+ {
+ tmpBond = (Bond) visiblebonds.elementAt(i);
+
+
+ xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+ ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ xend = (int) (((tmpBond.end[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+ yend = (int) (((tmpBond.end[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ xmid = (xend + xstart) / 2;
+ ymid = (yend + ystart) / 2;
+
+ if (depthcue && !bymolecule)
+ {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {
+ g.setColor(tmpBond.startCol.darker().darker());
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol.darker().darker());
+ drawLine(g, xmid, ymid, xend, yend);
+ } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {
+ g.setColor(tmpBond.startCol.darker());
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol.darker());
+ drawLine(g, xmid, ymid, xend, yend);
+ } else {
+ g.setColor(tmpBond.startCol);
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol);
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+
+ } else if (depthcue && bymolecule) {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) {
+ g.setColor(Color.green.darker().darker());
+ drawLine(g, xstart, ystart, xend, yend);
+ } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) {
+ g.setColor(Color.green.darker());
+ drawLine(g, xstart, ystart, xend, yend);
+ } else {
+ g.setColor(Color.green);
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+ } else if (!depthcue && !bymolecule) {
+ g.setColor(tmpBond.startCol);
+ drawLine(g, xstart, ystart, xmid, ymid);
+ g.setColor(tmpBond.endCol);
+ drawLine(g, xmid, ymid, xend, yend);
+ } else {
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+
+ if(highlightBond1!=null && highlightBond1==tmpBond)
+ {
+ g.setColor(Color.white);
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+
+ if(highlightBond2!=null && highlightBond2==tmpBond)
+ {
+ g.setColor(Color.white);
+ drawLine(g, xstart, ystart, xmid, ymid);
+ }
+
+ }
+ }
+
+ public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {
+ if (!wire) {
+ if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {
+ g.drawLine(x1, y1, x2, y2);
+ g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
+ g.drawLine(x1, y1 - 1, x2, y2 - 1);
+ } else {
+ g.setColor(g.getColor().brighter());
+ g.drawLine(x1, y1, x2, y2);
+ g.drawLine(x1 + 1, y1, x2 + 1, y2);
+ g.drawLine(x1 - 1, y1, x2 - 1, y2);
+ }
+ } else {
+ g.drawLine(x1, y1, x2, y2);
+ }
+ }
+
+ public Dimension minimumsize() {
+ return prefsize;
+ }
+
+ public Dimension preferredsize() {
+ return prefsize;
+ }
+
+ public void doKeyPressed(KeyEvent evt)
+ {
+ if (evt.getKeyCode() == KeyEvent.VK_UP)
+ {
+ scale = (float) (scale * 1.1);
+ redrawneeded = true;
+ repaint();
+ }
+ else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
+ {
+ scale = (float) (scale * 0.9);
+ redrawneeded = true;
+ repaint();
+ }
+ }
+
+ public void mousePressed(MouseEvent e) {
+ pdbAction = true;
+ Atom fatom = findAtom(e.getX(), e.getY());
+ if(fatom!=null)
+ {
+ fatom.isSelected = !fatom.isSelected;
+
+ redrawneeded = true;
+ repaint();
+ if (foundchain != -1)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ if (chain == mainchain)
+ {
+ if (fatom.alignmentMapping != -1)
+ {
+ if (highlightRes == null)
+ highlightRes = new Vector();
+
+ if (highlightRes.contains(fatom.alignmentMapping+"" + ""))
+ highlightRes.removeElement(fatom.alignmentMapping + "");
+ else
+ highlightRes.addElement(fatom.alignmentMapping + "");
+ }
+ }
+ }
+
+ }
+ mx = e.getX();
+ my = e.getY();
+ omx = mx;
+ omy = my;
+ dragging = false;
+ }
+
+ public void mouseMoved(MouseEvent e) {
+ pdbAction = true;
+ if(highlightBond1!=null)
+ {
+ highlightBond1.at2.isSelected = false;
+ highlightBond2.at1.isSelected = false;
+ highlightBond1 = null;
+ highlightBond2 = null;
+ }
+
+ Atom fatom = findAtom(e.getX(), e.getY());
+
+ PDBChain chain = null;
+ if(foundchain!=-1)
+ {
+ chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ if(chain == mainchain)
+ {
+ highlightSeqcanvas( fatom.alignmentMapping );
+ }
+ }
+
+ if (fatom != null) {
+ toolx = e.getX();
+ tooly = e.getY();
+
+ appletToolTip = chain.id+":"+ fatom.resNumber+" "+ fatom.resName;
+ redrawneeded = true;
+ repaint();
+ } else {
+ highlightSeqcanvas( -1);
+ appletToolTip = null;
+ redrawneeded = true;
+ repaint();
+ }
+ }
+
+
+ void highlightSeqcanvas(int pos)
+ {
+ SearchResults searchResults = new SearchResults();
+ if(highlightRes!=null)
+ {
+ for (int i = 0; i < highlightRes.size(); i++)
+ {
+ int a = Integer.parseInt(highlightRes.elementAt(
+ i).toString())+1;
+
+ searchResults.addResult(sequence, a, a);
+ }
+ }
+
+ if(pos!=-1)
+ {
+ searchResults.addResult(sequence, pos+1, pos+1);
+ }
+
+ seqcanvas.highlightSearchResults(searchResults);
+ }
+
+
+ public void mouseClicked(MouseEvent e) {
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+
+ public void mouseDragged(MouseEvent evt) {
+ int x = evt.getX();
+ int y = evt.getY();
+ mx = x;
+ my = y;
+
+ MCMatrix objmat = new MCMatrix(3, 3);
+ objmat.setIdentity();
+
+ if ((evt.getModifiers() & Event.META_MASK) != 0) {
+ objmat.rotatez((float) ((mx - omx)));
+ } else {
+ objmat.rotatex((float) ((my - omy)));
+ objmat.rotatey((float) ((omx - mx)));
+ }
+
+ //Alter the bonds
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++) {
+ Bond tmpBond = (Bond) bonds.elementAt(i);
+
+ //Translate the bond so the centre is 0,0,0
+ tmpBond.translate(-centre[0], -centre[1], -centre[2]);
+
+ //Now apply the rotation matrix
+ tmpBond.start = objmat.vectorMultiply(tmpBond.start);
+ tmpBond.end = objmat.vectorMultiply(tmpBond.end);
+
+ //Now translate back again
+ tmpBond.translate(centre[0], centre[1], centre[2]);
+ }
+ }
+
+ objmat = null;
+
+ omx = mx;
+ omy = my;
+
+ dragging = true;
+
+ redrawneeded = true;
+
+ repaint();
+ }
+
+ public void mouseReleased(MouseEvent evt) {
+ dragging = false;
+ return;
+ }
+
+ void drawLabels(Graphics g) {
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+
+ if (chain.isVisible)
+ {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++)
+ {
+ Bond tmpBond = (Bond) bonds.elementAt(i);
+
+ if (tmpBond.at1.isSelected)
+ {
+ labelAtom(g, tmpBond, 1);
+ }
+
+ if (tmpBond.at2.isSelected)
+ {
+
+ labelAtom(g, tmpBond, 2);
+ }
+ }
+ }
+ }
+ }
+
+ public void labelAtom(Graphics g, Bond b, int n) {
+ g.setFont(font);
+
+ if (n == 1) {
+ int xstart = (int) (((b.start[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+ int ystart = (int) (((b.start[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ g.setColor(Color.red);
+ g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);
+ }
+
+ if (n == 2) {
+ int xstart = (int) (((b.end[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+ int ystart = (int) (((b.end[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ g.setColor(Color.red);
+ g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);
+ }
+ }
+
+ int foundchain = -1;
+ public Atom findAtom(int x, int y) {
+ Atom fatom = null;
+
+ foundchain = -1;
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ int truex;
+ Bond tmpBond=null;
+
+ if (chain.isVisible)
+ {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++)
+ {
+ tmpBond = (Bond) bonds.elementAt(i);
+
+ truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ if (Math.abs(truey - y) <= 2)
+ {
+ fatom = tmpBond.at1;
+ foundchain = ii;
+ break;
+ }
+ }
+ }
+
+ // Still here? Maybe its the last bond
+
+ truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
+ (getSize().width / 2));
+
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
+ (getSize().height / 2));
+
+ if (Math.abs(truey - y) <= 2)
+ {
+ fatom = tmpBond.at2;
+ foundchain = ii;
+ break;
+ }
+ }
+
+ }
+
+ if (fatom != null) //)&& chain.ds != null)
+ {
+ chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ }
+ }
+
+ return fatom;
+ }
+
+ public void update(Graphics g)
+ {
+ paint(g);
+ }
+
+ public void highlightRes(int ii)
+ {
+ if(!seqColoursReady)
+ return;
+
+ if (highlightRes != null
+ && highlightRes.contains((ii-1) + ""))
+ {
+ return;
+ }
+
+ int index = -1;
+ Bond tmpBond;
+ for(index=0; index<mainchain.bonds.size(); index++)
+ {
+ tmpBond = (Bond) mainchain.bonds.elementAt(index);
+ if (tmpBond.at1.alignmentMapping == ii - 1)
+ {
+ if (highlightBond1 != null)
+ highlightBond1.at2.isSelected = false;
+
+ if (highlightBond2 != null)
+ highlightBond2.at1.isSelected = false;
+
+ highlightBond1 = null;
+ highlightBond2 = null;
+
+ if (index > 0)
+ {
+ highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
+ highlightBond1.at2.isSelected = true;
+ }
+
+ if (index != mainchain.bonds.size())
+ {
+ highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
+ highlightBond2.at1.isSelected = true;
+ }
+
+ break;
+ }
+ }
+
+ redrawneeded = true;
+ repaint();
+ }
+
+
+ public void setAllchainsVisible(boolean b)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ chain.isVisible = b;
+ }
+ mainchain.isVisible = true;
+ findCentre();
+ setupBonds();
+ }
+
+}
-/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
-*/\r
-package MCview;\r
-\r
-import jalview.analysis.AlignSeq;\r
-\r
-import jalview.datamodel.*;\r
-\r
-// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-import java.io.*;\r
-\r
-import java.util.*;\r
-\r
-import javax.swing.*;\r
-\r
-\r
-public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListener\r
-{\r
- MCMatrix idmat = new MCMatrix(3, 3);\r
- MCMatrix objmat = new MCMatrix(3, 3);\r
- boolean redrawneeded = true;\r
- int omx = 0;\r
- int mx = 0;\r
- int omy = 0;\r
- int my = 0;\r
- public PDBfile pdb;\r
- int bsize;\r
- Image img;\r
- Graphics ig;\r
- Dimension prefsize;\r
- float[] centre = new float[3];\r
- float[] width = new float[3];\r
- float maxwidth;\r
- float scale;\r
- String inStr;\r
- String inType;\r
- boolean bysequence = true;\r
- boolean depthcue = true;\r
- boolean wire = false;\r
- boolean bymolecule = false;\r
- boolean zbuffer = true;\r
- boolean dragging;\r
- int xstart;\r
- int xend;\r
- int ystart;\r
- int yend;\r
- int xmid;\r
- int ymid;\r
- Font font = new Font("Helvetica", Font.PLAIN, 10);\r
- jalview.gui.SeqCanvas seqcanvas;\r
- public Sequence sequence;\r
- final StringBuffer mappingDetails = new StringBuffer();\r
- PDBChain mainchain;\r
- Vector highlightRes;\r
- boolean pdbAction = false;\r
- boolean seqColoursReady = false;\r
- jalview.gui.FeatureRenderer fr;\r
- Color backgroundColour = Color.black;\r
-\r
- public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq)\r
- {\r
- this.seqcanvas = seqcanvas;\r
- this.sequence = seq;\r
- seqcanvas.setPDBCanvas(this);\r
- }\r
-\r
- public void setPDBFile(PDBfile pdb)\r
- {\r
- int max = -10;\r
- int maxchain = -1;\r
- int pdbstart = 0;\r
- int pdbend = 0;\r
- int seqstart = 0;\r
- int seqend = 0;\r
- AlignSeq maxAlignseq = null;\r
-\r
- for (int i = 0; i < pdb.chains.size(); i++)\r
- {\r
-\r
- mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence());\r
- mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\n\n");\r
-\r
- // Now lets compare the sequences to get\r
- // the start and end points.\r
- // Align the sequence to the pdb\r
- AlignSeq as = new AlignSeq(sequence,\r
- ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");\r
- as.calcScoreMatrix();\r
- as.traceAlignment();\r
- PrintStream ps = new PrintStream(System.out)\r
- {\r
- public void print(String x) {\r
- mappingDetails.append(x);\r
- }\r
- public void println()\r
- {\r
- mappingDetails.append("\n");\r
- }\r
- };\r
-\r
- as.printAlignment(ps);\r
-\r
-\r
-\r
- if (as.maxscore > max)\r
- {\r
- max = as.maxscore;\r
- maxchain = i;\r
- pdbstart = as.seq2start;\r
- pdbend = as.seq2end;\r
- seqstart = as.seq1start + sequence.getStart()-1;\r
- seqend = as.seq1end + sequence.getEnd()-1;\r
- maxAlignseq = as;\r
- }\r
-\r
- mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);\r
- mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);\r
- }\r
-\r
- mainchain = (PDBChain) pdb.chains.elementAt(maxchain);\r
-\r
- mainchain.pdbstart = pdbstart;\r
- mainchain.pdbend = pdbend;\r
- mainchain.seqstart = seqstart;\r
- mainchain.seqend = seqend;\r
- mainchain.isVisible = true;\r
- mainchain.makeExactMapping(maxAlignseq, sequence);\r
-\r
- this.pdb = pdb;\r
- this.prefsize = new Dimension(getWidth(), getHeight());\r
-\r
- //Initialize the matrices to identity\r
- for (int i = 0; i < 3; i++) {\r
- for (int j = 0; j < 3; j++) {\r
- if (i != j) {\r
- idmat.addElement(i, j, 0);\r
- objmat.addElement(i, j, 0);\r
- } else {\r
- idmat.addElement(i, j, 1);\r
- objmat.addElement(i, j, 1);\r
- }\r
- }\r
- }\r
-\r
- addMouseMotionListener(this);\r
- addMouseListener(this);\r
-\r
- addMouseWheelListener(new MouseWheelListener()\r
- {\r
- public void mouseWheelMoved(MouseWheelEvent e)\r
- {\r
- if (e.getWheelRotation() > 0)\r
- {\r
- scale = (float) (scale * 1.1);\r
- redrawneeded = true;\r
- repaint();\r
- }\r
-\r
- else\r
- {\r
- scale = (float) (scale * 0.9);\r
- redrawneeded = true;\r
- repaint();\r
- }\r
- }\r
- });\r
-\r
-\r
- findCentre();\r
- findWidth();\r
-\r
- setupBonds();\r
-\r
- scale = findScale();\r
-\r
- ToolTipManager.sharedInstance().registerComponent(this);\r
- ToolTipManager.sharedInstance().setInitialDelay(0);\r
- ToolTipManager.sharedInstance().setDismissDelay(10000);\r
- }\r
-\r
-\r
- Vector visiblebonds;\r
- void setupBonds()\r
- {\r
- seqColoursReady = false;\r
- // Sort the bonds by z coord\r
- visiblebonds = new Vector();\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)\r
- {\r
- Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < tmp.size(); i++)\r
- {\r
- visiblebonds.addElement(tmp.elementAt(i));\r
- }\r
- }\r
- }\r
-\r
- updateSeqColours();\r
- seqColoursReady = true;\r
- redrawneeded = true;\r
- repaint();\r
- }\r
-\r
-\r
- public void findWidth() {\r
- float[] max = new float[3];\r
- float[] min = new float[3];\r
-\r
- max[0] = (float) -1e30;\r
- max[1] = (float) -1e30;\r
- max[2] = (float) -1e30;\r
-\r
- min[0] = (float) 1e30;\r
- min[1] = (float) 1e30;\r
- min[2] = (float) 1e30;\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\r
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < bonds.size(); i++) {\r
- Bond tmp = (Bond) bonds.elementAt(i);\r
-\r
- if (tmp.start[0] >= max[0]) {\r
- max[0] = tmp.start[0];\r
- }\r
-\r
- if (tmp.start[1] >= max[1]) {\r
- max[1] = tmp.start[1];\r
- }\r
-\r
- if (tmp.start[2] >= max[2]) {\r
- max[2] = tmp.start[2];\r
- }\r
-\r
- if (tmp.start[0] <= min[0]) {\r
- min[0] = tmp.start[0];\r
- }\r
-\r
- if (tmp.start[1] <= min[1]) {\r
- min[1] = tmp.start[1];\r
- }\r
-\r
- if (tmp.start[2] <= min[2]) {\r
- min[2] = tmp.start[2];\r
- }\r
-\r
- if (tmp.end[0] >= max[0]) {\r
- max[0] = tmp.end[0];\r
- }\r
-\r
- if (tmp.end[1] >= max[1]) {\r
- max[1] = tmp.end[1];\r
- }\r
-\r
- if (tmp.end[2] >= max[2]) {\r
- max[2] = tmp.end[2];\r
- }\r
-\r
- if (tmp.end[0] <= min[0]) {\r
- min[0] = tmp.end[0];\r
- }\r
-\r
- if (tmp.end[1] <= min[1]) {\r
- min[1] = tmp.end[1];\r
- }\r
-\r
- if (tmp.end[2] <= min[2]) {\r
- min[2] = tmp.end[2];\r
- }\r
- }\r
- }\r
- }\r
- /*\r
- System.out.println("xmax " + max[0] + " min " + min[0]);\r
- System.out.println("ymax " + max[1] + " min " + min[1]);\r
- System.out.println("zmax " + max[2] + " min " + min[2]);*/\r
-\r
- width[0] = (float) Math.abs(max[0] - min[0]);\r
- width[1] = (float) Math.abs(max[1] - min[1]);\r
- width[2] = (float) Math.abs(max[2] - min[2]);\r
-\r
- maxwidth = width[0];\r
-\r
- if (width[1] > width[0]) {\r
- maxwidth = width[1];\r
- }\r
-\r
- if (width[2] > width[1]) {\r
- maxwidth = width[2];\r
- }\r
-\r
- // System.out.println("Maxwidth = " + maxwidth);\r
- }\r
-\r
- public float findScale() {\r
- int dim;\r
- int width;\r
- int height;\r
-\r
- if (getWidth() != 0) {\r
- width = getWidth();\r
- height = getHeight();\r
- } else {\r
- width = prefsize.width;\r
- height = prefsize.height;\r
- }\r
-\r
- if (width < height) {\r
- dim = width;\r
- } else {\r
- dim = height;\r
- }\r
-\r
- return (float) (dim / (1.5d * maxwidth));\r
- }\r
-\r
- public void findCentre() {\r
- float xtot = 0;\r
- float ytot = 0;\r
- float ztot = 0;\r
-\r
- int bsize = 0;\r
-\r
- //Find centre coordinate\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\r
- if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- bsize += bonds.size();\r
-\r
- for (int i = 0; i < bonds.size(); i++) {\r
- xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +\r
- ((Bond) bonds.elementAt(i)).end[0];\r
-\r
- ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +\r
- ((Bond) bonds.elementAt(i)).end[1];\r
-\r
- ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +\r
- ((Bond) bonds.elementAt(i)).end[2];\r
- }\r
- }\r
- }\r
-\r
- centre[0] = xtot / (2 * (float) bsize);\r
- centre[1] = ytot / (2 * (float) bsize);\r
- centre[2] = ztot / (2 * (float) bsize);\r
- }\r
-\r
- public void paintComponent(Graphics g)\r
- {\r
- super.paintComponent(g);\r
-\r
- if(!seqColoursReady)\r
- {\r
- g.setColor(Color.black);\r
- g.setFont(new Font("Verdana", Font.BOLD, 14));\r
- g.drawString("Retrieving PDB data....", 20, getHeight()/2);\r
- return;\r
- }\r
-\r
-\r
- //Only create the image at the beginning -\r
- //this saves much memory usage\r
- if ((img == null)\r
- || (prefsize.width != getWidth())\r
- || (prefsize.height != getHeight()))\r
-\r
- {\r
- prefsize.width = getWidth();\r
- prefsize.height = getHeight();\r
-\r
- scale = findScale();\r
- img = createImage(prefsize.width, prefsize.height);\r
- ig = img.getGraphics();\r
- Graphics2D ig2 = (Graphics2D) ig;\r
-\r
- ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
- RenderingHints.VALUE_ANTIALIAS_ON);\r
-\r
- redrawneeded = true;\r
- }\r
-\r
-\r
- if (redrawneeded)\r
- {\r
- drawAll(ig, prefsize.width, prefsize.height);\r
- redrawneeded = false;\r
- }\r
-\r
- g.drawImage(img, 0, 0, this);\r
-\r
- pdbAction = false;\r
- }\r
-\r
- public void drawAll(Graphics g, int width, int height)\r
- {\r
- g.setColor(backgroundColour);\r
- g.fillRect(0, 0, width, height);\r
- drawScene(g);\r
- drawLabels(g);\r
- }\r
-\r
-\r
- public void updateSeqColours()\r
- {\r
- if(pdbAction)\r
- {\r
- return;\r
- }\r
-\r
- // System.out.println("update seq colours");\r
- if(bysequence && pdb!=null)\r
- {\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- colourBySequence( (PDBChain) pdb.chains.elementAt(ii));\r
- }\r
- }\r
-\r
- redrawneeded=true;\r
- repaint();\r
- }\r
-\r
- int findTrueIndex(int pos)\r
- {\r
- // returns the alignment position for a residue\r
- int j = sequence.getStart();\r
- int i = 0;\r
-\r
- while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))\r
- {\r
- if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))\r
- {\r
- j++;\r
- }\r
-\r
- i++;\r
- }\r
-\r
- if(i>1)\r
- i--;\r
-\r
- if ( (j == sequence.getEnd()) && (j < pos))\r
- {\r
- return sequence.getEnd() + 1;\r
- }\r
- else\r
- {\r
- return i;\r
- }\r
- }\r
-\r
- // This method has been taken out of PDBChain to allow\r
- // Applet and Application specific sequence renderers to be used\r
- void colourBySequence(PDBChain chain)\r
- {\r
- // System.out.println("colour by seq");\r
- boolean showFeatures = false;\r
- if(seqcanvas.getViewport().getShowSequenceFeatures())\r
- {\r
- showFeatures = true;\r
- if (fr == null)\r
- fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport());\r
-\r
- fr.transferSettings( seqcanvas.getFeatureRenderer() );\r
- }\r
-\r
- Bond tmp;\r
- for (int i = 0; i < chain.bonds.size(); i++)\r
- {\r
- tmp = (Bond) chain.bonds.elementAt(i);\r
-\r
- if(chain!=mainchain)\r
- continue;\r
-\r
- if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
- (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))\r
- {\r
- int index = findTrueIndex(tmp.at1.alignmentMapping);\r
- //sequence.findIndex(tmp.at1.alignmentMapping);\r
- if (index != -1)\r
- {\r
- tmp.startCol = seqcanvas.getSequenceRenderer().\r
- getResidueBoxColour( sequence, index);\r
-\r
- if(showFeatures)\r
- tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);\r
-\r
- if(tmp.startCol==null)\r
- tmp.startCol = Color.white;\r
- }\r
- }\r
-\r
- if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
- (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))\r
- {\r
-\r
- int index = findTrueIndex(tmp.at2.alignmentMapping);\r
- //sequence.findIndex( tmp.at2.alignmentMapping );\r
- if (index != -1)\r
- {\r
- tmp.endCol = seqcanvas.getSequenceRenderer().\r
- getResidueBoxColour( sequence, index);\r
-\r
- if(showFeatures)\r
- tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);\r
-\r
- if(tmp.endCol==null)\r
- tmp.endCol = Color.white;\r
- }\r
- }\r
- }\r
- }\r
-\r
-\r
- Zsort zsort;\r
- public void drawScene(Graphics g)\r
- {\r
- if (zbuffer)\r
- {\r
- if (zsort == null)\r
- zsort = new Zsort();\r
-\r
- zsort.Zsort(visiblebonds);\r
- }\r
-\r
- Bond tmpBond = null;\r
- for (int i = 0; i < visiblebonds.size(); i++)\r
- {\r
- tmpBond = (Bond) visiblebonds.elementAt(i);\r
-\r
- xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
- ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
- yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- xmid = (xend + xstart) / 2;\r
- ymid = (yend + ystart) / 2;\r
- if (depthcue && !bymolecule)\r
- {\r
- if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))\r
- {\r
-\r
- g.setColor(tmpBond.startCol.darker().darker());\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
- g.setColor(tmpBond.endCol.darker().darker());\r
- drawLine(g, xmid, ymid, xend, yend);\r
-\r
- }\r
- else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))\r
- {\r
- g.setColor(tmpBond.startCol.darker());\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
- g.setColor(tmpBond.endCol.darker());\r
- drawLine(g, xmid, ymid, xend, yend);\r
- }\r
- else\r
- {\r
- g.setColor(tmpBond.startCol);\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
-\r
- g.setColor(tmpBond.endCol);\r
- drawLine(g, xmid, ymid, xend, yend);\r
- }\r
- }\r
- else if (depthcue && bymolecule)\r
- {\r
- if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))\r
- {\r
- g.setColor(Color.green.darker().darker());\r
- drawLine(g, xstart, ystart, xend, yend);\r
- }\r
- else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))\r
- {\r
- g.setColor(Color.green.darker());\r
- drawLine(g, xstart, ystart, xend, yend);\r
- }\r
- else\r
- {\r
- g.setColor(Color.green);\r
- drawLine(g, xstart, ystart, xend, yend);\r
- }\r
- }\r
- else if (!depthcue && !bymolecule)\r
- {\r
- g.setColor(tmpBond.startCol);\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
- g.setColor(tmpBond.endCol);\r
- drawLine(g, xmid, ymid, xend, yend);\r
- }\r
- else\r
- {\r
- drawLine(g, xstart, ystart, xend, yend);\r
- }\r
-\r
- if (highlightBond1 != null && highlightBond1 == tmpBond)\r
- {\r
- g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter());\r
- drawLine(g, xmid, ymid, xend, yend);\r
- }\r
-\r
- if (highlightBond2 != null && highlightBond2 == tmpBond)\r
- {\r
- g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter());\r
- drawLine(g, xstart, ystart, xmid, ymid);\r
- }\r
-\r
- }\r
-\r
-\r
- }\r
-\r
- public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {\r
- if (!wire) {\r
- if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {\r
- g.drawLine(x1, y1, x2, y2);\r
- g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);\r
- g.drawLine(x1, y1 - 1, x2, y2 - 1);\r
- } else {\r
- g.setColor(g.getColor().brighter());\r
- g.drawLine(x1, y1, x2, y2);\r
- g.drawLine(x1 + 1, y1, x2 + 1, y2);\r
- g.drawLine(x1 - 1, y1, x2 - 1, y2);\r
- }\r
- } else {\r
- g.drawLine(x1, y1, x2, y2);\r
- }\r
- }\r
-\r
- public Dimension minimumsize() {\r
- return prefsize;\r
- }\r
-\r
- public Dimension preferredsize() {\r
- return prefsize;\r
- }\r
-\r
- public void keyPressed(KeyEvent evt)\r
- {\r
- if (evt.getKeyCode() == KeyEvent.VK_UP)\r
- {\r
- scale = (float) (scale * 1.1);\r
- redrawneeded = true;\r
- repaint();\r
- }\r
- else if (evt.getKeyCode() == KeyEvent.VK_DOWN)\r
- {\r
- scale = (float) (scale * 0.9);\r
- redrawneeded = true;\r
- repaint();\r
- }\r
- }\r
-\r
- public void mousePressed(MouseEvent e)\r
- {\r
- pdbAction = true;\r
- Atom fatom = findAtom(e.getX(), e.getY());\r
- if(fatom!=null)\r
- {\r
- fatom.isSelected = !fatom.isSelected;\r
-\r
- redrawneeded = true;\r
- repaint();\r
- if (foundchain != -1)\r
- {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
- if (chain == mainchain)\r
- {\r
- if (fatom.alignmentMapping != -1)\r
- {\r
- if (highlightRes == null)\r
- highlightRes = new Vector();\r
-\r
- if (highlightRes.contains(fatom.alignmentMapping+""))\r
- highlightRes.remove(fatom.alignmentMapping + "");\r
- else\r
- highlightRes.add(fatom.alignmentMapping + "");\r
- }\r
- }\r
- }\r
-\r
- }\r
- mx = e.getX();\r
- my = e.getY();\r
- omx = mx;\r
- omy = my;\r
- dragging = false;\r
- }\r
-\r
- public void mouseMoved(MouseEvent e)\r
- {\r
- pdbAction = true;\r
- if(highlightBond1!=null)\r
- {\r
- highlightBond1.at2.isSelected = false;\r
- highlightBond2.at1.isSelected = false;\r
- highlightBond1 = null;\r
- highlightBond2 = null;\r
- }\r
-\r
- Atom fatom = findAtom(e.getX(), e.getY());\r
-\r
- PDBChain chain = null;\r
- if(foundchain!=-1)\r
- {\r
- chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
- if(chain == mainchain)\r
- {\r
- highlightSeqcanvas( fatom.alignmentMapping );\r
- }\r
- }\r
-\r
- if (fatom != null)\r
- {\r
- this.setToolTipText(chain.id+":"+ fatom.resNumber+" "+ fatom.resName);\r
- } else\r
- {\r
- highlightSeqcanvas( -1);\r
- this.setToolTipText(null);\r
- }\r
- }\r
-\r
-\r
- void highlightSeqcanvas(int pos)\r
- {\r
- SearchResults searchResults = new SearchResults();\r
- if(highlightRes!=null)\r
- {\r
- for (int i = 0; i < highlightRes.size(); i++)\r
- {\r
- int a = Integer.parseInt(highlightRes.elementAt(\r
- i).toString())+1;\r
-\r
- searchResults.addResult(sequence, a, a);\r
- }\r
- }\r
-\r
- if(pos!=-1)\r
- {\r
- searchResults.addResult(sequence, pos+1, pos+1);\r
- }\r
-\r
- seqcanvas.highlightSearchResults(searchResults);\r
- }\r
-\r
-\r
- public void mouseClicked(MouseEvent e) { }\r
-\r
- public void mouseEntered(MouseEvent e) { }\r
-\r
- public void mouseExited(MouseEvent e) { }\r
-\r
- public void mouseDragged(MouseEvent evt)\r
- {\r
- int x = evt.getX();\r
- int y = evt.getY();\r
- mx = x;\r
- my = y;\r
-\r
-\r
- MCMatrix objmat = new MCMatrix(3, 3);\r
- objmat.setIdentity();\r
-\r
- if ((evt.getModifiers() & Event.META_MASK) != 0) {\r
- objmat.rotatez((float) ((mx - omx)));\r
- } else {\r
- objmat.rotatex((float) ((my - omy)));\r
- objmat.rotatey((float) ((omx - mx)));\r
- }\r
-\r
- //Alter the bonds\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < bonds.size(); i++) {\r
- Bond tmpBond = (Bond) bonds.elementAt(i);\r
-\r
- //Translate the bond so the centre is 0,0,0\r
- tmpBond.translate(-centre[0], -centre[1], -centre[2]);\r
-\r
- //Now apply the rotation matrix\r
- tmpBond.start = objmat.vectorMultiply(tmpBond.start);\r
- tmpBond.end = objmat.vectorMultiply(tmpBond.end);\r
-\r
- //Now translate back again\r
- tmpBond.translate(centre[0], centre[1], centre[2]);\r
- }\r
- }\r
-\r
- objmat = null;\r
-\r
- omx = mx;\r
- omy = my;\r
-\r
- dragging = true;\r
-\r
- redrawneeded = true;\r
-\r
- repaint();\r
- }\r
-\r
- public void mouseReleased(MouseEvent evt)\r
- {\r
- dragging = false;\r
- return;\r
- }\r
-\r
- void drawLabels(Graphics g) {\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
-\r
- if (chain.isVisible)\r
- {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < bonds.size(); i++)\r
- {\r
- Bond tmpBond = (Bond) bonds.elementAt(i);\r
-\r
- if (tmpBond.at1.isSelected)\r
- {\r
- labelAtom(g, tmpBond, 1);\r
- }\r
-\r
- if (tmpBond.at2.isSelected)\r
- {\r
-\r
- labelAtom(g, tmpBond, 2);\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- public void labelAtom(Graphics g, Bond b, int n) {\r
- g.setFont(font);\r
- g.setColor(Color.red);\r
- if (n == 1)\r
- {\r
- int xstart = (int) (((b.start[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
- int ystart = (int) (((b.start[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);\r
- }\r
-\r
- if (n == 2) {\r
- int xstart = (int) (((b.end[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
- int ystart = (int) (((b.end[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);\r
- }\r
- }\r
-\r
- int foundchain = -1;\r
- public Atom findAtom(int x, int y) {\r
- Atom fatom = null;\r
-\r
- foundchain = -1;\r
-\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
- int truex;\r
- Bond tmpBond=null;\r
-\r
- if (chain.isVisible)\r
- {\r
- Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;\r
-\r
- for (int i = 0; i < bonds.size(); i++)\r
- {\r
- tmpBond = (Bond) bonds.elementAt(i);\r
-\r
- truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
-\r
- if (Math.abs(truex - x) <= 2)\r
- {\r
- int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- if (Math.abs(truey - y) <= 2)\r
- {\r
- fatom = tmpBond.at1;\r
- foundchain = ii;\r
- break;\r
- }\r
- }\r
- }\r
-\r
- // Still here? Maybe its the last bond\r
-\r
- truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +\r
- (getWidth() / 2));\r
-\r
- if (Math.abs(truex - x) <= 2)\r
- {\r
- int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +\r
- (getHeight() / 2));\r
-\r
- if (Math.abs(truey - y) <= 2)\r
- {\r
- fatom = tmpBond.at2;\r
- foundchain = ii;\r
- break;\r
- }\r
- }\r
-\r
- }\r
-\r
- if (fatom != null) //)&& chain.ds != null)\r
- {\r
- chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
- }\r
- }\r
-\r
- return fatom;\r
- }\r
-\r
- Bond highlightBond1, highlightBond2;\r
- public void highlightRes(int ii)\r
- {\r
- if( !seqColoursReady )\r
- return;\r
-\r
- if (highlightRes != null\r
- && highlightRes.contains((ii-1) + ""))\r
- {\r
- return;\r
- }\r
-\r
- int index = -1;\r
- Bond tmpBond;\r
- for(index=0; index<mainchain.bonds.size(); index++)\r
- {\r
- tmpBond = (Bond) mainchain.bonds.elementAt(index);\r
- if (tmpBond.at1.alignmentMapping == ii - 1)\r
- {\r
- if (highlightBond1 != null)\r
- highlightBond1.at2.isSelected = false;\r
-\r
- if (highlightBond2 != null)\r
- highlightBond2.at1.isSelected = false;\r
-\r
- highlightBond1 = null;\r
- highlightBond2 = null;\r
-\r
- if (index > 0)\r
- {\r
- highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);\r
- highlightBond1.at2.isSelected = true;\r
- }\r
-\r
- if (index != mainchain.bonds.size())\r
- {\r
- highlightBond2 = (Bond) mainchain.bonds.elementAt(index);\r
- highlightBond2.at1.isSelected = true;\r
- }\r
-\r
- break;\r
- }\r
- }\r
-\r
- redrawneeded = true;\r
- repaint();\r
- }\r
-\r
- public void setAllchainsVisible(boolean b)\r
- {\r
- for (int ii = 0; ii < pdb.chains.size(); ii++)\r
- {\r
- PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);\r
- chain.isVisible = b;\r
- }\r
- mainchain.isVisible = true;\r
- findCentre();\r
- setupBonds();\r
- }\r
-}\r
+/*
+* Jalview - A Sequence Alignment Editor and Viewer
+* Copyright (C) 2006 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 jalview.analysis.AlignSeq;
+
+import jalview.datamodel.*;
+
+// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug
+import java.awt.*;
+import java.awt.event.*;
+
+import java.io.*;
+
+import java.util.*;
+
+import javax.swing.*;
+
+
+public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListener
+{
+ MCMatrix idmat = new MCMatrix(3, 3);
+ MCMatrix objmat = new MCMatrix(3, 3);
+ boolean redrawneeded = true;
+ int omx = 0;
+ int mx = 0;
+ int omy = 0;
+ int my = 0;
+ public PDBfile pdb;
+ int bsize;
+ Image img;
+ Graphics ig;
+ Dimension prefsize;
+ float[] centre = new float[3];
+ float[] width = new float[3];
+ float maxwidth;
+ float scale;
+ String inStr;
+ String inType;
+ boolean bysequence = true;
+ boolean depthcue = true;
+ boolean wire = false;
+ boolean bymolecule = false;
+ boolean zbuffer = true;
+ boolean dragging;
+ int xstart;
+ int xend;
+ int ystart;
+ int yend;
+ int xmid;
+ int ymid;
+ Font font = new Font("Helvetica", Font.PLAIN, 10);
+ jalview.gui.SeqCanvas seqcanvas;
+ public Sequence sequence;
+ final StringBuffer mappingDetails = new StringBuffer();
+ PDBChain mainchain;
+ Vector highlightRes;
+ boolean pdbAction = false;
+ boolean seqColoursReady = false;
+ jalview.gui.FeatureRenderer fr;
+ Color backgroundColour = Color.black;
+
+ public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq)
+ {
+ this.seqcanvas = seqcanvas;
+ this.sequence = seq;
+ seqcanvas.setPDBCanvas(this);
+ }
+
+ public void setPDBFile(PDBfile pdb)
+ {
+ int max = -10;
+ int maxchain = -1;
+ int pdbstart = 0;
+ int pdbend = 0;
+ int seqstart = 0;
+ int seqend = 0;
+ AlignSeq maxAlignseq = null;
+
+ for (int i = 0; i < pdb.chains.size(); i++)
+ {
+
+ mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequenceAsString());
+ mappingDetails.append("\nNo of residues = " + ((PDBChain) pdb.chains.elementAt(i)).residues.size()+"\n\n");
+
+ // Now lets compare the sequences to get
+ // the start and end points.
+ // Align the sequence to the pdb
+ AlignSeq as = new AlignSeq(sequence,
+ ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep");
+ as.calcScoreMatrix();
+ as.traceAlignment();
+ PrintStream ps = new PrintStream(System.out)
+ {
+ public void print(String x) {
+ mappingDetails.append(x);
+ }
+ public void println()
+ {
+ mappingDetails.append("\n");
+ }
+ };
+
+ as.printAlignment(ps);
+
+
+
+ if (as.maxscore > max)
+ {
+ max = as.maxscore;
+ maxchain = i;
+ pdbstart = as.seq2start;
+ pdbend = as.seq2end;
+ seqstart = as.seq1start + sequence.getStart()-1;
+ seqend = as.seq1end + sequence.getEnd()-1;
+ maxAlignseq = as;
+ }
+
+ mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
+ mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend);
+ }
+
+ mainchain = (PDBChain) pdb.chains.elementAt(maxchain);
+
+ mainchain.pdbstart = pdbstart;
+ mainchain.pdbend = pdbend;
+ mainchain.seqstart = seqstart;
+ mainchain.seqend = seqend;
+ mainchain.isVisible = true;
+ mainchain.makeExactMapping(maxAlignseq, sequence);
+
+ this.pdb = pdb;
+ this.prefsize = new Dimension(getWidth(), getHeight());
+
+ //Initialize the matrices to identity
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ if (i != j) {
+ idmat.addElement(i, j, 0);
+ objmat.addElement(i, j, 0);
+ } else {
+ idmat.addElement(i, j, 1);
+ objmat.addElement(i, j, 1);
+ }
+ }
+ }
+
+ addMouseMotionListener(this);
+ addMouseListener(this);
+
+ addMouseWheelListener(new MouseWheelListener()
+ {
+ public void mouseWheelMoved(MouseWheelEvent e)
+ {
+ if (e.getWheelRotation() > 0)
+ {
+ scale = (float) (scale * 1.1);
+ redrawneeded = true;
+ repaint();
+ }
+
+ else
+ {
+ scale = (float) (scale * 0.9);
+ redrawneeded = true;
+ repaint();
+ }
+ }
+ });
+
+
+ findCentre();
+ findWidth();
+
+ setupBonds();
+
+ scale = findScale();
+
+ ToolTipManager.sharedInstance().registerComponent(this);
+ ToolTipManager.sharedInstance().setInitialDelay(0);
+ ToolTipManager.sharedInstance().setDismissDelay(10000);
+ }
+
+
+ Vector visiblebonds;
+ void setupBonds()
+ {
+ seqColoursReady = false;
+ // Sort the bonds by z coord
+ visiblebonds = new Vector();
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible)
+ {
+ Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < tmp.size(); i++)
+ {
+ visiblebonds.addElement(tmp.elementAt(i));
+ }
+ }
+ }
+
+ updateSeqColours();
+ seqColoursReady = true;
+ redrawneeded = true;
+ repaint();
+ }
+
+
+ public void findWidth() {
+ float[] max = new float[3];
+ float[] min = new float[3];
+
+ max[0] = (float) -1e30;
+ max[1] = (float) -1e30;
+ max[2] = (float) -1e30;
+
+ min[0] = (float) 1e30;
+ min[1] = (float) 1e30;
+ min[2] = (float) 1e30;
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++) {
+ Bond tmp = (Bond) bonds.elementAt(i);
+
+ if (tmp.start[0] >= max[0]) {
+ max[0] = tmp.start[0];
+ }
+
+ if (tmp.start[1] >= max[1]) {
+ max[1] = tmp.start[1];
+ }
+
+ if (tmp.start[2] >= max[2]) {
+ max[2] = tmp.start[2];
+ }
+
+ if (tmp.start[0] <= min[0]) {
+ min[0] = tmp.start[0];
+ }
+
+ if (tmp.start[1] <= min[1]) {
+ min[1] = tmp.start[1];
+ }
+
+ if (tmp.start[2] <= min[2]) {
+ min[2] = tmp.start[2];
+ }
+
+ if (tmp.end[0] >= max[0]) {
+ max[0] = tmp.end[0];
+ }
+
+ if (tmp.end[1] >= max[1]) {
+ max[1] = tmp.end[1];
+ }
+
+ if (tmp.end[2] >= max[2]) {
+ max[2] = tmp.end[2];
+ }
+
+ if (tmp.end[0] <= min[0]) {
+ min[0] = tmp.end[0];
+ }
+
+ if (tmp.end[1] <= min[1]) {
+ min[1] = tmp.end[1];
+ }
+
+ if (tmp.end[2] <= min[2]) {
+ min[2] = tmp.end[2];
+ }
+ }
+ }
+ }
+ /*
+ System.out.println("xmax " + max[0] + " min " + min[0]);
+ System.out.println("ymax " + max[1] + " min " + min[1]);
+ System.out.println("zmax " + max[2] + " min " + min[2]);*/
+
+ width[0] = (float) Math.abs(max[0] - min[0]);
+ width[1] = (float) Math.abs(max[1] - min[1]);
+ width[2] = (float) Math.abs(max[2] - min[2]);
+
+ maxwidth = width[0];
+
+ if (width[1] > width[0]) {
+ maxwidth = width[1];
+ }
+
+ if (width[2] > width[1]) {
+ maxwidth = width[2];
+ }
+
+ // System.out.println("Maxwidth = " + maxwidth);
+ }
+
+ public float findScale() {
+ int dim;
+ int width;
+ int height;
+
+ if (getWidth() != 0) {
+ width = getWidth();
+ height = getHeight();
+ } else {
+ width = prefsize.width;
+ height = prefsize.height;
+ }
+
+ if (width < height) {
+ dim = width;
+ } else {
+ dim = height;
+ }
+
+ return (float) (dim / (1.5d * maxwidth));
+ }
+
+ public void findCentre() {
+ float xtot = 0;
+ float ytot = 0;
+ float ztot = 0;
+
+ int bsize = 0;
+
+ //Find centre coordinate
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ bsize += bonds.size();
+
+ for (int i = 0; i < bonds.size(); i++) {
+ xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] +
+ ((Bond) bonds.elementAt(i)).end[0];
+
+ ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] +
+ ((Bond) bonds.elementAt(i)).end[1];
+
+ ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] +
+ ((Bond) bonds.elementAt(i)).end[2];
+ }
+ }
+ }
+
+ centre[0] = xtot / (2 * (float) bsize);
+ centre[1] = ytot / (2 * (float) bsize);
+ centre[2] = ztot / (2 * (float) bsize);
+ }
+
+ public void paintComponent(Graphics g)
+ {
+ super.paintComponent(g);
+
+ if(!seqColoursReady)
+ {
+ g.setColor(Color.black);
+ g.setFont(new Font("Verdana", Font.BOLD, 14));
+ g.drawString("Retrieving PDB data....", 20, getHeight()/2);
+ return;
+ }
+
+
+ //Only create the image at the beginning -
+ //this saves much memory usage
+ if ((img == null)
+ || (prefsize.width != getWidth())
+ || (prefsize.height != getHeight()))
+
+ {
+ prefsize.width = getWidth();
+ prefsize.height = getHeight();
+
+ scale = findScale();
+ img = createImage(prefsize.width, prefsize.height);
+ ig = img.getGraphics();
+ Graphics2D ig2 = (Graphics2D) ig;
+
+ ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ redrawneeded = true;
+ }
+
+
+ if (redrawneeded)
+ {
+ drawAll(ig, prefsize.width, prefsize.height);
+ redrawneeded = false;
+ }
+
+ g.drawImage(img, 0, 0, this);
+
+ pdbAction = false;
+ }
+
+ public void drawAll(Graphics g, int width, int height)
+ {
+ g.setColor(backgroundColour);
+ g.fillRect(0, 0, width, height);
+ drawScene(g);
+ drawLabels(g);
+ }
+
+
+ public void updateSeqColours()
+ {
+ if(pdbAction)
+ {
+ return;
+ }
+
+ // System.out.println("update seq colours");
+ if(bysequence && pdb!=null)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ colourBySequence( (PDBChain) pdb.chains.elementAt(ii));
+ }
+ }
+
+ redrawneeded=true;
+ repaint();
+ }
+
+ int findTrueIndex(int pos)
+ {
+ // returns the alignment position for a residue
+ int j = sequence.getStart();
+ int i = 0;
+
+ while ( (i < sequence.getLength()) && (j <= sequence.getEnd()) && (j <= pos+1))
+ {
+ if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))
+ {
+ j++;
+ }
+
+ i++;
+ }
+
+ if(i>1)
+ i--;
+
+ if ( (j == sequence.getEnd()) && (j < pos))
+ {
+ return sequence.getEnd() + 1;
+ }
+ else
+ {
+ return i;
+ }
+ }
+
+ // This method has been taken out of PDBChain to allow
+ // Applet and Application specific sequence renderers to be used
+ void colourBySequence(PDBChain chain)
+ {
+ // System.out.println("colour by seq");
+ boolean showFeatures = false;
+ if(seqcanvas.getViewport().getShowSequenceFeatures())
+ {
+ showFeatures = true;
+ if (fr == null)
+ fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport());
+
+ fr.transferSettings( seqcanvas.getFeatureRenderer() );
+ }
+
+ Bond tmp;
+ for (int i = 0; i < chain.bonds.size(); i++)
+ {
+ tmp = (Bond) chain.bonds.elementAt(i);
+
+ if(chain!=mainchain)
+ continue;
+
+ if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
+ (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))
+ {
+ int index = findTrueIndex(tmp.at1.alignmentMapping);
+ //sequence.findIndex(tmp.at1.alignmentMapping);
+ if (index != -1)
+ {
+ tmp.startCol = seqcanvas.getSequenceRenderer().
+ getResidueBoxColour( sequence, index);
+
+ if(showFeatures)
+ tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
+
+ if(tmp.startCol==null)
+ tmp.startCol = Color.white;
+ }
+ }
+
+ if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
+ (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))
+ {
+
+ int index = findTrueIndex(tmp.at2.alignmentMapping);
+ //sequence.findIndex( tmp.at2.alignmentMapping );
+ if (index != -1)
+ {
+ tmp.endCol = seqcanvas.getSequenceRenderer().
+ getResidueBoxColour( sequence, index);
+
+ if(showFeatures)
+ tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);
+
+ if(tmp.endCol==null)
+ tmp.endCol = Color.white;
+ }
+ }
+ }
+ }
+
+
+ Zsort zsort;
+ public void drawScene(Graphics g)
+ {
+ if (zbuffer)
+ {
+ if (zsort == null)
+ zsort = new Zsort();
+
+ zsort.Zsort(visiblebonds);
+ }
+
+ Bond tmpBond = null;
+ for (int i = 0; i < visiblebonds.size(); i++)
+ {
+ tmpBond = (Bond) visiblebonds.elementAt(i);
+
+ xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+ ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+ yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ xmid = (xend + xstart) / 2;
+ ymid = (yend + ystart) / 2;
+ if (depthcue && !bymolecule)
+ {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
+ {
+
+ g.setColor(tmpBond.startCol.darker().darker());
+ drawLine(g, xstart, ystart, xmid, ymid);
+ g.setColor(tmpBond.endCol.darker().darker());
+ drawLine(g, xmid, ymid, xend, yend);
+
+ }
+ else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))
+ {
+ g.setColor(tmpBond.startCol.darker());
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol.darker());
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+ else
+ {
+ g.setColor(tmpBond.startCol);
+ drawLine(g, xstart, ystart, xmid, ymid);
+
+ g.setColor(tmpBond.endCol);
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+ }
+ else if (depthcue && bymolecule)
+ {
+ if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
+ {
+ g.setColor(Color.green.darker().darker());
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+ else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))
+ {
+ g.setColor(Color.green.darker());
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+ else
+ {
+ g.setColor(Color.green);
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+ }
+ else if (!depthcue && !bymolecule)
+ {
+ g.setColor(tmpBond.startCol);
+ drawLine(g, xstart, ystart, xmid, ymid);
+ g.setColor(tmpBond.endCol);
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+ else
+ {
+ drawLine(g, xstart, ystart, xend, yend);
+ }
+
+ if (highlightBond1 != null && highlightBond1 == tmpBond)
+ {
+ g.setColor(tmpBond.endCol.brighter().brighter().brighter().brighter());
+ drawLine(g, xmid, ymid, xend, yend);
+ }
+
+ if (highlightBond2 != null && highlightBond2 == tmpBond)
+ {
+ g.setColor(tmpBond.startCol.brighter().brighter().brighter().brighter());
+ drawLine(g, xstart, ystart, xmid, ymid);
+ }
+
+ }
+
+
+ }
+
+ public void drawLine(Graphics g, int x1, int y1, int x2, int y2) {
+ if (!wire) {
+ if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) {
+ g.drawLine(x1, y1, x2, y2);
+ g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1);
+ g.drawLine(x1, y1 - 1, x2, y2 - 1);
+ } else {
+ g.setColor(g.getColor().brighter());
+ g.drawLine(x1, y1, x2, y2);
+ g.drawLine(x1 + 1, y1, x2 + 1, y2);
+ g.drawLine(x1 - 1, y1, x2 - 1, y2);
+ }
+ } else {
+ g.drawLine(x1, y1, x2, y2);
+ }
+ }
+
+ public Dimension minimumsize() {
+ return prefsize;
+ }
+
+ public Dimension preferredsize() {
+ return prefsize;
+ }
+
+ public void keyPressed(KeyEvent evt)
+ {
+ if (evt.getKeyCode() == KeyEvent.VK_UP)
+ {
+ scale = (float) (scale * 1.1);
+ redrawneeded = true;
+ repaint();
+ }
+ else if (evt.getKeyCode() == KeyEvent.VK_DOWN)
+ {
+ scale = (float) (scale * 0.9);
+ redrawneeded = true;
+ repaint();
+ }
+ }
+
+ public void mousePressed(MouseEvent e)
+ {
+ pdbAction = true;
+ Atom fatom = findAtom(e.getX(), e.getY());
+ if(fatom!=null)
+ {
+ fatom.isSelected = !fatom.isSelected;
+
+ redrawneeded = true;
+ repaint();
+ if (foundchain != -1)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ if (chain == mainchain)
+ {
+ if (fatom.alignmentMapping != -1)
+ {
+ if (highlightRes == null)
+ highlightRes = new Vector();
+
+ if (highlightRes.contains(fatom.alignmentMapping+""))
+ highlightRes.remove(fatom.alignmentMapping + "");
+ else
+ highlightRes.add(fatom.alignmentMapping + "");
+ }
+ }
+ }
+
+ }
+ mx = e.getX();
+ my = e.getY();
+ omx = mx;
+ omy = my;
+ dragging = false;
+ }
+
+ public void mouseMoved(MouseEvent e)
+ {
+ pdbAction = true;
+ if(highlightBond1!=null)
+ {
+ highlightBond1.at2.isSelected = false;
+ highlightBond2.at1.isSelected = false;
+ highlightBond1 = null;
+ highlightBond2 = null;
+ }
+
+ Atom fatom = findAtom(e.getX(), e.getY());
+
+ PDBChain chain = null;
+ if(foundchain!=-1)
+ {
+ chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ if(chain == mainchain)
+ {
+ highlightSeqcanvas( fatom.alignmentMapping );
+ }
+ }
+
+ if (fatom != null)
+ {
+ this.setToolTipText(chain.id+":"+ fatom.resNumber+" "+ fatom.resName);
+ } else
+ {
+ highlightSeqcanvas( -1);
+ this.setToolTipText(null);
+ }
+ }
+
+
+ void highlightSeqcanvas(int pos)
+ {
+ SearchResults searchResults = new SearchResults();
+ if(highlightRes!=null)
+ {
+ for (int i = 0; i < highlightRes.size(); i++)
+ {
+ int a = Integer.parseInt(highlightRes.elementAt(
+ i).toString())+1;
+
+ searchResults.addResult(sequence, a, a);
+ }
+ }
+
+ if(pos!=-1)
+ {
+ searchResults.addResult(sequence, pos+1, pos+1);
+ }
+
+ seqcanvas.highlightSearchResults(searchResults);
+ }
+
+
+ public void mouseClicked(MouseEvent e) { }
+
+ public void mouseEntered(MouseEvent e) { }
+
+ public void mouseExited(MouseEvent e) { }
+
+ public void mouseDragged(MouseEvent evt)
+ {
+ int x = evt.getX();
+ int y = evt.getY();
+ mx = x;
+ my = y;
+
+
+ MCMatrix objmat = new MCMatrix(3, 3);
+ objmat.setIdentity();
+
+ if ((evt.getModifiers() & Event.META_MASK) != 0) {
+ objmat.rotatez((float) ((mx - omx)));
+ } else {
+ objmat.rotatex((float) ((my - omy)));
+ objmat.rotatey((float) ((omx - mx)));
+ }
+
+ //Alter the bonds
+ for (int ii = 0; ii < pdb.chains.size(); ii++) {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++) {
+ Bond tmpBond = (Bond) bonds.elementAt(i);
+
+ //Translate the bond so the centre is 0,0,0
+ tmpBond.translate(-centre[0], -centre[1], -centre[2]);
+
+ //Now apply the rotation matrix
+ tmpBond.start = objmat.vectorMultiply(tmpBond.start);
+ tmpBond.end = objmat.vectorMultiply(tmpBond.end);
+
+ //Now translate back again
+ tmpBond.translate(centre[0], centre[1], centre[2]);
+ }
+ }
+
+ objmat = null;
+
+ omx = mx;
+ omy = my;
+
+ dragging = true;
+
+ redrawneeded = true;
+
+ repaint();
+ }
+
+ public void mouseReleased(MouseEvent evt)
+ {
+ dragging = false;
+ return;
+ }
+
+ void drawLabels(Graphics g) {
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+
+ if (chain.isVisible)
+ {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++)
+ {
+ Bond tmpBond = (Bond) bonds.elementAt(i);
+
+ if (tmpBond.at1.isSelected)
+ {
+ labelAtom(g, tmpBond, 1);
+ }
+
+ if (tmpBond.at2.isSelected)
+ {
+
+ labelAtom(g, tmpBond, 2);
+ }
+ }
+ }
+ }
+ }
+
+ public void labelAtom(Graphics g, Bond b, int n) {
+ g.setFont(font);
+ g.setColor(Color.red);
+ if (n == 1)
+ {
+ int xstart = (int) (((b.start[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+ int ystart = (int) (((b.start[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart);
+ }
+
+ if (n == 2) {
+ int xstart = (int) (((b.end[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+ int ystart = (int) (((b.end[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart);
+ }
+ }
+
+ int foundchain = -1;
+ public Atom findAtom(int x, int y) {
+ Atom fatom = null;
+
+ foundchain = -1;
+
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ int truex;
+ Bond tmpBond=null;
+
+ if (chain.isVisible)
+ {
+ Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds;
+
+ for (int i = 0; i < bonds.size(); i++)
+ {
+ tmpBond = (Bond) bonds.elementAt(i);
+
+ truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ if (Math.abs(truey - y) <= 2)
+ {
+ fatom = tmpBond.at1;
+ foundchain = ii;
+ break;
+ }
+ }
+ }
+
+ // Still here? Maybe its the last bond
+
+ truex = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
+ (getWidth() / 2));
+
+ if (Math.abs(truex - x) <= 2)
+ {
+ int truey = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
+ (getHeight() / 2));
+
+ if (Math.abs(truey - y) <= 2)
+ {
+ fatom = tmpBond.at2;
+ foundchain = ii;
+ break;
+ }
+ }
+
+ }
+
+ if (fatom != null) //)&& chain.ds != null)
+ {
+ chain = (PDBChain) pdb.chains.elementAt(foundchain);
+ }
+ }
+
+ return fatom;
+ }
+
+ Bond highlightBond1, highlightBond2;
+ public void highlightRes(int ii)
+ {
+ if( !seqColoursReady )
+ return;
+
+ if (highlightRes != null
+ && highlightRes.contains((ii-1) + ""))
+ {
+ return;
+ }
+
+ int index = -1;
+ Bond tmpBond;
+ for(index=0; index<mainchain.bonds.size(); index++)
+ {
+ tmpBond = (Bond) mainchain.bonds.elementAt(index);
+ if (tmpBond.at1.alignmentMapping == ii - 1)
+ {
+ if (highlightBond1 != null)
+ highlightBond1.at2.isSelected = false;
+
+ if (highlightBond2 != null)
+ highlightBond2.at1.isSelected = false;
+
+ highlightBond1 = null;
+ highlightBond2 = null;
+
+ if (index > 0)
+ {
+ highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
+ highlightBond1.at2.isSelected = true;
+ }
+
+ if (index != mainchain.bonds.size())
+ {
+ highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
+ highlightBond2.at1.isSelected = true;
+ }
+
+ break;
+ }
+ }
+
+ redrawneeded = true;
+ repaint();
+ }
+
+ public void setAllchainsVisible(boolean b)
+ {
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
+ {
+ PDBChain chain = (PDBChain) pdb.chains.elementAt(ii);
+ chain.isVisible = b;
+ }
+ mainchain.isVisible = true;
+ findCentre();
+ setupBonds();
+ }
+}
copiedSequences.append(seq.getName() + "\t" +
startRes + "\t" +
endRes + "\t" +
- seq.getSequence(sg.getStartRes(),
+ seq.getSequenceAsString(sg.getStartRes(),
sg.getEndRes() + 1) + "\n");
}
jalview.appletgui.AlignFrame.copiedSequences.append(sq.getName() + "\t" +
sq.getStart() + "\t" +
sq.getEnd() + "\t" +
- sq.getSequence() + "\n");
+ sq.getSequenceAsString() + "\n");
if (av.hasHiddenColumns)
{
jalview.appletgui.AlignFrame.copiedHiddenColumns=new Vector();
if (!gen_sgapped_s.getSequence().equals(s_gapped.getSequence()))
{
System.err.println("Couldn't reconstruct sequence.\n" +
- gen_sgapped_s.getSequence() + "\n" +
- s_gapped.getSequence());
+ gen_sgapped_s.getSequenceAsString() + "\n" +
+ s_gapped.getSequenceAsString());
return false;
}
return true;
+ "\nCigar String:" + sub_se_gp.getCigarstring() + "\n"
);
SequenceI ssgp = sub_se_gp.getSeq('-');
- System.out.println("\t " + ssgp.getSequence());
+ System.out.println("\t " + ssgp.getSequenceAsString());
for (int r = 0; r < 10; r++)
{
sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
System.out.println("" + al.getSequenceAt(i).getName() + "\t" +
al.getSequenceAt(i).getStart() + "\t" +
al.getSequenceAt(i).getEnd() + "\t" +
- al.getSequenceAt(i).getSequence());
+ al.getSequenceAt(i).getSequenceAsString());
}
}
// if (!ssgapedseq.equals("ryas---dtqqwa----slchvh"))