X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fschemes%2FResidueColourScheme.java;h=c435f7dc264687811c7001b68c8d62b6800d1c23;hb=95a46891288f4fc63d690cab4f56879678f54fb6;hp=9c10e7d8e1101c95b193233ff6c60c781de3b020;hpb=efc31b4a8d5cee63555586804a2b79c06bdb5a14;p=jalview.git diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index 9c10e7d..c435f7d 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -18,6 +18,8 @@ */ package jalview.schemes; +import jalview.analysis.*; + import java.awt.*; import java.util.*; @@ -31,11 +33,31 @@ import java.util.*; */ public class ResidueColourScheme implements ColourSchemeI { + + boolean conservationColouring = false; + boolean consensusColouring = false; + Color[] colors; int threshold = 0; - /** DOCUMENT ME!! */ - public Vector consensus; + /* Set when threshold colouring to either pid_gaps or pid_nogaps*/ + protected String ignoreGaps = "pid_gaps"; + + /** Consenus as a hashtable array */ + Hashtable [] consensus; + + /** Conservation string as a char array */ + char [] conservation; + + /** DOCUMENT ME!! */ + int inc = 30; + + /** + * The colour to be calculated, manipulated and returned + */ + Color currentColour = null; + + /** * Creates a new ResidueColourScheme object. @@ -43,9 +65,9 @@ public class ResidueColourScheme implements ColourSchemeI * @param colors DOCUMENT ME! * @param threshold DOCUMENT ME! */ - public ResidueColourScheme(Color[] colors, int threshold) + public ResidueColourScheme(Color[] colours, int threshold) { - this.colors = colors; + this.colors = colours; this.threshold = threshold; } @@ -57,25 +79,59 @@ public class ResidueColourScheme implements ColourSchemeI } /** - * DOCUMENT ME! + * Find a colour without an index in a sequence + */ + public Color findColour(String aa) + { + return colors[((Integer) (ResidueProperties.aaHash.get(aa))).intValue()]; + } + + + + public Color findColour(String s, int j) + { + + int index = ((Integer) (ResidueProperties.aaHash.get(s))).intValue(); + + if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j)) + { + currentColour = colors[index]; + } + else + { + currentColour = Color.white; + } + + if(conservationColouring) + applyConservation(j); + + + return currentColour; + } + + + /** + * Get the percentage threshold for this colour scheme * - * @param consensus DOCUMENT ME! + * @return Returns the percentage threshold */ - public void setConsensus(Vector consensus) + public int getThreshold() { - this.consensus = consensus; + return threshold; } /** * DOCUMENT ME! * - * @param aa DOCUMENT ME! - * - * @return DOCUMENT ME! + * @param ct DOCUMENT ME! */ - public Color findColour(String aa) + public void setThreshold(int ct, boolean ignoreGaps) { - return colors[((Integer) (ResidueProperties.aaHash.get(aa))).intValue()]; + threshold = ct; + if(ignoreGaps) + this.ignoreGaps = "pid_nogaps"; + else + this.ignoreGaps = "pid_gaps"; } /** @@ -86,63 +142,141 @@ public class ResidueColourScheme implements ColourSchemeI * * @return DOCUMENT ME! */ - public Color findColour(String s, int j) + public boolean aboveThreshold(String s, int j) { - if ((threshold == 0) || aboveThreshold(s, j)) + if ((((Integer) consensus[j].get("maxCount")).intValue() != -1) && + consensus[j].contains(s)) { - return colors[((Integer) (ResidueProperties.aaHash.get(s))).intValue()]; - } - else - { - return Color.white; + if (((Float)consensus[j].get(ignoreGaps)).floatValue() >= threshold) + { + return true; + } } + + return false; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public int getThreshold() + + public boolean conservationApplied() { - return threshold; + return conservationColouring; } - /** - * DOCUMENT ME! - * - * @param ct DOCUMENT ME! - */ - public void setThreshold(int ct) + public void setConservationInc(int i) { - threshold = ct; + inc = i; + } + + public int getConservationInc() + { + return inc; } /** * DOCUMENT ME! * - * @param s DOCUMENT ME! - * @param j DOCUMENT ME! - * - * @return DOCUMENT ME! + * @param consensus DOCUMENT ME! */ - public boolean aboveThreshold(String s, int j) + public void setConsensus(Vector vconsensus) { - Hashtable hash = (Hashtable) consensus.elementAt(j); + int i, iSize=vconsensus.size(); + consensus = new Hashtable[iSize]; + for(i=0; i= threshold) - { - return true; - } - } + public void setConservation(Conservation cons) + { + if(cons==null) + { + conservationColouring = false; + conservation = null; + } + else + { + conservationColouring = true; + int i, iSize = cons.getConsSequence().getLength(); + conservation = new char[iSize]; + for (i = 0; i < iSize; i++) + conservation[i] = cons.getConsSequence().getCharAt(i); + } - return false; } + + + /** + * DOCUMENT ME! + * + * @param s DOCUMENT ME! + * @param i DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + void applyConservation(int i) + { + if ((conservation[i] != '*') && (conservation[i] != '+')) + { + int tmp = 10; + int t = 0; + + if (!jalview.util.Comparison.isGap(conservation[i])) + { + t = conservation[i]-'0'; + } + + while (tmp >= t) + { + lighter(inc); + tmp--; + } + } + + } + + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + * @param inc DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + void lighter(int inc) + { + int red = currentColour.getRed(); + int blue = currentColour.getBlue(); + int green = currentColour.getGreen(); + + if (red < (255 - inc)) + { + red = red + inc; + } + else + { + red = 255; + } + + if (blue < (255 - inc)) + { + blue = blue + inc; + } + else + { + blue = 255; + } + + if (green < (255 - inc)) + { + green = green + inc; + } + else + { + green = 255; + } + + currentColour = new Color(red, green, blue); + } + + }