public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener\r
{\r
\r
- MCMatrix idmat = new MCMatrix(3, 3);\r
+ MCMatrix idmat = new MCMatrix(3, 3);\r
MCMatrix objmat = new MCMatrix(3, 3);\r
boolean redrawneeded = true;\r
int omx = 0;\r
int xmid;\r
int ymid;\r
Font font = new Font("Helvetica", Font.PLAIN, 10);\r
- jalview.appletgui.SequenceRenderer sr;\r
- jalview.appletgui.FeatureRenderer fr;\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
\r
public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq)\r
{\r
this.seqcanvas = seqcanvas;\r
this.sequence = seq;\r
- sr = seqcanvas.getSequenceRenderer();\r
- fr = seqcanvas.getFeatureRenderer();\r
\r
seqcanvas.setPDBCanvas(this);\r
addKeyListener(new KeyAdapter()\r
});\r
}\r
\r
- Bond highlightBond1, highlightBond2;\r
- public void highlightRes(int ii)\r
- {\r
- highlightBond1 = null;\r
- highlightBond2 = null;\r
-\r
- int index = ii - mainchain.seqstart;\r
-\r
- System.out.println(ii+" "+mainchain.seqstart+" "+index);\r
-\r
- if(index <0 )\r
- return;\r
-\r
- if(index<=mainchain.bonds.size())\r
- {\r
- if(index>0)\r
- {\r
- highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);\r
- }\r
-\r
- if(index!=mainchain.bonds.size())\r
- highlightBond2 = (Bond) mainchain.bonds.elementAt(index);\r
- }\r
-\r
- redrawneeded = true;\r
- repaint();\r
- }\r
-\r
\r
public void setPDBFile(PDBfile pdb)\r
{\r
- this.sr = sr;\r
- this.fr = fr;\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
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
mainchain.seqstart = seqstart;\r
mainchain.seqend = seqend;\r
mainchain.isVisible = true;\r
- mainchain.sequence = sequence;\r
+ mainchain.makeExactMapping(maxAlignseq, sequence);\r
\r
this.pdb = pdb;\r
this.prefsize = new Dimension(getSize().width, getSize().height);\r
addMouseMotionListener(this);\r
addMouseListener(this);\r
\r
- /*\r
- SequenceGroup sg = new SequenceGroup("PDB",\r
- null, true,true,false,\r
- sequence.findIndex(seqstart-1),\r
- sequence.findIndex(seqend-1));\r
- sg.addSequence(sequence, false);\r
- sg.setOutlineColour(Color.black);\r
- seqcanvas.getViewport().getAlignment().addGroup(sg);\r
- */\r
\r
findCentre();\r
findWidth();\r
\r
+ setupBonds();\r
+\r
scale = findScale();\r
\r
updateSeqColours();\r
}\r
\r
- public void deleteBonds() {\r
- scale = 0;\r
- maxwidth = 0;\r
\r
- width[0] = 0;\r
- width[1] = 0;\r
- width[2] = 0;\r
+ Vector visiblebonds;\r
+ void setupBonds()\r
+ {\r
+ // Sort the bonds by z coord\r
+ visiblebonds = new Vector();\r
\r
- centre[0] = 0;\r
- centre[1] = 0;\r
- centre[2] = 0;\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 < pdb.chains.size(); i++) {\r
- ((PDBChain) pdb.chains.elementAt(i)).bonds = null;\r
+ for (int i = 0; i < tmp.size(); i++)\r
+ {\r
+ visiblebonds.addElement(tmp.elementAt(i));\r
+ }\r
}\r
+ }\r
}\r
\r
+\r
public void findWidth() {\r
float[] max = new float[3];\r
float[] min = new float[3];\r
public void paint(Graphics g)\r
{\r
\r
- if(pdb==null)\r
+ if(visiblebonds==null)\r
{\r
g.setColor(Color.black);\r
g.setFont(new Font("Verdana", Font.BOLD, 14));\r
\r
g.drawImage(img, 0, 0, this);\r
\r
-\r
+ pdbAction = false;\r
}\r
\r
public void drawAll(Graphics g, int width, int height)\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
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
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 pos = chain.seqstart +\r
- (tmp.at1.resNumber - chain.pdbstart - chain.offset);\r
-\r
- int index = sequence.findIndex(pos);\r
-\r
- if(jalview.util.Comparison.isGap((sequence.getCharAt(index))))\r
- {\r
- index--;\r
- }\r
-\r
- tmp.startCol = sr.findSequenceColour(sequence, index);\r
-\r
- // tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);\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
+ // tmp.startCol = seqcanvas.getFeatureRenderer().\r
+ // findFeatureColour(tmp.startCol, sequence, index);\r
+ }\r
}\r
- else\r
- {\r
- tmp.startCol = Color.gray;\r
- }\r
-\r
- if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&\r
- (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))\r
- {\r
- int pos = chain.seqstart +\r
- (tmp.at2.resNumber - chain.pdbstart - chain.offset);\r
- int index = sequence.findIndex(pos);\r
- if (jalview.util.Comparison.isGap( (sequence.getCharAt(index))))\r
- {\r
- index--;\r
- }\r
-\r
\r
- tmp.endCol = sr.findSequenceColour(sequence, index);\r
- // tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);\r
- }\r
- else\r
+ int index = findTrueIndex(tmp.at2.alignmentMapping);\r
+ //sequence.findIndex( tmp.at2.alignmentMapping );\r
+ if (index != -1)\r
{\r
- tmp.endCol = Color.gray;\r
+ tmp.endCol = seqcanvas.getSequenceRenderer().\r
+ getResidueBoxColour( sequence, index);\r
+ // tmp.endCol = seqcanvas.getFeatureRenderer().\r
+ // findFeatureColour(tmp.endCol, sequence, index);\r
}\r
}\r
}\r
\r
\r
- public void drawScene(Graphics g) {\r
- // Sort the bonds by z coord\r
- Vector bonds = 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
- bonds.addElement(tmp.elementAt(i));\r
- }\r
- }\r
- }\r
+ public void drawScene(Graphics g)\r
+ {\r
\r
if (zbuffer) {\r
- Zsort.Zsort(bonds);\r
+ Zsort.Zsort(visiblebonds);\r
}\r
\r
- for (int i = 0; i < bonds.size(); i++) {\r
- Bond tmpBond = (Bond) bonds.elementAt(i);\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
}\r
\r
public void mousePressed(MouseEvent e) {\r
- Atom fatom = findAtom(e.getX(), e.getY());\r
- if(fatom!=null)\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
- fatom.isSelected = !fatom.isSelected;\r
- redrawneeded = true;\r
- repaint();\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
}\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
chain = (PDBChain) pdb.chains.elementAt(foundchain);\r
if(chain == mainchain)\r
{\r
- int pos = chain.seqstart +\r
- (fatom.resNumber - chain.pdbstart - chain.offset) + 1;\r
-\r
- int index = seqcanvas.getViewport().getAlignment().findIndex(\r
- sequence);\r
-\r
- seqcanvas.highlightSearchResults(new int[]\r
- {index, pos, pos});\r
+ highlightSeqcanvas( fatom.alignmentMapping );\r
}\r
}\r
- else\r
- seqcanvas.highlightSearchResults(null);\r
\r
if (fatom != null) {\r
toolx = e.getX();\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
+ int index = seqcanvas.getViewport().getAlignment().findIndex(sequence);\r
+\r
+ int size = pos==-1?0:3;\r
+\r
+ if(highlightRes!=null)\r
+ size += highlightRes.size()*3;\r
+\r
+ int [] array = new int[size];\r
+ int i=0;\r
+ if(highlightRes!=null)\r
+ {\r
+ for (i = 0; i < highlightRes.size(); i++)\r
+ {\r
+ int a = Integer.parseInt(highlightRes.elementAt(\r
+ i).toString())+1;\r
+ array[i * 3] = index;\r
+ array[ (i * 3) + 1] = a;\r
+ array[ (i * 3) + 2] = a;\r
+ }\r
+ }\r
+\r
+ if(pos!=-1)\r
+ {\r
+ array[i * 3] = index;\r
+ array[i * 3 + 1] = pos+1;\r
+ array[i * 3 + 2] = pos+1;\r
+ }\r
+\r
+ seqcanvas.highlightSearchResults(array);\r
+ }\r
+\r
+\r
public void mouseClicked(MouseEvent e) {\r
}\r
\r
\r
foundchain = -1;\r
\r
- for (int ii = 0; ii < pdb.chains.size(); ii++) {\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
+ if (chain.isVisible)\r
+ {\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
+ for (int i = 0; i < bonds.size(); i++)\r
+ {\r
+ tmpBond = (Bond) bonds.elementAt(i);\r
\r
- int truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +\r
+ truex = (int) (((tmpBond.start[0] - centre[0]) * scale) +\r
(getSize().width / 2));\r
\r
- if (Math.abs(truex - x) <= 2) {\r
+ if (Math.abs(truex - x) <= 2)\r
+ {\r
int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) +\r
(getSize().height / 2));\r
\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
paint(g);\r
}\r
\r
+ public void highlightRes(int ii)\r
+ {\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
mainchain.isVisible = true;\r
findCentre();\r
+ setupBonds();\r
+ redrawneeded = true;\r
+ repaint();\r
+\r
}\r
\r
}\r