X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FResidueColourScheme.java;h=f43aa020f193df136b1492ce5918b48d149bf873;hb=349ef01fe53c28dc78bec2d321f9c833a4b6e023;hp=f90f47589dbfa715e43d21a257478fc0dc1c32e6;hpb=1ecf6419aba86993b3c223bf5ec0fa79427baf85;p=jalview.git diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index f90f475..f43aa02 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -1,113 +1,271 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 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 + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ package jalview.schemes; -import jalview.datamodel.*; -import jalview.jbgui.*; - import java.util.*; + import java.awt.*; -public class ResidueColourScheme implements ColourSchemeI { - Color [] colors; - int threshold = 90; +import jalview.analysis.*; - public ResidueColourScheme(Color[] colors, int threshold) { - this.colors = colors; - this.threshold = threshold; - } +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class ResidueColourScheme + implements ColourSchemeI +{ - public ResidueColourScheme() { - } + boolean conservationColouring = false; - public Color findColour(String aa) - { - return colors[((Integer)(ResidueProperties.aaHash.get(aa))).intValue()]; - } + Color[] colors; + int threshold = 0; - public Color findColour(SequenceI seq,String s, int j, Vector aa) { - try { - return colors[((Integer)(ResidueProperties.aaHash.get(s))).intValue()]; - } catch (Exception e) { - return Color.white; - } - } + /* Set when threshold colouring to either pid_gaps or pid_nogaps*/ + protected String ignoreGaps = AAFrequency.PID_GAPS; - // aa should maybe be a class - public Color getColour(SequenceI seq, int j,Vector aa) { + /** Consenus as a hashtable array */ + Hashtable[] consensus; - Color c = Color.white; - String s = seq.getSequence(j,j+1); + /** Conservation string as a char array */ + char[] conservation; + int conservationLength=0; - if (threshold > 0 && aa != null) - { - if (aboveThreshold(aa,seq,j,threshold)) - c = findColour(seq,s,j,aa); - } - else - c = findColour(seq,s,j,aa); + /** DOCUMENT ME!! */ + int inc = 30; + + /** + * Creates a new ResidueColourScheme object. + * + * @param colors DOCUMENT ME! + * @param threshold DOCUMENT ME! + */ + public ResidueColourScheme(Color[] colours, int threshold) + { + this.colors = colours; + this.threshold = threshold; + } + + /** + * Creates a new ResidueColourScheme object. + */ + public ResidueColourScheme() + { + } + /** + * Find a colour without an index in a sequence + */ + public Color findColour(char c) + { + return colors[ResidueProperties.aaIndex[c]]; + } - return c; + public Color findColour(char c, int j) + { + Color currentColour; + + if ( (threshold == 0) || aboveThreshold(c, j)) + { + currentColour = colors[ResidueProperties.aaIndex[c]]; } - public int getThreshold() { - return threshold; + else + { + currentColour = Color.white; } - public void setThreshold(int ct) { - threshold = ct; + if (conservationColouring) + { + currentColour = applyConservation(currentColour, j); } - public Vector getColours(SequenceI s, Vector aa) { - Vector colours = new Vector(); + return currentColour; + } - for (int j = 0; j < s.getLength(); j++) - colours.addElement(getColour(s,j,aa)); + /** + * Get the percentage threshold for this colour scheme + * + * @return Returns the percentage threshold + */ + public int getThreshold() + { + return threshold; + } - return colours; + /** + * DOCUMENT ME! + * + * @param ct DOCUMENT ME! + */ + public void setThreshold(int ct, boolean ignoreGaps) + { + threshold = ct; + if (ignoreGaps) + { + this.ignoreGaps = AAFrequency.PID_NOGAPS; } + else + { + this.ignoreGaps = AAFrequency.PID_GAPS; + } + } - public Vector getColours(SequenceGroup sg, Vector aa) { - Vector colours = new Vector(); - - for (int j = 0; j < sg.getSize(); j++) { - SequenceI s = sg.getSequenceAt(j); + /** + * DOCUMENT ME! + * + * @param s DOCUMENT ME! + * @param j DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean aboveThreshold(char c, int j) + { + if ('a' <= c && c <= 'z') + { + // TO UPPERCASE !!! + //Faster than toUpperCase + c -= ('a' - 'A'); + } - for (int i = 0; i < s.getLength();i++) { - colours.addElement(getColour(s,i,aa)); - } - } - return colours; + if (consensus == null || consensus.length= threshold) + { + return true; + } + } - if (j < aa.size()) { - String maxRes = (String)hash.get("maxResidue"); + return false; + } - double sc = 0; + public boolean conservationApplied() + { + return conservationColouring; + } - if (((Integer)hash.get("maxCount")).intValue() != -1 && hash.contains(s)) { - int maxCount = ((Integer)hash.get("maxCount")).intValue(); - int resCount = ((Integer)hash.get(s)).intValue(); + public void setConservationInc(int i) + { + inc = i; + } - sc = resCount * 100.0 / resCount; + public int getConservationInc() + { + return inc; + } - // This should be isGap somewhere - if ( !s.equals("-") && !s.equals(".") && !s.equals(" ")) { - if (sc >= (double)threshold) { - return true; - } - } - } - } - return false; + /** + * DOCUMENT ME! + * + * @param consensus DOCUMENT ME! + */ + public void setConsensus(Hashtable[] consensus) + { + if (consensus == null) + { + return; } - public boolean canThreshold() { - return true; + this.consensus = consensus; + } + + public void setConservation(Conservation cons) + { + if (cons == null) + { + conservationColouring = false; + conservation = null; } - public boolean isUserDefinable() { - return false; + 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); + } + conservationLength = conservation.length; + } + + } + + /** + * DOCUMENT ME! + * + * @param s DOCUMENT ME! + * @param i DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + + Color applyConservation(Color currentColour, int i) + { + + if ((conservationLength>i) && (conservation[i] != '*') && (conservation[i] != '+')) + { + if ( jalview.util.Comparison.isGap(conservation[i])) + { + currentColour = Color.white; + } + else + { + float t = 11 - (conservation[i] - '0'); + if (t == 0) + { + return Color.white; + } + + int red = currentColour.getRed(); + int green = currentColour.getGreen(); + int blue = currentColour.getBlue(); + + 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); + } + } } + return currentColour; + } + }