refactor to send list of model filenames involved in each set of Jmol
authorjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 5 Jul 2011 11:10:28 +0000 (12:10 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 5 Jul 2011 11:10:28 +0000 (12:10 +0100)
commands so they can be sent to the correct Jmol. (JAL-816, JAL-621,
JAL-862)

src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/ext/jmol/JmolCommands.java
src/jalview/javascript/MouseOverStructureListener.java
src/jalview/structure/StructureMappingcommandSet.java [new file with mode: 0644]

index 6747349..da514a2 100644 (file)
@@ -570,7 +570,8 @@ public abstract class JalviewJmolBinding implements StructureListener,
     }\r
     AlignmentI alignment = alignmentv.getAlignment();\r
 \r
-    for (String cbyseq : JmolCommands.getColourBySequenceCommand(ssm, files, sequence, sr, fr, alignment)) {\r
+    for (jalview.structure.StructureMappingcommandSet cpdbbyseq: JmolCommands.getColourBySequenceCommand(ssm, files, sequence, sr, fr, alignment))\r
+      for (String cbyseq : cpdbbyseq.commands) {\r
       evalStateCommand(cbyseq);\r
     }\r
   }\r
index 9d01eab..bfb2766 100644 (file)
@@ -8,12 +8,12 @@ import jalview.api.SequenceRenderer;
 import jalview.datamodel.AlignmentI;\r
 import jalview.datamodel.SequenceI;\r
 import jalview.structure.StructureMapping;\r
+import jalview.structure.StructureMappingcommandSet;\r
 import jalview.structure.StructureSelectionManager;\r
 import jalview.util.Comparison;\r
 \r
 import java.awt.Color;\r
 import java.util.ArrayList;\r
-\r
 /**\r
  * Routines for generating Jmol commands for Jalview/Jmol binding\r
  * another cruisecontrol test.\r
@@ -26,20 +26,24 @@ public class JmolCommands
 \r
   /**\r
    * Jmol utility which constructs the commands to colour chains by the given alignment\r
+   * @returns Object[] { Object[] { <model being coloured>, \r
    * \r
    */\r
-  public static String[] getColourBySequenceCommand(StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, AlignmentI alignment)\r
+  public static StructureMappingcommandSet[] getColourBySequenceCommand(StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, AlignmentI alignment)\r
   {\r
-    ArrayList<String> str = new ArrayList<String>();\r
-    StringBuffer command = new StringBuffer();\r
-  \r
+    \r
+    ArrayList<StructureMappingcommandSet> cset = new ArrayList<StructureMappingcommandSet>();\r
+    \r
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)\r
     {\r
       StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);\r
+      StringBuffer command = new StringBuffer();\r
+      StructureMappingcommandSet smc;\r
+      ArrayList<String> str = new ArrayList<String>();\r
   \r
       if (mapping == null || mapping.length < 1)\r
         continue;\r
-  \r
+      \r
       int lastPos = -1;\r
       for (int s = 0; s < sequence[pdbfnum].length; s++)\r
       {\r
@@ -100,13 +104,16 @@ public class JmolCommands
           }\r
         }\r
       }\r
+      {\r
+          // add final chunk\r
+          str.add(command.toString());\r
+          command.setLength(0);\r
+        }\r
+        // Finally, add the command set ready to be returned.\r
+        cset.add(new StructureMappingcommandSet(JmolCommands.class,files[pdbfnum], str.toArray(new String[str.size()])));\r
+\r
     }\r
-    {\r
-      // add final chunk\r
-      str.add(command.toString());\r
-      command.setLength(0);\r
-    }\r
-    return str.toArray(new String[str.size()]);\r
+    return cset.toArray(new StructureMappingcommandSet[cset.size()]);\r
   }\r
 \r
   public static StringBuffer condenseCommand(StringBuffer command, int pos)\r
index 41af88e..085e50d 100644 (file)
@@ -1,6 +1,8 @@
 package jalview.javascript;\r
 \r
 import java.awt.Color;\r
+import java.util.ArrayList;\r
+\r
 import jalview.api.AlignmentViewPanel;\r
 import jalview.api.FeatureRenderer;\r
 import jalview.api.SequenceRenderer;\r
@@ -10,6 +12,7 @@ import jalview.datamodel.SequenceI;
 import jalview.ext.jmol.JmolCommands;\r
 import jalview.structure.StructureListener;\r
 import jalview.structure.StructureMapping;\r
