From 2da92b61300307562cb8bec70a72f0b0527aa3b3 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 18 Feb 2011 17:15:36 +0000 Subject: [PATCH] call to release any explicit event handler references --- src/MCview/AppletPDBCanvas.java | 7 + src/MCview/PDBCanvas.java | 7 + src/jalview/appletgui/AppletJmol.java | 19 +- src/jalview/appletgui/AppletJmolBinding.java | 18 +- src/jalview/appletgui/ExtJmol.java | 16 +- src/jalview/ext/jmol/JalviewJmolBinding.java | 388 +++++++++++--------- .../javascript/MouseOverStructureListener.java | 6 + src/jalview/structure/StructureListener.java | 6 + 8 files changed, 291 insertions(+), 176 deletions(-) diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index 9939131..39d0926 100755 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -1192,4 +1192,11 @@ public class AppletPDBCanvas extends Panel implements MouseListener, repaint(); } + @Override + public void releaseReferences(Object svl) + { + // TODO Auto-generated method stub + + } + } diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index 23de254..f9461e1 100755 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -1157,4 +1157,11 @@ public class PDBCanvas extends JPanel implements MouseListener, repaint(); } + @Override + public void releaseReferences(Object svl) + { + // TODO Auto-generated method stub + + } + } diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 42e6f56..619d522 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -83,6 +83,7 @@ public class AppletJmol extends EmbmenuFrame implements RenderPanel renderPanel; AlignmentPanel ap; + ArrayList _aps = new ArrayList(); String fileLoadingError; @@ -489,7 +490,7 @@ public class AppletJmol extends EmbmenuFrame implements if (evt.getSource() == seqColour) { setEnabled(seqColour); - jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment); + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); } else if (!allChainsSelected) centerViewer(); @@ -517,7 +518,7 @@ public class AppletJmol extends EmbmenuFrame implements public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; - jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment); + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); } public void updateTitleAndMenus() @@ -528,7 +529,7 @@ public class AppletJmol extends EmbmenuFrame implements return; } setChainMenuItems(jmb.chainNames); - jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment); + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); setTitle(jmb.getViewerTitle()); } @@ -632,4 +633,16 @@ public class AppletJmol extends EmbmenuFrame implements { jmb.setJalviewColourScheme(ucs); } + + public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment) + { + for (int i=0;i<_aps.size();i++) + { + if (((AlignmentPanel)_aps.get(i)).av.getAlignment()==alignment) + { + return ((AlignmentPanel)_aps.get(i)); + } + } + return ap; + } } diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 009cefd..152ebe9 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -20,6 +20,8 @@ package jalview.appletgui; import java.awt.Container; import java.util.BitSet; +import jalview.api.AlignmentViewPanel; +import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; @@ -43,8 +45,9 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding appletJmolBinding = appletJmol; } - public jalview.api.FeatureRenderer getFeatureRenderer() + public jalview.api.FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment) { + AlignmentPanel ap = (AlignmentPanel)alignment; if (appletJmolBinding.ap.av.showSequenceFeatures) { if (appletJmolBinding.fr == null) @@ -61,9 +64,9 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding return appletJmolBinding.fr; } - public jalview.api.SequenceRenderer getSequenceRenderer() + public jalview.api.SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment) { - return new SequenceRenderer(appletJmolBinding.ap.av); + return new SequenceRenderer(((AlignmentPanel)alignment).av); } public void sendConsoleEcho(String strEcho) @@ -97,7 +100,7 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding public void updateColours(Object source) { AlignmentPanel ap = (AlignmentPanel) source; - colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment); + colourBySequence(ap.av.getShowSequenceFeatures(), ap); } public void showUrl(String url) @@ -169,4 +172,11 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding } + @Override + public void releaseReferences(Object svl) + { + // TODO Auto-generated method stub + + } + } diff --git a/src/jalview/appletgui/ExtJmol.java b/src/jalview/appletgui/ExtJmol.java index d3dad58..5714ce9 100644 --- a/src/jalview/appletgui/ExtJmol.java +++ b/src/jalview/appletgui/ExtJmol.java @@ -25,8 +25,10 @@ import java.util.Vector; import org.jmol.api.JmolAppConsoleInterface; import org.jmol.api.JmolViewer; +import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; +import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JalviewJmolBinding; @@ -70,8 +72,9 @@ public class ExtJmol extends JalviewJmolBinding showUrl(arg0, "jmol"); } - public FeatureRenderer getFeatureRenderer() + public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment) { + AlignmentPanel ap = (AlignmentPanel)alignment; if (ap.av.showSequenceFeatures) { return ap.getFeatureRenderer(); @@ -82,9 +85,9 @@ public class ExtJmol extends JalviewJmolBinding } } - public SequenceRenderer getSequenceRenderer() + public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment) { - return ap.getSequenceRenderer(); + return ((AlignmentPanel)alignment).getSequenceRenderer(); } public void notifyScriptTermination(String strStatus, int msWalltime) @@ -182,4 +185,11 @@ public class ExtJmol extends JalviewJmolBinding } + @Override + public void releaseReferences(Object svl) + { + // TODO Auto-generated method stub + + } + } diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 67b688c..67327c1 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -26,6 +26,7 @@ import java.awt.event.*; import javax.swing.JPanel; +import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.api.SequenceStructureBinding; @@ -293,205 +294,242 @@ public abstract class JalviewJmolBinding implements StructureListener, public void superposeStructures(AlignmentI alignment, int refStructure, ColumnSelection hiddenCols) { + superposeStructures(new AlignmentI[] + { alignment }, new int[] + { refStructure }, new ColumnSelection[] + { hiddenCols }); + } + + public void superposeStructures(AlignmentI[] _alignment, + int[] _refStructure, ColumnSelection[] _hiddenCols) + { String[] files = getPdbFile(); - if (refStructure >= files.length) + StringBuffer selectioncom = new StringBuffer(); + assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length); + // union of all aligned positions are collected together. + for (int a = 0; a < _alignment.length; a++) { - System.err.println("Invalid reference structure value " - + refStructure); - refStructure = -1; - } - if (refStructure < -1) - { - refStructure = -1; - } - StringBuffer command = new StringBuffer(), selectioncom = new StringBuffer(); + int refStructure = _refStructure[a]; + AlignmentI alignment = _alignment[a]; + ColumnSelection hiddenCols = _hiddenCols[a]; + if (a > 0 + && selectioncom.length() > 0 + && !selectioncom.substring(selectioncom.length() - 1).equals( + "|")) + { + selectioncom.append("|"); + } + // process this alignment + if (refStructure >= files.length) + { + System.err.println("Invalid reference structure value " + + refStructure); + refStructure = -1; + } + if (refStructure < -1) + { + refStructure = -1; + } + StringBuffer command = new StringBuffer(); - boolean matched[] = new boolean[alignment.getWidth()]; - for (int m = 0; m < matched.length; m++) - { + boolean matched[] = new boolean[alignment.getWidth()]; + for (int m = 0; m < matched.length; m++) + { - matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true; - } + matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true; + } - int commonrpositions[][] = new int[files.length][alignment.getWidth()]; - String isel[] = new String[files.length]; - // reference structure - all others are superposed in it - String[] targetC = new String[files.length]; - String[] chainNames = new String[files.length]; - for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) - { - StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); + int commonrpositions[][] = new int[files.length][alignment.getWidth()]; + String isel[] = new String[files.length]; + // reference structure - all others are superposed in it + String[] targetC = new String[files.length]; + String[] chainNames = new String[files.length]; + for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) + { + StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); - if (mapping == null || mapping.length < 1) - continue; + if (mapping == null || mapping.length < 1) + continue; - int lastPos = -1; - for (int s = 0; s < sequence[pdbfnum].length; s++) - { - for (int sp, m = 0; m < mapping.length; m++) + int lastPos = -1; + for (int s = 0; s < sequence[pdbfnum].length; s++) { - if (mapping[m].getSequence() == sequence[pdbfnum][s] - && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1) + for (int sp, m = 0; m < mapping.length; m++) { - if (refStructure == -1) - { - refStructure = pdbfnum; - } - SequenceI asp = alignment.getSequenceAt(sp); - for (int r = 0; r < matched.length; r++) + if (mapping[m].getSequence() == sequence[pdbfnum][s] + && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1) { - if (!matched[r]) + if (refStructure == -1) { - continue; + refStructure = pdbfnum; } - matched[r] = false; // assume this is not a good site - if (r >= asp.getLength()) + SequenceI asp = alignment.getSequenceAt(sp); + for (int r = 0; r < matched.length; r++) { - continue; - } + if (!matched[r]) + { + continue; + } + matched[r] = false; // assume this is not a good site + if (r >= asp.getLength()) + { + continue; + } - if (jalview.util.Comparison.isGap(asp.getCharAt(r))) + if (jalview.util.Comparison.isGap(asp.getCharAt(r))) + { + // no mapping to gaps in sequence + continue; + } + int t = asp.findPosition(r); // sequence position + int apos = mapping[m].getAtomNum(t); + int pos = mapping[m].getPDBResNum(t); + + if (pos < 1 || pos == lastPos) + { + // can't align unmapped sequence + continue; + } + matched[r] = true; // this is a good ite + lastPos = pos; + // just record this residue position + commonrpositions[pdbfnum][r] = pos; + } + // create model selection suffix + isel[pdbfnum] = "/" + (pdbfnum + 1) + ".1"; + if (mapping[m].getChain() == null + || mapping[m].getChain().trim().length() == 0) { - // no mapping to gaps in sequence - continue; + targetC[pdbfnum] = ""; } - int t = asp.findPosition(r); // sequence position - int apos = mapping[m].getAtomNum(t); - int pos = mapping[m].getPDBResNum(t); - - if (pos < 1 || pos == lastPos) + else { - // can't align unmapped sequence - continue; + targetC[pdbfnum] = ":" + mapping[m].getChain(); } - matched[r] = true; // this is a good ite - lastPos = pos; - // just record this residue position - commonrpositions[pdbfnum][r] = pos; - } - // create model selection suffix - isel[pdbfnum] = "/" + (pdbfnum + 1) + ".1"; - if (mapping[m].getChain() == null - || mapping[m].getChain().trim().length() == 0) - { - targetC[pdbfnum] = ""; + chainNames[pdbfnum] = mapping[m].getPdbId() + + targetC[pdbfnum]; + // move on to next pdb file + s = sequence[pdbfnum].length; + break; } - else - { - targetC[pdbfnum] = ":" + mapping[m].getChain(); - } - chainNames[pdbfnum] = mapping[m].getPdbId()+targetC[pdbfnum]; - // move on to next pdb file - s = sequence[pdbfnum].length; - break; } } } - } - String[] selcom = new String[files.length]; - int nmatched = 0; - // generate select statements to select regions to superimpose structures - { - for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) + String[] selcom = new String[files.length]; + int nmatched = 0; + // generate select statements to select regions to superimpose structures { - String chainCd = targetC[pdbfnum]; - int lpos = -1; - boolean run = false; - StringBuffer molsel = new StringBuffer(); - molsel.append("{"); - for (int r = 0; r < matched.length; r++) + for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { - if (matched[r]) + String chainCd = targetC[pdbfnum]; + int lpos = -1; + boolean run = false; + StringBuffer molsel = new StringBuffer(); + molsel.append("{"); + for (int r = 0; r < matched.length; r++) { - if (pdbfnum == 0) + if (matched[r]) { - nmatched++; - } - if (lpos != commonrpositions[pdbfnum][r] - 1) - { - // discontinuity - if (lpos != -1) + if (pdbfnum == 0) { - molsel.append(lpos); - molsel.append(chainCd); - // molsel.append("} {"); - molsel.append("|"); + nmatched++; } - } - else - { - // continuous run - and lpos >-1 - if (!run) + if (lpos != commonrpositions[pdbfnum][r] - 1) + { + // discontinuity + if (lpos != -1) + { + molsel.append(lpos); + molsel.append(chainCd); + // molsel.append("} {"); + molsel.append("|"); + } + } + else { - // at the beginning, so add dash - molsel.append(lpos); - molsel.append("-"); + // continuous run - and lpos >-1 + if (!run) + { + // at the beginning, so add dash + molsel.append(lpos); + molsel.append("-"); + } + run = true; } - run = true; + lpos = commonrpositions[pdbfnum][r]; + // molsel.append(lpos); } - lpos = commonrpositions[pdbfnum][r]; - // molsel.append(lpos); + } + // add final selection phrase + if (lpos != -1) + { + molsel.append(lpos); + molsel.append(chainCd); + molsel.append("}"); + } + selcom[pdbfnum] = molsel.toString(); + selectioncom.append("(("); + selectioncom.append(selcom[pdbfnum].substring(1, + selcom[pdbfnum].length() - 1)); + selectioncom.append(" )& "); + selectioncom.append(pdbfnum + 1); + selectioncom.append(".1)"); + if (pdbfnum < files.length - 1) + { + selectioncom.append("|"); } } - // add final selection phrase - if (lpos != -1) + } + // TODO: consider bailing if nmatched less than 4 because superposition + // not + // well defined. + // TODO: refactor superposable position search (above) from jmol selection + // construction (below) + for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) + { + if (pdbfnum == refStructure) { - molsel.append(lpos); - molsel.append(chainCd); - molsel.append("}"); + continue; } - selcom[pdbfnum] = molsel.toString(); - selectioncom.append("(("); - selectioncom.append(selcom[pdbfnum].substring(1, - selcom[pdbfnum].length() - 1)); - selectioncom.append(" )& "); - selectioncom.append(pdbfnum + 1); - selectioncom.append(".1)"); - if (pdbfnum < files.length - 1) + command.append("echo "); + command.append("\"Superposing ("); + command.append(chainNames[pdbfnum]); + command.append(") against reference ("); + command.append(chainNames[refStructure]); + command.append(")\";\ncompare "); + command.append("{"); + command.append(1 + pdbfnum); + command.append(".1} {"); + command.append(1 + refStructure); + command.append(".1} SUBSET {*.CA | *.P} ATOMS "); + + // form the matched pair strings + String sep = ""; + for (int s = 0; s < 2; s++) { - selectioncom.append("|"); + command.append(selcom[(s == 0 ? pdbfnum : refStructure)]); } + command.append(" ROTATE TRANSLATE;\n"); } + System.out.println("Select regions:\n" + selectioncom.toString()); + evalStateCommand("select *; cartoons off; backbone; select (" + + selectioncom.toString() + "); cartoons; "); + // selcom.append("; ribbons; "); + System.out.println("Superimpose command(s):\n" + command.toString()); + + evalStateCommand(command.toString()); } - // TODO: consider bailing if nmatched less than 4 because superposition not - // well defined. - // TODO: refactor superposable position search (above) from jmol selection - // construction (below) - for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) - { - if (pdbfnum == refStructure) - { - continue; - } - command.append("echo "); - command.append("\"Superposing ("); - command.append(chainNames[pdbfnum]); - command.append(") against reference ("); - command.append(chainNames[refStructure]); - command.append(")\";\ncompare "); - command.append("{"); - command.append(1 + pdbfnum); - command.append(".1} {"); - command.append(1 + refStructure); - command.append(".1} SUBSET {*.CA | *.P} ATOMS "); - - // form the matched pair strings - String sep = ""; - for (int s = 0; s < 2; s++) + if (selectioncom.length() > 0) + {// finally, mark all regions that were superposed. + if (selectioncom.substring(selectioncom.length() - 1).equals("|")) { - command.append(selcom[(s == 0 ? pdbfnum : refStructure)]); + selectioncom.setLength(selectioncom.length() - 1); } - command.append(" ROTATE TRANSLATE;\n"); + System.out.println("Select regions:\n" + selectioncom.toString()); + evalStateCommand("select *; cartoons off; backbone; select (" + + selectioncom.toString() + "); cartoons; "); + // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString()); } - System.out.println("Select regions:\n" + selectioncom.toString()); - evalStateCommand("select *; cartoons off; backbone; select (" - + selectioncom.toString() + "); cartoons; "); - // selcom.append("; ribbons; "); - System.out.println("Superimpose command(s):\n" + command.toString()); - - evalStateCommand(command.toString()); - - // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString()); } public void evalStateCommand(String command) @@ -510,7 +548,8 @@ public abstract class JalviewJmolBinding implements StructureListener, * using the getFeatureRenderer() and getSequenceRenderer() renderers but only * if colourBySequence is enabled. */ - public void colourBySequence(boolean showFeatures, AlignmentI alignment) + public void colourBySequence(boolean showFeatures, + jalview.api.AlignmentViewPanel alignmentv) { if (!colourBySequence) return; @@ -519,14 +558,15 @@ public abstract class JalviewJmolBinding implements StructureListener, return; } String[] files = getPdbFile(); - SequenceRenderer sr = getSequenceRenderer(); + + SequenceRenderer sr = getSequenceRenderer(alignmentv); FeatureRenderer fr = null; if (showFeatures) { - fr = getFeatureRenderer(); + fr = getFeatureRenderer(alignmentv); } - + AlignmentI alignment = alignmentv.getAlignment(); StringBuffer command = new StringBuffer(); for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) @@ -673,9 +713,12 @@ public abstract class JalviewJmolBinding implements StructureListener, * returns the current featureRenderer that should be used to colour the * structures * + * @param alignment + * * @return */ - public abstract FeatureRenderer getFeatureRenderer(); + public abstract FeatureRenderer getFeatureRenderer( + AlignmentViewPanel alignment); /** * instruct the Jalview binding to update the pdbentries vector if necessary @@ -751,9 +794,12 @@ public abstract class JalviewJmolBinding implements StructureListener, * returns the current sequenceRenderer that should be used to colour the * structures * + * @param alignment + * * @return */ - public abstract SequenceRenderer getSequenceRenderer(); + public abstract SequenceRenderer getSequenceRenderer( + AlignmentViewPanel alignment); // /////////////////////////////// // JmolStatusListener @@ -848,6 +894,7 @@ public abstract class JalviewJmolBinding implements StructureListener, public void mouseOverStructure(int atomIndex, String strInfo) { int pdbResNum; + int alocsep = strInfo.indexOf("^"); int mdlSep = strInfo.indexOf("/"); int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1; @@ -860,9 +907,18 @@ public abstract class JalviewJmolBinding implements StructureListener, chainSeparator = mdlSep; } } - pdbResNum = Integer.parseInt(strInfo.substring( - strInfo.indexOf("]") + 1, chainSeparator)); + // handle insertion codes + if (alocsep != -1) + { + pdbResNum = Integer.parseInt(strInfo.substring( + strInfo.indexOf("]") + 1, alocsep)); + } + else + { + pdbResNum = Integer.parseInt(strInfo.substring( + strInfo.indexOf("]") + 1, chainSeparator)); + } String chainId; if (strInfo.indexOf(":") > -1) @@ -1220,7 +1276,7 @@ public abstract class JalviewJmolBinding implements StructureListener, ssm.addStructureViewerListener(this); if (notifyLoaded) { - FeatureRenderer fr = getFeatureRenderer(); + FeatureRenderer fr = getFeatureRenderer(null); if (fr != null) { fr.featuresAdded(); diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java index 4cdf123..37d2559 100644 --- a/src/jalview/javascript/MouseOverStructureListener.java +++ b/src/jalview/javascript/MouseOverStructureListener.java @@ -76,5 +76,11 @@ public class MouseOverStructureListener extends JSFunctionExec implements { return _listenerfn; } + @Override + public void releaseReferences(Object svl) + { + // TODO Auto-generated method stub + + } } diff --git a/src/jalview/structure/StructureListener.java b/src/jalview/structure/StructureListener.java index 4ad4405..698fa7e 100644 --- a/src/jalview/structure/StructureListener.java +++ b/src/jalview/structure/StructureListener.java @@ -59,4 +59,10 @@ public interface StructureListener */ public java.awt.Color getColour(int atomIndex, int pdbResNum, String chain, String pdbId); + + /** + * called by structureSelectionManager to instruct implementor to release any direct references it may hold to the given object (typically, these are Jalview alignment panels). + * @param svl + */ + public void releaseReferences(Object svl); } -- 1.7.10.2