Formatting changes
[jalview.git] / src / jalview / schemes / ClustalxColourScheme.java
index 17398fc..addf00f 100755 (executable)
 /*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program 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 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
-*/\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program 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 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 package jalview.schemes;\r
 \r
-import jalview.datamodel.*;\r
-\r
-import java.awt.*;\r
-\r
 import java.util.*;\r
 \r
+import java.awt.*;\r
 \r
-public class ClustalxColourScheme extends ResidueColourScheme {\r
-    public static Hashtable colhash = new Hashtable();\r
-    Hashtable[] cons;\r
-    int[][] cons2;\r
-    ConsensusColour[] colours;\r
-    ConsensusColour[] ResidueColour;\r
-    int size;\r
-    Consensus[] conses = new Consensus[32];\r
-    Vector colourTable = new Vector();\r
+import jalview.datamodel.*;\r
 \r
+public class ClustalxColourScheme\r
+    extends ResidueColourScheme\r
+{\r
+  public static Hashtable colhash = new Hashtable();\r
+  Hashtable[] cons;\r
+  int[][] cons2;\r
+  ConsensusColour[] colours;\r
+  ConsensusColour[] ResidueColour;\r
+  int size;\r
+  Consensus[] conses = new Consensus[32];\r
+  Vector colourTable = new Vector();\r
+\r
+  {\r
+    colhash.put("RED", new Color( (float) 0.9, (float) 0.2, (float) 0.1));\r
+    colhash.put("BLUE", new Color( (float) 0.5, (float) 0.7, (float) 0.9));\r
+    colhash.put("GREEN", new Color( (float) 0.1, (float) 0.8, (float) 0.1));\r
+    colhash.put("ORANGE", new Color( (float) 0.9, (float) 0.6, (float) 0.3));\r
+    colhash.put("CYAN", new Color( (float) 0.1, (float) 0.7, (float) 0.7));\r
+    colhash.put("PINK", new Color( (float) 0.9, (float) 0.5, (float) 0.5));\r
+    colhash.put("MAGENTA", new Color( (float) 0.8, (float) 0.3, (float) 0.8));\r
+    colhash.put("YELLOW", new Color( (float) 0.8, (float) 0.8, (float) 0.0));\r
+  }\r
+\r
+  public ClustalxColourScheme(Vector seqs, int maxWidth)\r
+  {\r
+    resetClustalX(seqs, maxWidth);\r
+  }\r
+\r
+  public void resetClustalX(Vector seqs, int maxWidth)\r
+  {\r
+    cons2 = new int[maxWidth][24];\r
+\r
+    int start = 0;\r
+\r
+    // Initialize the array\r
+    for (int j = 0; j < 24; j++)\r
     {\r
-        colhash.put("RED", new Color((float) 0.9, (float) 0.2, (float) 0.1));\r
-        colhash.put("BLUE", new Color((float) 0.5, (float) 0.7, (float) 0.9));\r
-        colhash.put("GREEN", new Color((float) 0.1, (float) 0.8, (float) 0.1));\r
-        colhash.put("ORANGE", new Color((float) 0.9, (float) 0.6, (float) 0.3));\r
-        colhash.put("CYAN", new Color((float) 0.1, (float) 0.7, (float) 0.7));\r
-        colhash.put("PINK", new Color((float) 0.9, (float) 0.5, (float) 0.5));\r
-        colhash.put("MAGENTA", new Color((float) 0.8, (float) 0.3, (float) 0.8));\r
-        colhash.put("YELLOW", new Color((float) 0.8, (float) 0.8, (float) 0.0));\r
-    }\r
-\r
-    public ClustalxColourScheme(Vector seqs, int maxWidth) {\r
-        resetClustalX(seqs, maxWidth);\r
+      for (int i = 0; i < maxWidth; i++)\r
+      {\r
+        cons2[i][j] = 0;\r
+      }\r
     }\r
 \r
-    public void resetClustalX(Vector seqs, int maxWidth) {\r
-        cons2 = new int[maxWidth][24];\r
+    int res;\r
+    int i;\r
+    int j = 0;\r
+    String seq;\r
 \r
-        int start = 0;\r
-\r
-        // Initialize the array\r
-        for (int j = 0; j < 24; j++)\r
-            for (int i = 0; i < maxWidth; i++)\r
-                cons2[i][j] = 0;\r
-\r
-        int res;\r
-        int i;\r
-        int j = 0;\r
-        String seq;\r
-\r
-        while (j < seqs.size()) {\r
-            seq = ((SequenceI) seqs.elementAt(j)).getSequence();\r
-\r
-            int end_j = seq.length() - 1;\r
-\r
-            for (i = start; i <= end_j; i++) {\r
-                if ((seq.length() - 1) < i) {\r
-                    res = 23;\r
-                } else {\r
-                    res = ((Integer) ResidueProperties.aaHash.get(seq.charAt(i) +\r
-                            "")).intValue();\r
-                }\r
+    while (j < seqs.size())\r
+    {\r
+      seq = ( (SequenceI) seqs.elementAt(j)).getSequence();\r
 \r
-                cons2[i][res]++;\r
-            }\r
+      int end_j = seq.length() - 1;\r
 \r
-            j++;\r
+      for (i = start; i <= end_j; i++)\r
+      {\r
+        if ( (seq.length() - 1) < i)\r
+        {\r
+          res = 23;\r
+        }\r
+        else\r
+        {\r
+          res = ( (Integer) ResidueProperties.aaHash.get(seq.charAt(i) +\r
+              "")).intValue();\r
         }\r
 \r
-        this.size = seqs.size();\r
-        makeColours();\r
-    }\r
+        cons2[i][res]++;\r
+      }\r
 \r
-    public void makeColours() {\r
-        conses[0] = new Consensus("WLVIMAFCYHP", 60);\r
-        conses[1] = new Consensus("WLVIMAFCYHP", 80);\r
-        conses[2] = new Consensus("ED", 50);\r
-        conses[3] = new Consensus("KR", 60);\r
-        conses[4] = new Consensus("G", 50);\r
-        conses[5] = new Consensus("N", 50);\r
-        conses[6] = new Consensus("QE", 50);\r
-        conses[7] = new Consensus("P", 50);\r
-        conses[8] = new Consensus("TS", 50);\r
-\r
-        conses[26] = new Consensus("A", 85);\r
-        conses[27] = new Consensus("C", 85);\r
-        conses[10] = new Consensus("E", 85);\r
-        conses[11] = new Consensus("F", 85);\r
-        conses[12] = new Consensus("G", 85);\r
-        conses[13] = new Consensus("H", 85);\r
-        conses[14] = new Consensus("I", 85);\r
-        conses[15] = new Consensus("L", 85);\r
-        conses[16] = new Consensus("M", 85);\r
-        conses[17] = new Consensus("N", 85);\r
-        conses[18] = new Consensus("P", 85);\r
-        conses[19] = new Consensus("Q", 85);\r
-        conses[20] = new Consensus("R", 85);\r
-        conses[21] = new Consensus("S", 85);\r
-        conses[22] = new Consensus("T", 85);\r
-        conses[23] = new Consensus("V", 85);\r
-        conses[24] = new Consensus("W", 85);\r
-        conses[25] = new Consensus("Y", 85);\r
-        conses[28] = new Consensus("K", 85);\r
-        conses[29] = new Consensus("D", 85);\r
-\r
-        conses[30] = new Consensus("G", 0);\r
-        conses[31] = new Consensus("P", 0);\r
-\r
-        // We now construct the colours\r
-        colours = new ConsensusColour[11];\r
-\r
-        Consensus[] tmp8 = new Consensus[1];\r
-        tmp8[0] = conses[30]; //G\r
-        colours[7] = new ConsensusColour((Color) colhash.get("ORANGE"), tmp8);\r
-\r
-        Consensus[] tmp9 = new Consensus[1];\r
-        tmp9[0] = conses[31]; //P\r
-        colours[8] = new ConsensusColour((Color) colhash.get("YELLOW"), tmp9);\r
-\r
-        Consensus[] tmp10 = new Consensus[1];\r
-        tmp10[0] = conses[27]; //C\r
-        colours[9] = new ConsensusColour((Color) colhash.get("PINK"), tmp8);\r
-\r
-        Consensus[] tmp1 = new Consensus[14];\r
-        tmp1[0] = conses[0]; //%\r
-        tmp1[1] = conses[1]; //#\r
-        tmp1[2] = conses[26]; //A\r
-        tmp1[3] = conses[27]; //C\r
-        tmp1[4] = conses[11]; //F\r
-        tmp1[5] = conses[13]; //H\r
-        tmp1[6] = conses[14]; //I\r
-        tmp1[7] = conses[15]; //L\r
-        tmp1[8] = conses[16]; //M\r
-        tmp1[9] = conses[23]; //V\r
-        tmp1[10] = conses[24]; //W\r
-        tmp1[11] = conses[25]; //Y\r
-        tmp1[12] = conses[18]; //P\r
-        tmp1[13] = conses[19]; //p\r
-        colours[0] = new ConsensusColour((Color) colhash.get("BLUE"), tmp1);\r
-\r
-        colours[10] = new ConsensusColour((Color) colhash.get("CYAN"), tmp1);\r
-\r
-        Consensus[] tmp2 = new Consensus[5];\r
-        tmp2[0] = conses[8]; //t\r
-        tmp2[1] = conses[21]; //S\r
-        tmp2[2] = conses[22]; //T\r
-        tmp2[3] = conses[0]; //%\r
-        tmp2[4] = conses[1]; //#\r
-        colours[1] = new ConsensusColour((Color) colhash.get("GREEN"), tmp2);\r
-\r
-        Consensus[] tmp3 = new Consensus[3];\r
-\r
-        tmp3[0] = conses[17]; //N\r
-        tmp3[1] = conses[29]; //D\r
-        tmp3[2] = conses[5]; //n\r
-        colours[2] = new ConsensusColour((Color) colhash.get("GREEN"), tmp3);\r
-\r
-        Consensus[] tmp4 = new Consensus[6];\r
-        tmp4[0] = conses[6]; // q = QE\r
-        tmp4[1] = conses[19]; //Q\r
-        tmp4[2] = conses[22]; //E\r
-        tmp4[3] = conses[3]; //+\r
-        tmp4[4] = conses[28]; //K\r
-        tmp4[5] = conses[20]; //R\r
-        colours[3] = new ConsensusColour((Color) colhash.get("GREEN"), tmp4);\r
-\r
-        Consensus[] tmp5 = new Consensus[4];\r
-        tmp5[0] = conses[3]; //+\r
-        tmp5[1] = conses[28]; //K\r
-        tmp5[2] = conses[20]; //R\r
-        tmp5[3] = conses[19]; //Q\r
-        colours[4] = new ConsensusColour((Color) colhash.get("RED"), tmp5);\r
-\r
-        Consensus[] tmp6 = new Consensus[5];\r
-        tmp6[0] = conses[3]; //-\r
-        tmp6[1] = conses[29]; //D\r
-        tmp6[2] = conses[10]; //E\r
-        tmp6[3] = conses[6]; //q\r
-        tmp6[4] = conses[19]; //Q\r
-        colours[5] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp6);\r
-\r
-        Consensus[] tmp7 = new Consensus[5];\r
-        tmp7[0] = conses[3]; //-\r
-        tmp7[1] = conses[29]; //D\r
-        tmp7[2] = conses[10]; //E\r
-        tmp7[3] = conses[17]; //N\r
-        tmp7[4] = conses[2]; //DE\r
-        colours[6] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp7);\r
-\r
-        // Now attach the ConsensusColours to the residue letters\r
-        ResidueColour = new ConsensusColour[20];\r
-        ResidueColour[0] = colours[0]; // A\r
-        ResidueColour[1] = colours[4]; // R\r
-        ResidueColour[2] = colours[2]; // N\r
-        ResidueColour[3] = colours[6]; // D\r
-        ResidueColour[4] = colours[0]; // C\r
-        ResidueColour[5] = colours[3]; // Q\r
-        ResidueColour[6] = colours[5]; // E\r
-        ResidueColour[7] = colours[7]; // G\r
-        ResidueColour[8] = colours[10]; // H\r
-        ResidueColour[9] = colours[0]; // I\r
-        ResidueColour[10] = colours[0]; // L\r
-        ResidueColour[11] = colours[4]; // K\r
-        ResidueColour[12] = colours[0]; // M\r
-        ResidueColour[13] = colours[0]; // F\r
-        ResidueColour[14] = colours[8]; // P\r
-        ResidueColour[15] = colours[1]; // S\r
-        ResidueColour[16] = colours[1]; // T\r
-        ResidueColour[17] = colours[0]; // W\r
-        ResidueColour[18] = colours[10]; // Y\r
-        ResidueColour[19] = colours[0]; // V\r
+      j++;\r
     }\r
 \r
-    public Color findColour(String s) {\r
-        return Color.pink;\r
+    this.size = seqs.size();\r
+    makeColours();\r
+  }\r
+\r
+  public void makeColours()\r
+  {\r
+    conses[0] = new Consensus("WLVIMAFCYHP", 60);\r
+    conses[1] = new Consensus("WLVIMAFCYHP", 80);\r
+    conses[2] = new Consensus("ED", 50);\r
+    conses[3] = new Consensus("KR", 60);\r
+    conses[4] = new Consensus("G", 50);\r
+    conses[5] = new Consensus("N", 50);\r
+    conses[6] = new Consensus("QE", 50);\r
+    conses[7] = new Consensus("P", 50);\r
+    conses[8] = new Consensus("TS", 50);\r
+\r
+    conses[26] = new Consensus("A", 85);\r
+    conses[27] = new Consensus("C", 85);\r
+    conses[10] = new Consensus("E", 85);\r
+    conses[11] = new Consensus("F", 85);\r
+    conses[12] = new Consensus("G", 85);\r
+    conses[13] = new Consensus("H", 85);\r
+    conses[14] = new Consensus("I", 85);\r
+    conses[15] = new Consensus("L", 85);\r
+    conses[16] = new Consensus("M", 85);\r
+    conses[17] = new Consensus("N", 85);\r
+    conses[18] = new Consensus("P", 85);\r
+    conses[19] = new Consensus("Q", 85);\r
+    conses[20] = new Consensus("R", 85);\r
+    conses[21] = new Consensus("S", 85);\r
+    conses[22] = new Consensus("T", 85);\r
+    conses[23] = new Consensus("V", 85);\r
+    conses[24] = new Consensus("W", 85);\r
+    conses[25] = new Consensus("Y", 85);\r
+    conses[28] = new Consensus("K", 85);\r
+    conses[29] = new Consensus("D", 85);\r
+\r
+    conses[30] = new Consensus("G", 0);\r
+    conses[31] = new Consensus("P", 0);\r
+\r
+    // We now construct the colours\r
+    colours = new ConsensusColour[11];\r
+\r
+    Consensus[] tmp8 = new Consensus[1];\r
+    tmp8[0] = conses[30]; //G\r
+    colours[7] = new ConsensusColour( (Color) colhash.get("ORANGE"), tmp8);\r
+\r
+    Consensus[] tmp9 = new Consensus[1];\r
+    tmp9[0] = conses[31]; //P\r
+    colours[8] = new ConsensusColour( (Color) colhash.get("YELLOW"), tmp9);\r
+\r
+    Consensus[] tmp10 = new Consensus[1];\r
+    tmp10[0] = conses[27]; //C\r
+    colours[9] = new ConsensusColour( (Color) colhash.get("PINK"), tmp8);\r
+\r
+    Consensus[] tmp1 = new Consensus[14];\r
+    tmp1[0] = conses[0]; //%\r
+    tmp1[1] = conses[1]; //#\r
+    tmp1[2] = conses[26]; //A\r
+    tmp1[3] = conses[27]; //C\r
+    tmp1[4] = conses[11]; //F\r
+    tmp1[5] = conses[13]; //H\r
+    tmp1[6] = conses[14]; //I\r
+    tmp1[7] = conses[15]; //L\r
+    tmp1[8] = conses[16]; //M\r
+    tmp1[9] = conses[23]; //V\r
+    tmp1[10] = conses[24]; //W\r
+    tmp1[11] = conses[25]; //Y\r
+    tmp1[12] = conses[18]; //P\r
+    tmp1[13] = conses[19]; //p\r
+    colours[0] = new ConsensusColour( (Color) colhash.get("BLUE"), tmp1);\r
+\r
+    colours[10] = new ConsensusColour( (Color) colhash.get("CYAN"), tmp1);\r
+\r
+    Consensus[] tmp2 = new Consensus[5];\r
+    tmp2[0] = conses[8]; //t\r
+    tmp2[1] = conses[21]; //S\r
+    tmp2[2] = conses[22]; //T\r
+    tmp2[3] = conses[0]; //%\r
+    tmp2[4] = conses[1]; //#\r
+    colours[1] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp2);\r
+\r
+    Consensus[] tmp3 = new Consensus[3];\r
+\r
+    tmp3[0] = conses[17]; //N\r
+    tmp3[1] = conses[29]; //D\r
+    tmp3[2] = conses[5]; //n\r
+    colours[2] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp3);\r
+\r
+    Consensus[] tmp4 = new Consensus[6];\r
+    tmp4[0] = conses[6]; // q = QE\r
+    tmp4[1] = conses[19]; //Q\r
+    tmp4[2] = conses[22]; //E\r
+    tmp4[3] = conses[3]; //+\r
+    tmp4[4] = conses[28]; //K\r
+    tmp4[5] = conses[20]; //R\r
+    colours[3] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp4);\r
+\r
+    Consensus[] tmp5 = new Consensus[4];\r
+    tmp5[0] = conses[3]; //+\r
+    tmp5[1] = conses[28]; //K\r
+    tmp5[2] = conses[20]; //R\r
+    tmp5[3] = conses[19]; //Q\r
+    colours[4] = new ConsensusColour( (Color) colhash.get("RED"), tmp5);\r
+\r
+    Consensus[] tmp6 = new Consensus[5];\r
+    tmp6[0] = conses[3]; //-\r
+    tmp6[1] = conses[29]; //D\r
+    tmp6[2] = conses[10]; //E\r
+    tmp6[3] = conses[6]; //q\r
+    tmp6[4] = conses[19]; //Q\r
+    colours[5] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp6);\r
+\r
+    Consensus[] tmp7 = new Consensus[5];\r
+    tmp7[0] = conses[3]; //-\r
+    tmp7[1] = conses[29]; //D\r
+    tmp7[2] = conses[10]; //E\r
+    tmp7[3] = conses[17]; //N\r
+    tmp7[4] = conses[2]; //DE\r
+    colours[6] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp7);\r
+\r
+    // Now attach the ConsensusColours to the residue letters\r
+    ResidueColour = new ConsensusColour[20];\r
+    ResidueColour[0] = colours[0]; // A\r
+    ResidueColour[1] = colours[4]; // R\r
+    ResidueColour[2] = colours[2]; // N\r
+    ResidueColour[3] = colours[6]; // D\r
+    ResidueColour[4] = colours[0]; // C\r
+    ResidueColour[5] = colours[3]; // Q\r
+    ResidueColour[6] = colours[5]; // E\r
+    ResidueColour[7] = colours[7]; // G\r
+    ResidueColour[8] = colours[10]; // H\r
+    ResidueColour[9] = colours[0]; // I\r
+    ResidueColour[10] = colours[0]; // L\r
+    ResidueColour[11] = colours[4]; // K\r
+    ResidueColour[12] = colours[0]; // M\r
+    ResidueColour[13] = colours[0]; // F\r
+    ResidueColour[14] = colours[8]; // P\r
+    ResidueColour[15] = colours[1]; // S\r
+    ResidueColour[16] = colours[1]; // T\r
+    ResidueColour[17] = colours[0]; // W\r
+    ResidueColour[18] = colours[10]; // Y\r
+    ResidueColour[19] = colours[0]; // V\r
+  }\r
+\r
+  public Color findColour(String s)\r
+  {\r
+    return Color.pink;\r
+  }\r
+\r
+  public Color findColour(String s, int j)\r
+  {\r
+    if ( (threshold != 0) && !aboveThreshold(s, j))\r
+    {\r
+      return Color.white;\r
     }\r
 \r
-    public Color findColour(String s, int j) {\r
-        if ((threshold != 0) && !aboveThreshold(s, j)) {\r
-            return Color.white;\r
-        }\r
-\r
-        int i = ((Integer) ResidueProperties.aaHash.get(s)).intValue();\r
+    int i = ( (Integer) ResidueProperties.aaHash.get(s)).intValue();\r
 \r
-        Color c = Color.white;\r
+    Color c = Color.white;\r
 \r
-        if (i > 19) {\r
-            return c;\r
-        }\r
-\r
-        for (int k = 0; k < ResidueColour[i].conses.length; k++)\r
-            if (ResidueColour[i].conses[k].isConserved(cons2, j, size)) {\r
-                c = ResidueColour[i].c;\r
-            }\r
+    if (i > 19)\r
+    {\r
+      return c;\r
+    }\r
 \r
-        if (i == 4) {\r
-            if (conses[27].isConserved(cons2, j, size)) {\r
-                c = (Color) colhash.get("PINK");\r
-            }\r
-        }\r
+    for (int k = 0; k < ResidueColour[i].conses.length; k++)\r
+    {\r
+      if (ResidueColour[i].conses[k].isConserved(cons2, j, size))\r
+      {\r
+        c = ResidueColour[i].c;\r
+      }\r
+    }\r
 \r
-        return c;\r
+    if (i == 4)\r
+    {\r
+      if (conses[27].isConserved(cons2, j, size))\r
+      {\r
+        c = (Color) colhash.get("PINK");\r
+      }\r
     }\r
-}\r
 \r
+    return c;\r
+  }\r
+}\r
 \r
-class ConsensusColour {\r
-    Consensus[] conses;\r
-    Color c;\r
+class ConsensusColour\r
+{\r
+  Consensus[] conses;\r
+  Color c;\r
 \r
-    public ConsensusColour(Color c, Consensus[] conses) {\r
-        this.conses = conses;\r
+  public ConsensusColour(Color c, Consensus[] conses)\r
+  {\r
+    this.conses = conses;\r
 \r
-        //    this.list = list;\r
-        this.c = c;\r
-    }\r
+    //    this.list = list;\r
+    this.c = c;\r
+  }\r
 }\r