From 65bf1cd0ea1526762e829059bf6ae0901db9731d Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 10 Nov 2005 14:19:48 +0000 Subject: [PATCH] Add mapping details to stringbuffer --- src/MCview/PDBCanvas.java | 80 +++++++++++++++++++++++++++++---------------- src/MCview/PDBChain.java | 5 ++- src/MCview/PDBViewer.java | 37 +++++++++++++-------- src/MCview/PDBfile.java | 2 -- 4 files changed, 77 insertions(+), 47 deletions(-) diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index e9f8dce..ccb1643 100755 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -68,18 +68,22 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe Font font = new Font("Helvetica", Font.PLAIN, 10); jalview.gui.SequenceRenderer sr; jalview.gui.FeatureRenderer fr; + jalview.gui.SeqCanvas seqcanvas; + Sequence sequence; + final StringBuffer mappingDetails = new StringBuffer(); - public PDBCanvas() + public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq) { + this.seqcanvas = seqcanvas; + this.sequence = seq; + sr = seqcanvas.getSequenceRenderer(); + fr = seqcanvas.getFeatureRenderer(); + seqcanvas.setPDBViewer(this); } - public void setPDBFile(PDBfile pdb, Sequence sequence, - jalview.gui.SequenceRenderer sr, - jalview.gui.FeatureRenderer fr) + public void setPDBFile(PDBfile pdb) { - - this.sr = sr; this.fr = fr; int max = -10; @@ -89,7 +93,12 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe int seqstart = 0; int seqend = 0; - for (int i = 0; i < pdb.chains.size(); i++) { + for (int i = 0; i < pdb.chains.size(); i++) + { + + mappingDetails.append("\n\nPDB Sequence is :\nSequence = " + ((PDBChain) pdb.chains.elementAt(i)).sequence.getSequence()); + 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 @@ -97,8 +106,18 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep"); as.calcScoreMatrix(); as.traceAlignment(); - as.printAlignment(); - + 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; @@ -110,8 +129,8 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe seqend = as.seq1end + sequence.getEnd()-1; } - System.out.println("PDB start/end " + pdbstart + " " + pdbend); - System.out.println("SEQ start/end "+ seqstart + " " + seqend); + mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend); + mappingDetails.append("\nSEQ start/end "+ seqstart + " " + seqend); } ((PDBChain) pdb.chains.elementAt(maxchain)).pdbstart = pdbstart; @@ -145,7 +164,6 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe scale = findScale(); - System.out.println("Scale factor = " + scale); updateSeqColours(); ToolTipManager.sharedInstance().registerComponent(this); @@ -240,10 +258,10 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe } } } - + /* 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]); + 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]); @@ -259,7 +277,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe maxwidth = width[2]; } - System.out.println("Maxwidth = " + maxwidth); + // System.out.println("Maxwidth = " + maxwidth); } public float findScale() { @@ -318,12 +336,13 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe public void paintComponent(Graphics g) { + super.paintComponent(g); + if(pdb==null) { g.setColor(Color.black); g.setFont(new Font("Verdana", Font.BOLD, 14)); g.drawString("Retrieving PDB data....", 20, getHeight()/2); - return; } @@ -368,7 +387,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe public void updateSeqColours() { - if(bysequence) + if(bysequence && pdb!=null) { for (int ii = 0; ii < pdb.chains.size(); ii++) { @@ -487,7 +506,6 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe public void keyPressed(KeyEvent evt) { int key = evt.getKeyChar(); - System.out.println(key); if (evt.getKeyCode() == KeyEvent.VK_UP) { scale = (float) (scale * 1.1); @@ -521,6 +539,19 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe myAtom fatom = findAtom(e.getX(), e.getY()); + if(foundchain!=-1) + { + PDBChain chain = (PDBChain) pdb.chains.elementAt(foundchain); + 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}); + } + else + seqcanvas.highlightSearchResults(null); + if (fatom != null) { this.setToolTipText(fatom.resNumber+" "+ fatom.resName); } else { @@ -636,10 +667,11 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe } } + int foundchain = -1; public myAtom findAtom(int x, int y) { myAtom fatom = null; - int foundchain = -1; + foundchain = -1; for (int ii = 0; ii < pdb.chains.size(); ii++) { PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); @@ -661,6 +693,7 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe { fatom = tmpBond.at1; foundchain = ii; + break; } } } @@ -669,18 +702,9 @@ public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListe if (fatom != null) //)&& chain.ds != null) { chain = (PDBChain) pdb.chains.elementAt(foundchain); - - // SMJS TODO - // int tmp = chain.ds.seqstart + fatom.resNumber - chain.offset; - // int pos = chain.ds.findIndex(tmp); - // System.out.println("Found seq " + chain.ds.name + " " + tmp + " " + pos); } } return fatom; } - - public void update(Graphics g) { - paint(g); - } } diff --git a/src/MCview/PDBChain.java b/src/MCview/PDBChain.java index 86755dd..166e537 100755 --- a/src/MCview/PDBChain.java +++ b/src/MCview/PDBChain.java @@ -140,12 +140,11 @@ public class PDBChain { seq = seq + tmpres2; } - // System.out.println(tmpat.resName + " " + tmpres2); } sequence = new Sequence("PDB_seq", seq, 1, seq.length()); - System.out.println("PDB Sequence is :\nSequence = " + seq); - System.out.println("No of residues = " + residues.size()); + // System.out.println("PDB Sequence is :\nSequence = " + seq); + // System.out.println("No of residues = " + residues.size()); } public void setChargeColours() { diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 2610b40..49c1b11 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -19,7 +19,6 @@ public class PDBViewer extends JInternalFrame implements Runnable { PDBEntry pdb; Sequence sequence; - SeqCanvas seqcanvas; PDBCanvas pdbcanvas; @@ -29,8 +28,6 @@ public class PDBViewer extends JInternalFrame implements Runnable { pdb = entry; sequence = seq; - this.seqcanvas = seqcanvas; - try { @@ -41,7 +38,8 @@ public class PDBViewer extends JInternalFrame implements Runnable ex.printStackTrace(); } - pdbcanvas = new PDBCanvas(); + pdbcanvas = new PDBCanvas(seqcanvas, seq); + setContentPane(pdbcanvas); Desktop.addInternalFrame(this, sequence.getName() + ":" + pdb.getId() @@ -63,12 +61,8 @@ public class PDBViewer extends JInternalFrame implements Runnable PDBfile pdbfile = new PDBfile(result); - pdbcanvas.setPDBFile(pdbfile, - sequence, - seqcanvas.getSequenceRenderer(), - seqcanvas.getFeatureRenderer()); + pdbcanvas.setPDBFile(pdbfile); - seqcanvas.setPDBViewer(pdbcanvas); } catch (Exception ex) { @@ -83,7 +77,6 @@ public class PDBViewer extends JInternalFrame implements Runnable { public void keyPressed(KeyEvent evt) { - System.out.println("key press"); pdbcanvas.keyPressed(evt); } }); @@ -110,6 +103,13 @@ public class PDBViewer extends JInternalFrame implements Runnable } }); mapping.setText("View Mapping"); + mapping.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + mapping_actionPerformed(e); + } + }); wire.setText("Wireframe"); wire.addActionListener(new ActionListener() { @@ -337,6 +337,7 @@ public class PDBViewer extends JInternalFrame implements Runnable public void charge_actionPerformed(ActionEvent e) { + clearButtonGroup(); pdbcanvas.pdb.setChargeColours(); pdbcanvas.redrawneeded=true; pdbcanvas.repaint(); @@ -344,6 +345,7 @@ public class PDBViewer extends JInternalFrame implements Runnable public void hydro_actionPerformed(ActionEvent e) { + clearButtonGroup(); pdbcanvas.pdb.setHydrophobicityColours(); pdbcanvas.redrawneeded=true; pdbcanvas.repaint(); @@ -351,6 +353,7 @@ public class PDBViewer extends JInternalFrame implements Runnable public void chain_actionPerformed(ActionEvent e) { + clearButtonGroup(); pdbcanvas.pdb.setChainColours(); pdbcanvas.redrawneeded=true; pdbcanvas.repaint(); @@ -386,15 +389,21 @@ public class PDBViewer extends JInternalFrame implements Runnable public void seqButton_actionPerformed(ActionEvent e) { + clearButtonGroup(); pdbcanvas.bysequence = seqButton.isSelected(); pdbcanvas.updateSeqColours(); } void clearButtonGroup() { - charge.setSelected(false); - hydro.setSelected(false); - chain.setSelected(false); - seqButton.setSelected(false); + pdbcanvas.bysequence = false; + pdbcanvas.bymolecule = false; + } + + public void mapping_actionPerformed(ActionEvent e) + { + jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); + Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 500, 600); + cap.setText(pdbcanvas.mappingDetails.toString()); } } diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index ae1e4ec..8cbe37d 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -18,8 +18,6 @@ */ package MCview; -import jalview.datamodel.*; - import java.io.*; import java.net.*; -- 1.7.10.2