Merge branch 'develop' into feature/JAL-3551Pymol
[jalview.git] / src / jalview / ext / jmol / JmolCommands.java
index 9c05a37..3e0afd7 100644 (file)
@@ -98,160 +98,6 @@ public class JmolCommands extends StructureCommandsBase
                     c.getBlue());
   }
 
-  @Deprecated
-  public String[] colourBySequence(StructureSelectionManager ssm,
-          String[] files,
-          SequenceI[][] sequence, SequenceRenderer sr,
-          AlignmentViewPanel viewPanel)
-  {
-    // TODO delete method
-
-    FeatureRenderer fr = viewPanel.getFeatureRenderer();
-    FeatureColourFinder finder = new FeatureColourFinder(fr);
-    AlignViewportI viewport = viewPanel.getAlignViewport();
-    HiddenColumns cs = viewport.getAlignment().getHiddenColumns();
-    AlignmentI al = viewport.getAlignment();
-    List<String> cset = new ArrayList<>();
-
-    for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
-    {
-      StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
-      StringBuilder command = new StringBuilder(128);
-      List<String> str = new ArrayList<>();
-
-      if (mapping == null || mapping.length < 1)
-      {
-        continue;
-      }
-
-      for (int s = 0; s < sequence[pdbfnum].length; s++)
-      {
-        for (int sp, m = 0; m < mapping.length; m++)
-        {
-          if (mapping[m].getSequence() == sequence[pdbfnum][s]
-                  && (sp = al.findIndex(sequence[pdbfnum][s])) > -1)
-          {
-            int lastPos = StructureMapping.UNASSIGNED_VALUE;
-            SequenceI asp = al.getSequenceAt(sp);
-            for (int r = 0; r < asp.getLength(); r++)
-            {
-              // no mapping to gaps in sequence
-              if (Comparison.isGap(asp.getCharAt(r)))
-              {
-                continue;
-              }
-              int pos = mapping[m].getPDBResNum(asp.findPosition(r));
-
-              if (pos == lastPos)
-              {
-                continue;
-              }
-              if (pos == StructureMapping.UNASSIGNED_VALUE)
-              {
-                // terminate current colour op
-                if (command.length() > 0
-                        && command.charAt(command.length() - 1) != ';')
-                {
-                  command.append(";");
-                }
-                // reset lastPos
-                lastPos = StructureMapping.UNASSIGNED_VALUE;
-                continue;
-              }
-
-              lastPos = pos;
-
-              Color col = sr.getResidueColour(sequence[pdbfnum][s], r,
-                      finder);
-
-              /*
-               * shade hidden regions darker
-               */
-              if (!cs.isVisible(r))
-              {
-                col = Color.GRAY;
-              }
-
-              String newSelcom = (mapping[m].getChain() != " "
-                      ? ":" + mapping[m].getChain()
-                      : "") + "/" + (pdbfnum + 1) + ".1" + ";color"
-                      + getColourString(col);
-              if (command.length() > newSelcom.length() && command
-                      .substring(command.length() - newSelcom.length())
-                      .equals(newSelcom))
-              {
-                command = JmolCommands.condenseCommand(command, pos);
-                continue;
-              }
-              // TODO: deal with case when buffer is too large for Jmol to parse
-              // - execute command and flush
-
-              if (command.length() > 0
-                      && command.charAt(command.length() - 1) != ';')
-              {
-                command.append(";");
-              }
-
-              if (command.length() > 51200)
-              {
-                // add another chunk
-                str.add(command.toString());
-                command.setLength(0);
-              }
-              command.append("select " + pos);
-              command.append(newSelcom);
-            }
-            // break;
-          }
-        }
-      }
-      {
-        // add final chunk
-        str.add(command.toString());
-        command.setLength(0);
-      }
-      cset.addAll(str);
-
-    }
-    return cset.toArray(new String[cset.size()]);
-  }
-
-  public static StringBuilder condenseCommand(StringBuilder command,
-          int pos)
-  {
-
-    // work back to last 'select'
-    int p = command.length(), q = p;
-    do
-    {
-      p -= 6;
-      if (p < 1)
-      {
-        p = 0;
-      }
-      ;
-    } while ((q = command.indexOf("select", p)) == -1 && p > 0);
-
-    StringBuilder sb = new StringBuilder(command.substring(0, q + 7));
-
-    command = command.delete(0, q + 7);
-
-    String start;
-
-    if (command.indexOf("-") > -1)
-    {
-      start = command.substring(0, command.indexOf("-"));
-    }
-    else
-    {
-      start = command.substring(0, command.indexOf(":"));
-    }
-
-    sb.append(start + "-" + pos + command.substring(command.indexOf(":")));
-
-    return sb;
-  }
-
   @Override
   public StructureCommandI colourByChain()
   {
@@ -447,4 +293,177 @@ public class JmolCommands extends StructureCommandsBase
   {
     return null;
   }
+
+  /**
+   * Obsolete method, only referenced from
+   * jalview.javascript.MouseOverStructureListener
+   * 
+   * @param ssm
+   * @param files
+   * @param sequence
+   * @param sr
+   * @param viewPanel
+   * @return
+   */
+  @Deprecated
+  public String[] colourBySequence(StructureSelectionManager ssm,
+          String[] files, SequenceI[][] sequence, SequenceRenderer sr,
+          AlignmentViewPanel viewPanel)
+  {
+    // TODO delete method
+
+    FeatureRenderer fr = viewPanel.getFeatureRenderer();
+    FeatureColourFinder finder = new FeatureColourFinder(fr);
+    AlignViewportI viewport = viewPanel.getAlignViewport();
+    HiddenColumns cs = viewport.getAlignment().getHiddenColumns();
+    AlignmentI al = viewport.getAlignment();
+    List<String> cset = new ArrayList<>();
+
+    for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
+    {
+      StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
+      StringBuilder command = new StringBuilder(128);
+      List<String> str = new ArrayList<>();
+
+      if (mapping == null || mapping.length < 1)
+      {
+        continue;
+      }
+
+      for (int s = 0; s < sequence[pdbfnum].length; s++)
+      {
+        for (int sp, m = 0; m < mapping.length; m++)
+        {
+          if (mapping[m].getSequence() == sequence[pdbfnum][s]
+                  && (sp = al.findIndex(sequence[pdbfnum][s])) > -1)
+          {
+            int lastPos = StructureMapping.UNASSIGNED_VALUE;
+            SequenceI asp = al.getSequenceAt(sp);
+            for (int r = 0; r < asp.getLength(); r++)
+            {
+              // no mapping to gaps in sequence
+              if (Comparison.isGap(asp.getCharAt(r)))
+              {
+                continue;
+              }
+              int pos = mapping[m].getPDBResNum(asp.findPosition(r));
+
+              if (pos == lastPos)
+              {
+                continue;
+              }
+              if (pos == StructureMapping.UNASSIGNED_VALUE)
+              {
+                // terminate current colour op
+                if (command.length() > 0
+                        && command.charAt(command.length() - 1) != ';')
+                {
+                  command.append(";");
+                }
+                // reset lastPos
+                lastPos = StructureMapping.UNASSIGNED_VALUE;
+                continue;
+              }
+
+              lastPos = pos;
+
+              Color col = sr.getResidueColour(sequence[pdbfnum][s], r,
+                      finder);
+
+              /*
+               * shade hidden regions darker
+               */
+              if (!cs.isVisible(r))
+              {
+                col = Color.GRAY;
+              }
+
+              String newSelcom = (mapping[m].getChain() != " "
+                      ? ":" + mapping[m].getChain()
+                      : "") + "/" + (pdbfnum + 1) + ".1" + ";color"
+                      + getColourString(col);
+              if (command.length() > newSelcom.length() && command
+                      .substring(command.length() - newSelcom.length())
+                      .equals(newSelcom))
+              {
+                command = JmolCommands.condenseCommand(command, pos);
+                continue;
+              }
+              // TODO: deal with case when buffer is too large for Jmol to parse
+              // - execute command and flush
+
+              if (command.length() > 0
+                      && command.charAt(command.length() - 1) != ';')
+              {
+                command.append(";");
+              }
+
+              if (command.length() > 51200)
+              {
+                // add another chunk
+                str.add(command.toString());
+                command.setLength(0);
+              }
+              command.append("select " + pos);
+              command.append(newSelcom);
+            }
+            // break;
+          }
+        }
+      }
+      {
+        // add final chunk
+        str.add(command.toString());
+        command.setLength(0);
+      }
+      cset.addAll(str);
+
+    }
+    return cset.toArray(new String[cset.size()]);
+  }
+
+  /**
+   * Helper method
+   * 
+   * @param command
+   * @param pos
+   * @return
+   */
+  @Deprecated
+  private static StringBuilder condenseCommand(
+          StringBuilder command,
+          int pos)
+  {
+
+    // work back to last 'select'
+    int p = command.length(), q = p;
+    do
+    {
+      p -= 6;
+      if (p < 1)
+      {
+        p = 0;
+      }
+      ;
+    } while ((q = command.indexOf("select", p)) == -1 && p > 0);
+
+    StringBuilder sb = new StringBuilder(command.substring(0, q + 7));
+
+    command = command.delete(0, q + 7);
+
+    String start;
+
+    if (command.indexOf("-") > -1)
+    {
+      start = command.substring(0, command.indexOf("-"));
+    }
+    else
+    {
+      start = command.substring(0, command.indexOf(":"));
+    }
+
+    sb.append(start + "-" + pos + command.substring(command.indexOf(":")));
+
+    return sb;
+  }
 }