From: amwaterhouse Date: Wed, 30 Nov 2005 15:06:14 +0000 (+0000) Subject: Exact mapping for applet as well X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=19609f31cb839e3e86de561283fa1cdb508c6eae;p=jalview.git Exact mapping for applet as well --- diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index 7a6a368..bdef555 100755 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -35,7 +35,7 @@ import java.util.*; public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotionListener { - MCMatrix idmat = new MCMatrix(3, 3); + MCMatrix idmat = new MCMatrix(3, 3); MCMatrix objmat = new MCMatrix(3, 3); boolean redrawneeded = true; int omx = 0; @@ -66,21 +66,20 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion int xmid; int ymid; Font font = new Font("Helvetica", Font.PLAIN, 10); - jalview.appletgui.SequenceRenderer sr; - jalview.appletgui.FeatureRenderer fr; 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; public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq) { this.seqcanvas = seqcanvas; this.sequence = seq; - sr = seqcanvas.getSequenceRenderer(); - fr = seqcanvas.getFeatureRenderer(); seqcanvas.setPDBCanvas(this); addKeyListener(new KeyAdapter() @@ -93,45 +92,16 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion }); } - Bond highlightBond1, highlightBond2; - public void highlightRes(int ii) - { - highlightBond1 = null; - highlightBond2 = null; - - int index = ii - mainchain.seqstart; - - System.out.println(ii+" "+mainchain.seqstart+" "+index); - - if(index <0 ) - return; - - if(index<=mainchain.bonds.size()) - { - if(index>0) - { - highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1); - } - - if(index!=mainchain.bonds.size()) - highlightBond2 = (Bond) mainchain.bonds.elementAt(index); - } - - redrawneeded = true; - repaint(); - } - 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++) { @@ -167,6 +137,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion pdbend = as.seq2end; seqstart = as.seq1start + sequence.getStart()-1; seqend = as.seq1end + sequence.getEnd()-1; + maxAlignseq = as; } mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend); @@ -180,7 +151,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion mainchain.seqstart = seqstart; mainchain.seqend = seqend; mainchain.isVisible = true; - mainchain.sequence = sequence; + mainchain.makeExactMapping(maxAlignseq, sequence); this.pdb = pdb; this.prefsize = new Dimension(getSize().width, getSize().height); @@ -201,41 +172,39 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion addMouseMotionListener(this); addMouseListener(this); - /* - 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(); + setupBonds(); + scale = findScale(); updateSeqColours(); } - 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)); + } } + } } + public void findWidth() { float[] max = new float[3]; float[] min = new float[3]; @@ -380,7 +349,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion public void paint(Graphics g) { - if(pdb==null) + if(visiblebonds==null) { g.setColor(Color.black); g.setFont(new Font("Verdana", Font.BOLD, 14)); @@ -423,7 +392,7 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion g.drawImage(img, 0, 0, this); - + pdbAction = false; } public void drawAll(Graphics g, int width, int height) @@ -437,6 +406,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion public void updateSeqColours() { + if (pdbAction) + { + return; + } + if(bysequence && pdb!=null) { for (int ii = 0; ii < pdb.chains.size(); ii++) @@ -449,6 +423,37 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion 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) @@ -456,76 +461,52 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion 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); - - if(jalview.util.Comparison.isGap((sequence.getCharAt(index)))) - { - index--; - } - - tmp.startCol = sr.findSequenceColour(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); + // tmp.startCol = seqcanvas.getFeatureRenderer(). + // findFeatureColour(tmp.startCol, sequence, index); + } } - else - { - tmp.startCol = Color.gray; - } - - 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); - if (jalview.util.Comparison.isGap( (sequence.getCharAt(index)))) - { - index--; - } - - tmp.endCol = sr.findSequenceColour(sequence, index); - // tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index); - } - else + int index = findTrueIndex(tmp.at2.alignmentMapping); + //sequence.findIndex( tmp.at2.alignmentMapping ); + if (index != -1) { - tmp.endCol = Color.gray; + tmp.endCol = seqcanvas.getSequenceRenderer(). + getResidueBoxColour( sequence, index); + // 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++) - { - 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)); - } - } - } + public void drawScene(Graphics g) + { if (zbuffer) { - Zsort.Zsort(bonds); + Zsort.Zsort(visiblebonds); } - for (int i = 0; i < bonds.size(); i++) { - Bond tmpBond = (Bond) bonds.elementAt(i); + + Bond tmpBond=null; + for (int i = 0; i < visiblebonds.size(); i++) + { + tmpBond = (Bond) visiblebonds.elementAt(i); xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + @@ -639,12 +620,32 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion } public void mousePressed(MouseEvent e) { - Atom fatom = findAtom(e.getX(), e.getY()); - if(fatom!=null) + pdbAction = true; + Atom fatom = findAtom(e.getX(), e.getY()); + if(fatom!=null) + { + fatom.isSelected = !fatom.isSelected; + + redrawneeded = true; + repaint(); + if (foundchain != -1) { - fatom.isSelected = !fatom.isSelected; - redrawneeded = true; - repaint(); + 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(); @@ -654,6 +655,14 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion } 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()); @@ -663,18 +672,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion 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) { toolx = e.getX(); @@ -684,12 +684,48 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion redrawneeded = true; repaint(); } else { + highlightSeqcanvas( -1); appletToolTip = null; redrawneeded = true; repaint(); } } + + void highlightSeqcanvas(int pos) + { + int index = seqcanvas.getViewport().getAlignment().findIndex(sequence); + + int size = pos==-1?0:3; + + 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 mouseClicked(MouseEvent e) { } @@ -810,19 +846,25 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion foundchain = -1; - for (int ii = 0; ii < pdb.chains.size(); ii++) { + for (int ii = 0; ii < pdb.chains.size(); ii++) + { PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + int truex; + Bond tmpBond=null; - if (chain.isVisible) { + 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); + for (int i = 0; i < bonds.size(); i++) + { + tmpBond = (Bond) bonds.elementAt(i); - int truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + + truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + (getSize().width / 2)); - if (Math.abs(truex - x) <= 2) { + if (Math.abs(truex - x) <= 2) + { int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) + (getSize().height / 2)); @@ -834,6 +876,25 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion } } } + + // 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) @@ -850,6 +911,52 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion paint(g); } + public void highlightRes(int ii) + { + + if (highlightRes != null + && highlightRes.contains((ii-1) + "")) + { + return; + } + + int index = -1; + Bond tmpBond; + for(index=0; 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++) @@ -859,6 +966,10 @@ public class AppletPDBCanvas extends Panel implements MouseListener, MouseMotion } mainchain.isVisible = true; findCentre(); + setupBonds(); + redrawneeded = true; + repaint(); + } } diff --git a/src/MCview/AppletPDBViewer.java b/src/MCview/AppletPDBViewer.java index 1ed4d10..3f4e42c 100755 --- a/src/MCview/AppletPDBViewer.java +++ b/src/MCview/AppletPDBViewer.java @@ -117,14 +117,6 @@ public class AppletPDBViewer extends Frame seqButton_actionPerformed(); } }); - molecule.setLabel("By Molecule"); - molecule.addItemListener(new ItemListener() - { - public void itemStateChanged(ItemEvent e) - { - molecule_actionPerformed(); - } - }); allchains.setLabel("All Chains Visible"); allchains.addItemListener(new ItemListener() { @@ -141,7 +133,6 @@ public class AppletPDBViewer extends Frame coloursMenu.add(chain); coloursMenu.add(hydro); coloursMenu.add(charge); - coloursMenu.add(molecule); coloursMenu.addSeparator(); coloursMenu.add(wire); coloursMenu.add(depth); @@ -164,7 +155,6 @@ public class AppletPDBViewer extends Frame MenuItem chain = new MenuItem(); MenuItem seqButton = new MenuItem(); - CheckboxMenuItem molecule = new CheckboxMenuItem(); CheckboxMenuItem allchains = new CheckboxMenuItem(); public void charge_actionPerformed() @@ -198,13 +188,6 @@ public class AppletPDBViewer extends Frame pdbcanvas.repaint(); } - public void molecule_actionPerformed() - { - pdbcanvas.bymolecule = ! pdbcanvas.bymolecule; - pdbcanvas.redrawneeded=true; - pdbcanvas.repaint(); - } - public void depth_actionPerformed() { pdbcanvas.depthcue = ! pdbcanvas.depthcue;