From a7ea1ba47dae32481aa6390a29cef6c7c5a403c4 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 4 Jun 2015 14:37:13 +0100 Subject: [PATCH] JAL-1750 View Mapping scoped to that viewer's mappings only --- src/jalview/appletgui/AppletJmol.java | 41 +++++++--------- src/jalview/ext/jmol/JalviewJmolBinding.java | 11 ----- .../ext/rbvi/chimera/JalviewChimeraBinding.java | 11 ----- src/jalview/gui/AppJmol.java | 50 +++++++++----------- src/jalview/gui/ChimeraViewFrame.java | 6 +-- .../structure/StructureSelectionManager.java | 26 ++++++++-- .../structures/models/AAStructureBindingModel.java | 25 ++++++++++ 7 files changed, 90 insertions(+), 80 deletions(-) diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 32465c1..f54717d 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -20,23 +20,6 @@ */ package jalview.appletgui; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; -import jalview.io.FileParse; -import jalview.schemes.BuriedColourScheme; -import jalview.schemes.HelixColourScheme; -import jalview.schemes.HydrophobicColourScheme; -import jalview.schemes.PurinePyrimidineColourScheme; -import jalview.schemes.StrandColourScheme; -import jalview.schemes.TaylorColourScheme; -import jalview.schemes.TurnColourScheme; -import jalview.schemes.UserColourScheme; -import jalview.schemes.ZappoColourScheme; -import jalview.structure.StructureSelectionManager; -import jalview.util.MessageManager; - import java.awt.BorderLayout; import java.awt.CheckboxMenuItem; import java.awt.Color; @@ -63,6 +46,23 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.Vector; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.io.FileParse; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.HydrophobicColourScheme; +import jalview.schemes.PurinePyrimidineColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.UserColourScheme; +import jalview.schemes.ZappoColourScheme; +import jalview.structure.StructureSelectionManager; +import jalview.util.MessageManager; + public class AppletJmol extends EmbmenuFrame implements // StructureListener, KeyListener, ActionListener, ItemListener @@ -429,12 +429,7 @@ public class AppletJmol extends EmbmenuFrame implements StringBuffer sb = new StringBuffer(); try { - for (int s = 0; s < jmb.getPdbCount(); s++) - { - sb.append(jmb.printMapping(jmb.getPdbEntry(s).getFile())); - sb.append("\n"); - } - cap.setText(sb.toString()); + cap.setText(jmb.printMappings()); } catch (OutOfMemoryError ex) { frame.dispose(); diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 50e156f..deadbfc 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -1440,17 +1440,6 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel jmolHistory(true); } - /** - * - * @param pdbfile - * @return text report of alignment between pdbfile and any associated - * alignment sequences - */ - public String printMapping(String pdbfile) - { - return getSsm().printMapping(pdbfile); - } - @Override public void resizeInnerPanel(String data) { diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 95ece8a..3c455c2 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -1094,17 +1094,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel } /** - * - * @param pdbfile - * @return text report of alignment between pdbfile and any associated - * alignment sequences - */ - public String printMapping(String pdbfile) - { - return getSsm().printMapping(pdbfile); - } - - /** * Ask Chimera to save its session to the given file. Returns true if * successful, else false. * diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 2180d07..1c92e56 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -20,28 +20,6 @@ */ package jalview.gui; -import jalview.bin.Cache; -import jalview.datamodel.Alignment; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.ColumnSelection; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; -import jalview.io.JalviewFileChooser; -import jalview.io.JalviewFileView; -import jalview.schemes.BuriedColourScheme; -import jalview.schemes.ColourSchemeI; -import jalview.schemes.HelixColourScheme; -import jalview.schemes.HydrophobicColourScheme; -import jalview.schemes.PurinePyrimidineColourScheme; -import jalview.schemes.StrandColourScheme; -import jalview.schemes.TaylorColourScheme; -import jalview.schemes.TurnColourScheme; -import jalview.schemes.ZappoColourScheme; -import jalview.structures.models.AAStructureBindingModel; -import jalview.util.MessageManager; -import jalview.util.Platform; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -73,6 +51,28 @@ import javax.swing.event.InternalFrameEvent; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; +import jalview.bin.Cache; +import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.ColourSchemeI; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.HydrophobicColourScheme; +import jalview.schemes.PurinePyrimidineColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.ZappoColourScheme; +import jalview.structures.models.AAStructureBindingModel; +import jalview.util.MessageManager; +import jalview.util.Platform; + public class AppJmol extends StructureViewerBase { AppJmolBinding jmb; @@ -844,11 +844,7 @@ public class AppJmol extends StructureViewerBase jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); try { - for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++) - { - cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile())); - cap.appendText("\n"); - } + cap.appendText(jmb.printMappings()); } catch (OutOfMemoryError e) { new OOMWarning( diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 6c0fa74..a89af2c 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -931,11 +931,7 @@ public class ChimeraViewFrame extends StructureViewerBase jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); try { - for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++) - { - cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile())); - cap.appendText("\n"); - } + cap.appendText(jmb.printMappings()); } catch (OutOfMemoryError e) { new OOMWarning( diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 156fc35..9702159 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -53,6 +53,8 @@ import jalview.util.MessageManager; public class StructureSelectionManager { + public final static String NEWLINE = System.lineSeparator(); + static IdentityHashMap instances; private List mappings = new ArrayList(); @@ -495,7 +497,7 @@ public class StructureSelectionManager do { - Atom tmp = (Atom) maxChain.atoms.elementAt(index); + Atom tmp = maxChain.atoms.elementAt(index); if (resNum != tmp.resNumber && tmp.alignmentMapping != -1) { resNum = tmp.resNumber; @@ -853,16 +855,34 @@ public class StructureSelectionManager return tmp.toArray(new StructureMapping[tmp.size()]); } - public String printMapping(String pdbfile) + /** + * Returns a readable description of all mappings for the given pdbfile to any + * of the given sequences + * + * @param pdbfile + * @param seqs + * @return + */ + public String printMappings(String pdbfile, List seqs) { + if (pdbfile == null || seqs == null || seqs.isEmpty()) + { + return ""; + } + StringBuilder sb = new StringBuilder(64); for (StructureMapping sm : mappings) { - if (sm.pdbfile.equals(pdbfile)) + if (sm.pdbfile.equals(pdbfile) && seqs.contains(sm.sequence)) { sb.append(sm.mappingDetails); + sb.append(NEWLINE); + // separator makes it easier to read multiple mappings + sb.append("====================="); + sb.append(NEWLINE); } } + sb.append(NEWLINE); return sb.toString(); } diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 9186024..298e82c 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -1,6 +1,7 @@ package jalview.structures.models; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import jalview.api.StructureSelectionManagerProvider; @@ -387,6 +388,30 @@ public abstract class AAStructureBindingModel extends } } + /** + * Returns a readable description of all mappings for the wrapped pdbfile to + * any mapped sequences + * + * @param pdbfile + * @param seqs + * @return + */ + public String printMappings() + { + if (pdbEntry == null) + { + return ""; + } + StringBuilder sb = new StringBuilder(128); + for (int pdbe = 0; pdbe < getPdbCount(); pdbe++) + { + String pdbfile = getPdbEntry(pdbe).getFile(); + List seqs = Arrays.asList(getSequence()[pdbe]); + sb.append(getSsm().printMappings(pdbfile, seqs)); + } + return sb.toString(); + } + @Override public void highlightAtoms(List atoms) { -- 1.7.10.2