Merge branch 'develop' into menard
[jalview.git] / src / jalview / ext / varna / VarnaCommands.java
index a1d3a77..21f626f 100644 (file)
@@ -1,5 +1,19 @@
-/**\r
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)\r
+ * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle\r
+ * \r
+ * This file is part of Jalview.\r
+ * \r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
+ *  \r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE.  See the GNU General Public License for more details.\r
  * \r
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 package jalview.ext.varna;\r
 \r
@@ -15,35 +29,32 @@ import java.awt.Color;
 import java.util.ArrayList;\r
 \r
 /**\r
- * Routines for generating Jmol commands for Jalview/Jmol binding another\r
- * cruisecontrol test.\r
+ * Routines for generating Jmol commands for Jalview/Jmol binding\r
+ * another cruisecontrol test.\r
  * \r
  * @author JimP\r
- * \r
+ *\r
  */\r
 public class VarnaCommands\r
 {\r
 \r
   /**\r
-   * Jmol utility which constructs the commands to colour chains by the given\r
-   * alignment\r
+   * Jmol utility which constructs the commands to colour chains by the given alignment\r
    * \r
    */\r
-  public static String[] getColourBySequenceCommand(\r
-          StructureSelectionManager ssm, String[] files,\r
-          SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,\r
-          AlignmentI alignment)\r
+  public static String[] getColourBySequenceCommand(StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, AlignmentI alignment)\r
   {\r
+       \r
     ArrayList<String> str = new ArrayList<String>();\r
     StringBuffer command = new StringBuffer();\r
-\r
+  \r
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)\r
     {\r
       StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);\r
-\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
@@ -61,14 +72,14 @@ public class VarnaCommands
                 continue;\r
               }\r
               int pos = mapping[m].getPDBResNum(asp.findPosition(r));\r
-\r
+  \r
               if (pos < 1 || pos == lastPos)\r
                 continue;\r
-\r
+  \r
               lastPos = pos;\r
-\r
+  \r
               Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);\r
-\r
+  \r
               if (fr != null)\r
                 col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);\r
               String newSelcom = (mapping[m].getChain() != " " ? ":"\r
@@ -82,19 +93,16 @@ public class VarnaCommands
                       + col.getGreen()\r
                       + ","\r
                       + col.getBlue() + "]";\r
-              if (command.length() > newSelcom.length()\r
-                      && command.substring(\r
-                              command.length() - newSelcom.length())\r
-                              .equals(newSelcom))\r
+              if (command.length()>newSelcom.length() && command.substring(command.length()-newSelcom.length()).equals(newSelcom))\r
               {\r
                 command = VarnaCommands.condenseCommand(command, pos);\r
                 continue;\r
               }\r
               // TODO: deal with case when buffer is too large for Jmol to parse\r
               // - execute command and flush\r
-\r
+  \r
               command.append(";");\r
-              if (command.length() > 51200)\r
+              if (command.length()>51200)\r
               {\r
                 // add another chunk\r
                 str.add(command.toString());\r
@@ -118,25 +126,20 @@ public class VarnaCommands
 \r
   public static StringBuffer condenseCommand(StringBuffer command, int pos)\r
   {\r
-\r
+  \r
     // work back to last 'select'\r
-    int p = command.length(), q = p;\r
-    do\r
-    {\r
-      p -= 6;\r
-      if (p < 1)\r
-      {\r
-        p = 0;\r
-      }\r
-      ;\r
-    } while ((q = command.indexOf("select", p)) == -1 && p > 0);\r
-\r
-    StringBuffer sb = new StringBuffer(command.substring(0, q + 7));\r
-\r
-    command = command.delete(0, q + 7);\r
-\r
+    int p=command.length(),q=p;\r
+    do {\r
+      p-=6;\r
+      if (p<1) { p=0; };\r
+    } while ((q=command.indexOf("select",p))==-1 && p>0);\r
+    \r
+    StringBuffer sb = new StringBuffer(command.substring(0,q+7));\r
+  \r
+    command =  command.delete(0,q+7);\r
+  \r
     String start;\r
-\r
+  \r
     if (command.indexOf("-") > -1)\r
     {\r
       start = command.substring(0, command.indexOf("-"));\r
@@ -145,9 +148,9 @@ public class VarnaCommands
     {\r
       start = command.substring(0, command.indexOf(":"));\r
     }\r
-\r
+  \r
     sb.append(start + "-" + pos + command.substring(command.indexOf(":")));\r
-\r
+  \r
     return sb;\r
   }\r
 \r