X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FResidueColourScheme.java;h=b905c452ba87dcce2683ded2f74c2ec0fdc5cd36;hb=d640a8ce605b836b2e6eb1771994d3baef5c31a0;hp=c435f7dc264687811c7001b68c8d62b6800d1c23;hpb=95a46891288f4fc63d690cab4f56879678f54fb6;p=jalview.git diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index c435f7d..b905c45 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -41,7 +41,7 @@ public class ResidueColourScheme implements ColourSchemeI int threshold = 0; /* Set when threshold colouring to either pid_gaps or pid_nogaps*/ - protected String ignoreGaps = "pid_gaps"; + protected String ignoreGaps = AAFrequency.PID_GAPS; /** Consenus as a hashtable array */ Hashtable [] consensus; @@ -52,12 +52,6 @@ public class ResidueColourScheme implements ColourSchemeI /** DOCUMENT ME!! */ int inc = 30; - /** - * The colour to be calculated, manipulated and returned - */ - Color currentColour = null; - - /** * Creates a new ResidueColourScheme object. @@ -83,15 +77,15 @@ public class ResidueColourScheme implements ColourSchemeI */ public Color findColour(String aa) { - return colors[((Integer) (ResidueProperties.aaHash.get(aa))).intValue()]; + return colors[ResidueProperties.aaIndex[aa.charAt(0)]]; } public Color findColour(String s, int j) { - - int index = ((Integer) (ResidueProperties.aaHash.get(s))).intValue(); + Color currentColour; + int index = ResidueProperties.aaIndex[s.charAt(0)]; if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j)) { @@ -103,7 +97,7 @@ public class ResidueColourScheme implements ColourSchemeI } if(conservationColouring) - applyConservation(j); + currentColour = applyConservation(currentColour, j); return currentColour; @@ -129,9 +123,9 @@ public class ResidueColourScheme implements ColourSchemeI { threshold = ct; if(ignoreGaps) - this.ignoreGaps = "pid_nogaps"; + this.ignoreGaps = AAFrequency.PID_NOGAPS; else - this.ignoreGaps = "pid_gaps"; + this.ignoreGaps = AAFrequency.PID_GAPS; } /** @@ -144,13 +138,25 @@ public class ResidueColourScheme implements ColourSchemeI */ public boolean aboveThreshold(String s, int j) { - if ((((Integer) consensus[j].get("maxCount")).intValue() != -1) && - consensus[j].contains(s)) + char c = s.charAt(0); + if ('a' <= c && c <= 'z') { - if (((Float)consensus[j].get(ignoreGaps)).floatValue() >= threshold) - { - return true; - } + // TO UPPERCASE !!! + //Faster than toUpperCase + c -= ('a' - 'A'); + s = String.valueOf(c); + } + + if (consensus == null || consensus[j] == null) + return false; + + if ( ( ( (Integer) consensus[j].get(AAFrequency.MAXCOUNT)).intValue() != -1) && + consensus[j].contains(s)) + { + if ( ( (Float) consensus[j].get(ignoreGaps)).floatValue() >= threshold) + { + return true; + } } return false; @@ -177,15 +183,16 @@ public class ResidueColourScheme implements ColourSchemeI * * @param consensus DOCUMENT ME! */ - public void setConsensus(Vector vconsensus) + public void setConsensus(Hashtable [] consensus) { - int i, iSize=vconsensus.size(); - consensus = new Hashtable[iSize]; - for(i=0; i= t) - { - lighter(inc); - tmp--; - } - } - } - - /** - * DOCUMENT ME! - * - * @param c DOCUMENT ME! - * @param inc DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - void lighter(int inc) + Color applyConservation(Color currentColour, int i) { - int red = currentColour.getRed(); - int blue = currentColour.getBlue(); - int green = currentColour.getGreen(); - if (red < (255 - inc)) + if ((conservation[i] != '*') && (conservation[i] != '+')) + { + if(jalview.util.Comparison.isGap(conservation[i])) { - red = red + inc; + currentColour = Color.white; } else { - red = 255; - } + float t = 11 - (conservation[i] - '0'); + if(t==0) + { + return Color.white; + } - if (blue < (255 - inc)) - { - blue = blue + inc; - } - else - { - blue = 255; - } + int red = currentColour.getRed(); + int green = currentColour.getGreen(); + int blue = currentColour.getBlue(); - if (green < (255 - inc)) - { - green = green + inc; + int dr = 255 - red; + int dg = 255 - green; + int db = 255 - blue; + + dr *= t / 10f; + dg *= t / 10f; + db *= t / 10f; + + red += (inc / 20f) * dr; + green += (inc / 20f) * dg; + blue += (inc / 20f) * db; + + if (red > 255 || green > 255 || blue > 255) + currentColour = Color.white; + else + currentColour = new Color(red, green, blue); } - else - { - green = 255; } - - currentColour = new Color(red, green, blue); + return currentColour; }