Clustal colours now work
[jalview.git] / src / jalview / schemes / ClustalxColourScheme.java
index 128929c..b28ac76 100755 (executable)
@@ -17,6 +17,8 @@
  */\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
@@ -196,16 +216,35 @@ public class ClustalxColourScheme implements ColourSchemeI
     return Color.pink;\r
   }\r
 \r
+ public void setGroupSizeChanged(int i)\r
+ {\r
+   size = i;\r
+ }\r
+\r
   public Color findColour(String s, int j, Vector seqs)\r
-  {\r
+   {\r
+     int i = ((Integer)ResidueProperties.aaHash.get(s)).intValue();\r
 \r
-    int i = Integer.parseInt( ResidueProperties.aaHash.get(s).toString() );\r
+     Color c = Color.white;\r
 \r
-    if(i>22) // ie -, ., or space\r
-      return Color.white;\r
+     if(i>20)\r
+       return c;\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 == 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
-    return ResidueColour[i].c;\r
-  }\r
 \r
   public boolean canThreshold()\r
   {\r
@@ -217,6 +256,7 @@ public class ClustalxColourScheme implements ColourSchemeI
     return false;\r
   }\r
 \r
+\r
 }\r
 \r
 class ConsensusColour {\r
@@ -236,3 +276,12 @@ class ConsensusColour {
 \r
 \r
 \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r