import jalview.analysis.*;
import jalview.datamodel.*;
+import jalview.appletgui.*;
+import jalview.structure.*;
+
public class AppletPDBCanvas
- extends Panel implements MouseListener, MouseMotionListener
+ extends Panel implements MouseListener, MouseMotionListener, StructureListener
{
MCMatrix idmat = new MCMatrix(3, 3);
int omy = 0;
int my = 0;
public PDBfile pdb;
+ PDBEntry pdbentry;
int bsize;
Image img;
Graphics ig;
int xmid;
int ymid;
Font font = new Font("Helvetica", Font.PLAIN, 10);
- jalview.appletgui.SeqCanvas seqcanvas;
- public Sequence sequence;
+ public SequenceI [] sequence;
final StringBuffer mappingDetails = new StringBuffer();
String appletToolTip = null;
int toolx, tooly;
Bond highlightBond1, highlightBond2;
boolean errorLoading = false;
boolean seqColoursReady = false;
- jalview.appletgui.FeatureRenderer fr;
+ FeatureRenderer fr;
+ AlignmentPanel ap;
+ StructureSelectionManager ssm;
+
+ public AppletPDBCanvas(PDBEntry pdbentry,
+ SequenceI[] seq,
+ String [] chains,
+ AlignmentPanel ap,
+ String protocol)
- public AppletPDBCanvas(jalview.appletgui.SeqCanvas seqcanvas, Sequence seq)
{
- this.seqcanvas = seqcanvas;
+ this.ap = ap;
+ this.pdbentry = pdbentry;
this.sequence = seq;
- seqcanvas.setPDBCanvas(this);
- addKeyListener(new KeyAdapter()
+ ssm = StructureSelectionManager.getStructureSelectionManager();
+
+ try{
+ pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol);
+
+ if(protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
+ pdbentry.setFile("INLINE"+pdb.id);
+
+ }catch(Exception ex)
{
+ ex.printStackTrace();
+ return;
+ }
- public void keyPressed(KeyEvent evt)
- {
- doKeyPressed(evt);
- }
- });
- }
+ pdbentry.setId(pdb.id);
+
+ ssm.addStructureViewerListener(this);
+
+ colourBySequence();
- 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; ;
+
+ //JUST DEAL WITH ONE SEQUENCE FOR NOW
+ SequenceI sequence = seq[0];
for (int i = 0; i < pdb.chains.size(); i++)
{
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.seqstart = seqstart;
mainchain.seqend = seqend;
mainchain.isVisible = true;
- mainchain.makeExactMapping(maxAlignseq, sequence);
- mainchain.transferRESNUMFeatures(sequence, null);
+ // mainchain.makeExactMapping(maxAlignseq, sequence);
+ // mainchain.transferRESNUMFeatures(sequence, null);
this.pdb = pdb;
this.prefsize = new Dimension(getSize().width, getSize().height);
addMouseMotionListener(this);
addMouseListener(this);
+ addKeyListener(new KeyAdapter()
+ {
+ public void keyPressed(KeyEvent evt)
+ {
+ doKeyPressed(evt);
+ }
+ });
+
findCentre();
findWidth();
}
}
}
- updateSeqColours();
seqColoursReady = true;
+ colourBySequence();
redrawneeded = true;
repaint();
}
drawLabels(ig);
}
- void setColours(jalview.schemes.ColourSchemeI cs)
+ public void setColours(jalview.schemes.ColourSchemeI cs)
{
bysequence = false;
pdb.setColours(cs);
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)
+ void colourBySequence()
{
- boolean showFeatures = false;
+ SequenceRenderer sr = new SequenceRenderer(ap.av);
+
+ StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
- if (seqcanvas.getViewport().getShowSequenceFeatures())
+ boolean showFeatures = false;
+ if (ap.av.getShowSequenceFeatures())
{
if (fr == null)
{
- fr = new jalview.appletgui.FeatureRenderer(seqcanvas.getViewport());
+ fr = new jalview.appletgui.FeatureRenderer(ap.av);
}
- fr.transferSettings(seqcanvas.getFeatureRenderer());
+
+ fr.transferSettings(ap.getFeatureRenderer());
+
showFeatures = true;
}
- for (int i = 0; i < chain.bonds.size(); i++)
+ PDBChain chain;
+ if (bysequence && pdb != null)
{
- 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)))
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
{
+ chain = (PDBChain) pdb.chains.elementAt(ii);
- int index = findTrueIndex(tmp.at1.alignmentMapping);
- //sequence.findIndex(tmp.at1.alignmentMapping);
- if (index != -1)
+ for (int i = 0; i < chain.bonds.size(); i++)
{
- tmp.startCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour(sequence, index);
-
- if (showFeatures)
+ Bond tmp = (Bond) chain.bonds.elementAt(i);
+ tmp.startCol = Color.lightGray;
+ tmp.endCol = Color.lightGray;
+ if (chain != mainchain)
{
- tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
+ continue;
}
- }
- }
-
- 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);
+ for (int s = 0; s < sequence.length; s++)
+ {
+ for (int m = 0; m < mapping.length; m++)
+ {
+ if (mapping[m].getSequence() == sequence[s])
+ {
+ int pos = mapping[m].getSeqPos(tmp.at1.resNumber)-1;
+ if (pos > 0)
+ {
+ pos = sequence[s].findIndex(pos);
+ tmp.startCol = sr.getResidueBoxColour(sequence[s], pos);
+ if (showFeatures)
+ {
+ tmp.startCol = fr.findFeatureColour(tmp.startCol,
+ sequence[s],
+ pos);
+ }
+ }
+ pos = mapping[m].getSeqPos(tmp.at2.resNumber)-1;
+ if (pos > 0)
+ {
+ pos = sequence[s].findIndex(pos);
+ tmp.endCol = sr.getResidueBoxColour(sequence[s], pos);
+ if (showFeatures)
+ {
+ tmp.endCol = fr.findFeatureColour(tmp.endCol,
+ sequence[s],
+ pos);
+ }
+ }
+
+ }
+ }
+ }
}
}
}
xstart = (int) ( ( (tmpBond.start[0] - centre[0]) * scale) +
(getSize().width / 2));
- ystart = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) +
+ ystart = (int) ( ( (centre[1] - tmpBond.start[1] ) * scale) +
(getSize().height / 2));
xend = (int) ( ( (tmpBond.end[0] - centre[0]) * scale) +
(getSize().width / 2));
- yend = (int) ( ( (tmpBond.end[1] - centre[1]) * scale) +
+ yend = (int) ( ( (centre[1] - tmpBond.end[1] ) * scale) +
(getSize().height / 2));
xmid = (xend + xstart) / 2;
chain = (PDBChain) pdb.chains.elementAt(foundchain);
if (chain == mainchain)
{
- highlightSeqcanvas(fatom.alignmentMapping);
+ mouseOverStructure(fatom.resNumber, chain.id);
}
}
}
else
{
- highlightSeqcanvas( -1);
+ mouseOverStructure(-1, chain!=null?chain.id:null);
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)
{
}
}
else
{
- objmat.rotatex( (float) ( (my - omy)));
+ objmat.rotatex( (float) ( (omy - my)));
objmat.rotatey( (float) ( (omx - mx)));
}
{
int xstart = (int) ( ( (b.start[0] - centre[0]) * scale) +
(getSize().width / 2));
- int ystart = (int) ( ( (b.start[1] - centre[1]) * scale) +
+ int ystart = (int) ( ( (centre[1] - b.start[1]) * scale) +
(getSize().height / 2));
g.setColor(Color.red);
{
int xstart = (int) ( ( (b.end[0] - centre[0]) * scale) +
(getSize().width / 2));
- int ystart = (int) ( ( (b.end[1] - centre[1]) * scale) +
+ int ystart = (int) ( ( (centre[1] - b.end[1]) * scale) +
(getSize().height / 2));
g.setColor(Color.red);
if (Math.abs(truex - x) <= 2)
{
- int truey = (int) ( ( (tmpBond.start[1] - centre[1]) * scale) +
+ int truey = (int) ( ( (centre[1] - tmpBond.start[1] ) * scale) +
(getSize().height / 2));
if (Math.abs(truey - y) <= 2)
setupBonds();
}
+
+ //////////////////////////////////
+ ///StructureListener
+ public String getPdbFile()
+ {
+ return pdbentry.getFile();
+ }
+
+
+ String lastMessage;
+ public void mouseOverStructure(int pdbResNum, String chain)
+ {
+ if (lastMessage == null || !lastMessage.equals(pdbResNum+chain))
+ ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile());
+
+ lastMessage = pdbResNum+chain;
+ }
+
+ StringBuffer resetLastRes = new StringBuffer();
+ StringBuffer eval = new StringBuffer();
+
+ public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile)
+ {
+ if (!seqColoursReady)
+ {
+ return;
+ }
+
+ if (highlightRes != null
+ && highlightRes.contains( (atomIndex - 1) + ""))
+ {
+ return;
+ }
+
+ int index = -1;
+ Bond tmpBond;
+ for (index = 0; index < mainchain.bonds.size(); index++)
+ {
+ tmpBond = (Bond) mainchain.bonds.elementAt(index);
+ if (tmpBond.at1.atomIndex == atomIndex)
+ {
+ 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 Color getColour(int atomIndex, int pdbResNum, String chain, String pdbfile)
+ {
+ return Color.white;
+ // if (!pdbfile.equals(pdbentry.getFile()))
+ // return null;
+
+ //return new Color(viewer.getAtomArgb(atomIndex));
+ }
+
+ public void updateColours(Object source)
+ {
+ colourBySequence();
+ redrawneeded = true;
+ repaint();
+ }
+
+
}