X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FPDBCanvas.java;h=17db1a0b26059f5fce1386a0c44c5609f84ba94b;hb=0712410094dece81fc8677d3a31fef6bac9d2b7d;hp=5ff0f1f5a8e1eafdc4cd9f5623e05509e06cbd61;hpb=9672f029a8731004f58fa3f1b78e4e0f62ad52c2;p=jalview.git diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index 5ff0f1f..17db1a0 100755 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -66,33 +66,29 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe int xmid; int ymid; Font font = new Font("Helvetica", Font.PLAIN, 10); - jalview.gui.SequenceRenderer sr; - jalview.gui.FeatureRenderer fr; jalview.gui.SeqCanvas seqcanvas; public Sequence sequence; final StringBuffer mappingDetails = new StringBuffer(); PDBChain mainchain; + Vector highlightRes; + boolean pdbAction = false; public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq) { this.seqcanvas = seqcanvas; this.sequence = seq; - sr = seqcanvas.getSequenceRenderer(); - fr = seqcanvas.getFeatureRenderer(); - seqcanvas.setPDBCanvas(this); } public void setPDBFile(PDBfile pdb) { - this.sr = sr; - this.fr = fr; 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++) { @@ -120,14 +116,17 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe as.printAlignment(ps); - if (as.maxscore > max) { + + + 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); @@ -141,7 +140,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe mainchain.seqstart = seqstart; mainchain.seqend = seqend; mainchain.isVisible = true; - mainchain.sequence = sequence; + mainchain.makeExactMapping(maxAlignseq, sequence); this.pdb = pdb; this.prefsize = new Dimension(getWidth(), getHeight()); @@ -182,46 +181,45 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe } }); - /* - SequenceGroup sg = new SequenceGroup("PDB", - null, true,true,false, - sequence.findIndex(seqstart-1), - sequence.findIndex(seqend-1)); - sg.addSequence(sequence, false); - sg.setOutlineColour(Color.black); - seqcanvas.getViewport().getAlignment().addGroup(sg); - */ findCentre(); findWidth(); - scale = findScale(); + setupBonds(); + scale = findScale(); - updateSeqColours(); ToolTipManager.sharedInstance().registerComponent(this); ToolTipManager.sharedInstance().setInitialDelay(0); ToolTipManager.sharedInstance().setDismissDelay(10000); - } - public void deleteBonds() { - scale = 0; - maxwidth = 0; - width[0] = 0; - width[1] = 0; - width[2] = 0; + Vector visiblebonds; + void setupBonds() + { + // Sort the bonds by z coord + visiblebonds = new Vector(); - centre[0] = 0; - centre[1] = 0; - centre[2] = 0; + 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 < pdb.chains.size(); i++) { - ((PDBChain) pdb.chains.elementAt(i)).bonds = null; + for (int i = 0; i < tmp.size(); i++) + { + visiblebonds.addElement(tmp.elementAt(i)); + } } + } + + updateSeqColours(); + redrawneeded = true; + repaint(); } + public void findWidth() { float[] max = new float[3]; float[] min = new float[3]; @@ -367,11 +365,11 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe centre[2] = ztot / (2 * (float) bsize); } - public void paintComponent(Graphics g) { - + public void paintComponent(Graphics g) + { super.paintComponent(g); - if(pdb==null) + if(visiblebonds==null) { g.setColor(Color.black); g.setFont(new Font("Verdana", Font.BOLD, 14)); @@ -382,8 +380,11 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe //Only create the image at the beginning - //this saves much memory usage - if ((img == null) || (prefsize.width != getWidth()) || - (prefsize.height != getHeight())) { + if ((img == null) + || (prefsize.width != getWidth()) + || (prefsize.height != getHeight())) + + { prefsize.width = getWidth(); prefsize.height = getHeight(); @@ -395,7 +396,6 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - redrawneeded = true; } @@ -407,6 +407,8 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe } g.drawImage(img, 0, 0, this); + + pdbAction = false; } public void drawAll(Graphics g, int width, int height) @@ -420,87 +422,115 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe 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) ); + 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"); 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 pos = chain.seqstart + - (tmp.at1.resNumber - chain.pdbstart - chain.offset); - - int index = sequence.findIndex(pos); - - tmp.startCol = sr.findSequenceColour(Color.lightGray, sequence, index); - - tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index); + int index = findTrueIndex(tmp.at1.alignmentMapping); + //sequence.findIndex(tmp.at1.alignmentMapping); + if (index != -1) + { + tmp.startCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour( sequence, index); + if(tmp.startCol==null) + tmp.startCol = Color.white; - } - else - { - tmp.startCol = Color.gray; + tmp.startCol = seqcanvas.getFeatureRenderer(). + findFeatureColour(tmp.startCol, sequence, index); + } } if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) && (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1))) { - int pos = chain.seqstart + - (tmp.at2.resNumber - chain.pdbstart - chain.offset); - int index = sequence.findIndex(pos); - tmp.endCol = sr.findSequenceColour(tmp.endCol, sequence, index); - tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index); - } - else - { - tmp.endCol = Color.gray; + int index = findTrueIndex(tmp.at2.alignmentMapping); + //sequence.findIndex( tmp.at2.alignmentMapping ); + if (index != -1) + { + tmp.endCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour( sequence, index); + if(tmp.endCol==null) + tmp.endCol = Color.white; + tmp.endCol = seqcanvas.getFeatureRenderer(). + findFeatureColour(tmp.endCol, sequence, index); + } } } } - public void drawScene(Graphics g) { - // Sort the bonds by z coord - Vector bonds = new Vector(); - - for (int ii = 0; ii < pdb.chains.size(); ii++) + public void drawScene(Graphics g) + { + if (zbuffer) { - if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) - { - Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; - - for (int i = 0; i < tmp.size(); i++) - { - bonds.addElement(tmp.elementAt(i)); - } - } - } - - if (zbuffer) { - Zsort.Zsort(bonds); + Zsort.Zsort(visiblebonds); } Bond tmpBond=null; - for (int i = 0; i < bonds.size(); i++) { - tmpBond = (Bond) bonds.elementAt(i); + for (int i = 0; i < visiblebonds.size(); i++) + { + tmpBond = (Bond) visiblebonds.elementAt(i); xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getWidth() / 2)); @@ -515,11 +545,11 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe xmid = (xend + xstart) / 2; ymid = (yend + ystart) / 2; - if (depthcue && !bymolecule) { + 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))) { @@ -613,13 +643,34 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe } } - public void mousePressed(MouseEvent e) { + 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(); @@ -628,7 +679,16 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe dragging = false; } - public void mouseMoved(MouseEvent e) { + 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()); @@ -638,43 +698,69 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe chain = (PDBChain) pdb.chains.elementAt(foundchain); if(chain == mainchain) { - int pos = chain.seqstart + - (fatom.resNumber - chain.pdbstart - chain.offset) + 1; - - int index = seqcanvas.getViewport().getAlignment().findIndex( - sequence); - - seqcanvas.highlightSearchResults(new int[] - {index, pos, pos}); + highlightSeqcanvas( fatom.alignmentMapping ); } } - else - seqcanvas.highlightSearchResults(null); if (fatom != null) { this.setToolTipText(chain.id+":"+ fatom.resNumber+" "+ fatom.resName); } else { - this.setToolTipText(""); + highlightSeqcanvas( -1); + this.setToolTipText(null); } } - public void mouseClicked(MouseEvent e) { - } - public void mouseEntered(MouseEvent e) { - } + void highlightSeqcanvas(int pos) + { + int index = seqcanvas.getViewport().getAlignment().findIndex(sequence); + + int size = pos==-1?0:3; - public void mouseExited(MouseEvent e) { + if(highlightRes!=null) + size += highlightRes.size()*3; + + int [] array = new int[size]; + int i=0; + if(highlightRes!=null) + { + for (i = 0; i < highlightRes.size(); i++) + { + int a = Integer.parseInt(highlightRes.elementAt( + i).toString())+1; + array[i * 3] = index; + array[ (i * 3) + 1] = a; + array[ (i * 3) + 2] = a; + } + } + + if(pos!=-1) + { + array[i * 3] = index; + array[i * 3 + 1] = pos+1; + array[i * 3 + 2] = pos+1; + } + + seqcanvas.highlightSearchResults(array); } - public void mouseDragged(MouseEvent evt) { + + 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(); @@ -716,7 +802,8 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe repaint(); } - public void mouseReleased(MouseEvent evt) { + public void mouseReleased(MouseEvent evt) + { dragging = false; return; } @@ -729,22 +816,22 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe if (chain.isVisible) { - Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; - for (int i = 0; i < bonds.size(); i++) - { - Bond tmpBond = (Bond) bonds.elementAt(i); + for (int i = 0; i < bonds.size(); i++) + { + Bond tmpBond = (Bond) bonds.elementAt(i); - if (tmpBond.at1.isSelected) - { - labelAtom(g, tmpBond, 1); - } + if (tmpBond.at1.isSelected) + { + labelAtom(g, tmpBond, 1); + } - if (tmpBond.at2.isSelected) - { + if (tmpBond.at2.isSelected) + { - labelAtom(g, tmpBond, 2); - } + labelAtom(g, tmpBond, 2); + } } } } @@ -752,14 +839,14 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe public void labelAtom(Graphics g, Bond b, int n) { g.setFont(font); - - if (n == 1) { + 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.setColor(Color.red); g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); } @@ -769,7 +856,6 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe int ystart = (int) (((b.end[1] - centre[1]) * scale) + (getHeight() / 2)); - g.setColor(Color.red); g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); } } @@ -843,23 +929,43 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe Bond highlightBond1, highlightBond2; public void highlightRes(int ii) { - highlightBond1 = null; - highlightBond2 = null; - int index = ii - mainchain.seqstart; - - if(index <0 ) + if (highlightRes != null + && highlightRes.contains((ii-1) + "")) + { return; + } - if(index<=mainchain.bonds.size()) + int index = -1; + Bond tmpBond; + for(index=0; index0) + tmpBond = (Bond) mainchain.bonds.elementAt(index); + if (tmpBond.at1.alignmentMapping == ii - 1) { - highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1); - } + if (highlightBond1 != null) + highlightBond1.at2.isSelected = false; + + if (highlightBond2 != null) + highlightBond2.at1.isSelected = false; + + highlightBond1 = null; + highlightBond2 = null; - if(index!=mainchain.bonds.size()) - highlightBond2 = (Bond) mainchain.bonds.elementAt(index); + 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; @@ -875,5 +981,6 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe } mainchain.isVisible = true; findCentre(); + setupBonds(); } }