Clustal colours now work
[jalview.git] / src / jalview / schemes / ClustalxColourScheme.java
index 0479e5c..b28ac76 100755 (executable)
  * along with this program; if not, write to the Free Software\r
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
  */\r
-/*\r
+\r
 package jalview.schemes;\r
+\r
+import jalview.datamodel.*;\r
 import java.util.*;\r
 import java.awt.*;\r
 \r
@@ -42,14 +44,32 @@ public class ClustalxColourScheme implements ColourSchemeI
 \r
     }\r
   Vector colourTable = new Vector();\r
-  public ClustalxColourScheme() {\r
-    this.cons2 = null;\r
-    this.size = 0;\r
-    makeColours();\r
-  }\r
-  public ClustalxColourScheme(int[][] cons2, int size) {\r
-    this.cons2 = cons2;\r
-    this.size = size;\r
+\r
+\r
+  public ClustalxColourScheme(Vector seqs, int maxWidth)\r
+  {\r
+    cons2 = new int[maxWidth][24];\r
+    int start = 0, end = maxWidth-1;\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,i, j = 0;\r
+      String seq;\r
+      while(j < seqs.size())\r
+      {\r
+        seq = ( (SequenceI) seqs.get(j)).getSequence();\r
+        for (i = start; i <= end; i++)\r
+        {\r
+          res = ( (Integer) ResidueProperties.aaHash.get(seq.charAt(i) + "")).intValue();\r
+          cons2[i][res]++;\r
+        }\r
+        j++;\r
+      }\r
+\r
+    this.size = seqs.size();\r
     makeColours();\r
   }\r
   public void makeColours() {\r
@@ -191,55 +211,75 @@ public class ClustalxColourScheme implements ColourSchemeI
     ResidueColour[19] = colours[0]; // V\r
   }\r
 \r
-  public Color findColour(DrawableSequence seq, String s, int j) {\r
-    // System.out.println("Finding colour for " + s + " " + j);\r
-    int i = seq.num[j];\r
-    Color c = Color.white;\r
-    for (int k=0; k < ResidueColour[i].conses.length ; k++) {\r
-      if (ResidueColour[i].conses[k].isConserved(cons2,j,seq.num[j],size)) {\r
-        c =  ResidueColour[i].c;\r
-      }\r
-    }\r
-    if (i ==4) {\r
-      if (conses[27].isConserved(cons2,j,seq.num[j],size)) {\r
-        c = (Color)colhash.get("PINK");\r
-      }\r
-    }\r
-    return c;\r
+  public Color findColour(String s)\r
+  {\r
+    return Color.pink;\r
   }\r
 \r
-  public void setColours(DrawableSequence seq, int j) {\r
-    Color c = Color.white;\r
+ public void setGroupSizeChanged(int i)\r
+ {\r
+   size = i;\r
+ }\r
+\r
+  public Color findColour(String s, int j, Vector seqs)\r
+   {\r
+     int i = ((Integer)ResidueProperties.aaHash.get(s)).intValue();\r
+\r
+     Color c = Color.white;\r
+\r
+     if(i>20)\r
+       return c;\r
 \r
-    String s = seq.getSequence().substring(j,j+1);\r
-    try {\r
-      c = findColour(seq,s,j);\r
-      seq.setResidueBoxColour(j,c);\r
-    } catch (Exception e) {\r
-      seq.setResidueBoxColour(j,Color.white);\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 == 4)\r
+    {\r
+      if (conses[27].isConserved(cons2, j, size))\r
+        c = (Color) colhash.get("PINK");\r
     }\r
+\r
+\r
+     return c;\r
+\r
+   }\r
+\r
+\r
+  public boolean canThreshold()\r
+  {\r
+    return false;\r
   }\r
 \r
-  public void setColours(DrawableSequence s) {\r
-    for (int j = 0; j < s.sequence.length(); j++) {\r
-      setColours(s,j);\r
-    }\r
+  public boolean isUserDefinable()\r
+  {\r
+    return false;\r
   }\r
 \r
-  public void setColours(SequenceGroup sg) {\r
-    for (int j = 0; j < sg.sequences.size(); j++) {\r
 \r
-      DrawableSequence s = (DrawableSequence)sg.sequences.elementAt(j);\r
-      for (int i = 0; i < s.getSequence().length();i++) {\r
-        setColours(s,i);\r
-      }\r
-    }\r
-  }\r
+}\r
 \r
+class ConsensusColour {\r
 \r
+  Consensus[] conses;\r
+  Color c;\r
+\r
+  public ConsensusColour(Color c,Consensus[] conses) {\r
+    this.conses = conses;\r
+    //    this.list = list;\r
+    this.c = c;\r
+  }\r
 }\r
 \r
-*/\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
 \r
 \r
 \r