JAL-1750 View Mapping scoped to that viewer's mappings only
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 4 Jun 2015 13:37:13 +0000 (14:37 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 4 Jun 2015 13:37:13 +0000 (14:37 +0100)
src/jalview/appletgui/AppletJmol.java
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java
src/jalview/gui/AppJmol.java
src/jalview/gui/ChimeraViewFrame.java
src/jalview/structure/StructureSelectionManager.java
src/jalview/structures/models/AAStructureBindingModel.java

index 32465c1..f54717d 100644 (file)
  */
 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();
index 50e156f..deadbfc 100644 (file)
@@ -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)
   {
index 95ece8a..3c455c2 100644 (file)
@@ -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.
    * 
index 2180d07..1c92e56 100644 (file)
  */
 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(
index 6c0fa74..a89af2c 100644 (file)
@@ -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(
index 156fc35..9702159 100644 (file)
@@ -53,6 +53,8 @@ import jalview.util.MessageManager;
 
 public class StructureSelectionManager
 {
+  public final static String NEWLINE = System.lineSeparator();
+
   static IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> instances;
 
   private List<StructureMapping> mappings = new ArrayList<StructureMapping>();
@@ -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<SequenceI> 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();
   }
index 9186024..298e82c 100644 (file)
@@ -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<SequenceI> seqs = Arrays.asList(getSequence()[pdbe]);
+      sb.append(getSsm().printMappings(pdbfile, seqs));
+    }
+    return sb.toString();
+  }
+
   @Override
   public void highlightAtoms(List<AtomSpec> atoms)
   {