+import jalview.structure.StructureMappingcommandSet;\r
 import jalview.structure.StructureSelectionManager;\r
 \r
 /**\r
@@ -179,26 +182,41 @@ public class MouseOverStructureListener extends JSFunctionExec implements
       }\r
       ;\r
 \r
-      // Form a colour command for the given alignment panel\r
-      final String[] colcommands = JmolCommands.getColourBySequenceCommand(\r
+      \r
+      // Form a colour command from the given alignment panel for each distinct structure \r
+      ArrayList<String[]> ccomands=new ArrayList<String[]>();\r
+      ArrayList<String> pdbfn=new ArrayList<String>();\r
+      StructureMappingcommandSet[] colcommands=JmolCommands.getColourBySequenceCommand(\r
               ssm, modelSet, sequence, sr, fr,\r
               ((AlignmentViewPanel) source).getAlignment());\r
-      if (colcommands==null)\r
-      {\r
-        // \r
+      if (colcommands==null) {\r
         return;\r
       }\r
+      int sz=0;\r
+      for (jalview.structure.StructureMappingcommandSet ccset: colcommands) {\r
+        sz+=ccset.commands.length;\r
+        ccomands.add(ccset.commands);\r
+        pdbfn.add(ccset.mapping);\r
+      }\r
+      \r
       String mclass,mhandle;\r
+      String ccomandset[] = new String[sz];\r
+      sz=0;\r
+      for (String[] ccset: ccomands) {\r
+        System.arraycopy(ccset, 0, ccomandset, sz, ccset.length);\r
+        sz+=ccset.length;\r
+      }\r
       if (jvlite.isJsMessageSetChanged(mclass="colourstruct",mhandle=((jalview.appletgui.AlignmentPanel) source).av\r
-              .getViewId(), colcommands)) {\r
-      jvlite.setJsMessageSet(mclass, mhandle , colcommands);\r
+              .getViewId(), ccomandset)) {\r
+      jvlite.setJsMessageSet(mclass, mhandle , ccomandset);\r
       // and notify javascript handler\r
       String st[] = new String[]\r
                                                   {\r
               "colourstruct",\r
               ""\r
                       + ((jalview.appletgui.AlignmentPanel) source).av\r
-                              .getViewId(), ""+colcommands.length, ""+(colcommands[0]!=null ? colcommands[0].length() : 0)};\r
+                              .getViewId(), ""+ccomandset.length, jvlite.arrayToSeparatorList(pdbfn.toArray(new String[pdbfn.size()]))\r
+                              };\r
       try\r
       {\r
         executeJavascriptFunction(\r
@@ -209,7 +227,7 @@ public class MouseOverStructureListener extends JSFunctionExec implements
       {\r
         System.err.println("Couldn't execute callback with "\r
                 + _listenerfn + " using args { " + st[0] + ", "\r
-                + st[1] + ", " + st[2] + "," + st[3] + "\n");\r
+                + st[1] + ", " + st[2] + "," + st[3]+"}"); //  + ","+st[4]+"\n");\r
         ex.printStackTrace();\r
 \r
       }\r
diff --git a/src/jalview/structure/StructureMappingcommandSet.java b/src/jalview/structure/StructureMappingcommandSet.java
new file mode 100644 (file)
index 0000000..5bf6e57
--- /dev/null
@@ -0,0 +1,34 @@
+package jalview.structure;
+
+
+/**
+ * holder for script commands generated for a particular structure mapping
+ * @author jimp
+ *
+ */
+public class StructureMappingcommandSet {
+  /**
+   * structure file for which these commands were generated
+   */
+  public String mapping;
+  /**
+   * set of commands
+   */
+  public String[] commands;
+  /**
+   * some object that indicates what the commands can be parsed by (eg JmolCommands.class implies these are Jmol commands)
+   */
+  public Object handledBy;
+  /**
+   * record the originating command generator, the structure mapping involved, and the set of commands to be passed.
+   * @param handledBy
+   * @param files
+   * @param commands
+   */
+  public StructureMappingcommandSet(Object handledBy, String files, String[] commands)
+  {
+    this.mapping=files;
+    this.handledBy=handledBy;
+    this.commands=commands;
+  }
+}