JAL-4366 JAL-4371 allow cruft after inferred pdb ids, ex 1xyz_A.pdb yields 1xyzA
[jalview.git] / src / jalview / schemes / ClustalxColourScheme.java
index 19723ca..04097a8 100755 (executable)
  */
 package jalview.schemes;
 
+import java.awt.Color;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import jalview.api.AlignViewportI;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
 import jalview.util.Comparison;
 
-import java.awt.Color;
-import java.util.List;
-import java.util.Map;
-
 public class ClustalxColourScheme extends ResidueColourScheme
 {
   private static final int EIGHTY_FIVE = 85;
@@ -95,7 +97,7 @@ public class ClustalxColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public void alignmentChanged(AnnotatedCollectionI alignment,
+  public synchronized void alignmentChanged(AnnotatedCollectionI alignment,
           Map<SequenceI, SequenceCollectionI> hiddenReps)
   {
     int maxWidth = alignment.getWidth();
@@ -278,7 +280,7 @@ public class ClustalxColourScheme extends ResidueColourScheme
   }
 
   @Override
-  protected Color findColour(char c, int j, SequenceI seq)
+  protected synchronized Color findColour(char c, int j, SequenceI seq)
   {
     // TODO why the test for includeGaps here?
     if (cons2.length <= j || Comparison.isGap(c)
@@ -362,4 +364,63 @@ public class ClustalxColourScheme extends ResidueColourScheme
   {
     return false;
   }
+  public String toRuleRep()
+  {
+    makeColours();
+    HashMap<String, String> cols=new HashMap();
+    for (String res:ResidueProperties.aa) {
+      StringBuilder sb = new StringBuilder();
+      
+      int rnum=ResidueProperties.aaIndex[res.charAt(0)];
+      if (rnum<0 || rnum>=residueColour.length)
+      {
+        continue;
+      }
+      
+      ConsensusColour cc = residueColour[rnum];
+      if (cc==null)
+      {
+        continue;
+      }
+      //sb.append("Residue "+res+" ("+rnum+")");
+      //sb.append("\t");
+      sb.append(cc.c.toString());
+      double f=0;
+      sb.append("\t");
+      for (Consensus cons: cc.cons) {
+        if (cons.threshold==0 || f!=cons.threshold)
+        {
+          if (f!=0)
+          {
+
+              sb.append("}, {");
+          } else {
+          sb.append("{");
+          }
+        sb.append(cons.threshold);
+        sb.append(",");
+        f=cons.threshold;
+        } else {
+          sb.append(",");
+        }
+        sb.append(cons.maskstr);
+      }
+      sb.append("}");
+      String clxrep=sb.toString();
+      String xres = cols.get(clxrep);
+      if (xres==null) { xres = "";}
+      xres+=res;
+      cols.put(clxrep, xres);
+    }
+    StringBuilder sb = new StringBuilder();
+    for (String clxrep:cols.keySet())
+    {
+      sb.append(cols.get(clxrep));
+      sb.append("\t");
+      sb.append(clxrep);
+      sb.append("\n");
+      
+    }
+    return sb.toString();
+  }
 }