X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FConservationColourScheme.java;h=b47b01a7432fcece099a9cd392f545ab8ffc9de7;hb=1402060fb2ca7b2639ef98da3e22766d01149b16;hp=0eac54be7e14c89dae568ecbaa1d21a229f46fac;hpb=6a4192007f93c030726298295037f6eac97cf4f3;p=jalview.git diff --git a/src/jalview/schemes/ConservationColourScheme.java b/src/jalview/schemes/ConservationColourScheme.java index 0eac54b..b47b01a 100755 --- a/src/jalview/schemes/ConservationColourScheme.java +++ b/src/jalview/schemes/ConservationColourScheme.java @@ -1,138 +1,161 @@ -/* Jalview - a java multiple alignment editor - * Copyright (C) 1998 Michele Clamp - * - * 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. +/* +* Jalview - A Sequence Alignment Editor and Viewer +* Copyright (C) 2005 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.analysis.*; + +import java.awt.*; + +import java.util.Vector; + + +/** + * DOCUMENT ME! * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * @author $author$ + * @version $Revision$ */ +public class ConservationColourScheme extends ResidueColourScheme +{ + /** DOCUMENT ME!! */ + public Conservation conserve; + + /** DOCUMENT ME!! */ + public ColourSchemeI cs; + + /** DOCUMENT ME!! */ + public int inc = 30; + + /** + * Creates a new ConservationColourScheme object. + * + * @param cons DOCUMENT ME! + * @param oldcs DOCUMENT ME! + */ + public ConservationColourScheme(Conservation cons, ColourSchemeI oldcs) + { + super(); + conserve = cons; + cs = oldcs; + } -package jalview.schemes; -import java.awt.*; -import jalview.gui.*; -import jalview.datamodel.*; -import jalview.analysis.*; + /** + * DOCUMENT ME! + * + * @param consensus DOCUMENT ME! + */ + public void setConsensus(Vector consensus) + { + super.setConsensus(consensus); + + if (cs != null) + { + cs.setConsensus(consensus); + } + } -public class ConservationColourScheme extends ResidueColourScheme { - public Conservation conserve; - boolean byResidue = true; - public ColourSchemeI cs; - public int inc = 30; - int colourThreshold = 7; - - public ConservationColourScheme(SequenceGroup sg) - { - super(); - this.conserve = sg.getConservation(); - colourThreshold = 7; - this.cs = sg.cs; - } - - public void setColours(DrawableSequence seq, int j) { - Color c = Color.white; - String s = seq.getSequence().substring(j,j+1); - - if (colourThreshold > 0 && conserve.getConsSequence() != null) { - if (fullConservation(j)) { - if (byResidue) { - c = findColour(seq,s,j); - } else { - c = Color.red; - } - } else { - if (byResidue) { + /** + * DOCUMENT ME! + * + * @param s DOCUMENT ME! + * @param i DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Color findColour(String s, int i) + { + Color c = Color.white; + + if (cs == null) + { + return c; + } - int tmp = 10; - int t = Integer.parseInt(conserve.getConsSequence().getSequence().substring(j,j+1)); - c = findColour(seq,s,j); - - while (tmp >= t) { - // c = c.darker(); - c = lighter(c,inc); - tmp--; - } - } else { - c = Color.yellow; - } + char ch = conserve.getConsSequence().getSequence().charAt(i); + + if ((ch == '*') || (ch == '+')) + { + c = cs.findColour(s, i); } - } - - seq.setColor(c); - - } - public Color findColour(SequenceI seq, String s, int i, java.util.Vector whatever) - { - Color c = null; - if (colourThreshold > 0 && conserve.getConsSequence() != null) - { - if (fullConservation(i)) { - if (byResidue) { - c = findColour(null,s,i); - } else { - c = Color.red; - } - } else { - if (byResidue) { - - int tmp = 10; - int t = 0; - try - {t=Integer.parseInt(conserve.getConsSequence().getSequence().substring(i,i+1));} - catch(NumberFormatException ex){ - System.out.println("fix this bug, conserveColourScheme"); - t=0; - } - c = findColour(null,s,i); - - while (tmp >= t) { - // c = c.darker(); - c = lighter(c,inc); - tmp--; + else + { + int tmp = 10; + int t = 0; + + if (!jalview.util.Comparison.isGap(ch)) + { + t = Integer.parseInt(ch + ""); } - } else { - c = Color.yellow; - } - } - } - return c; - } - - public Color findColour(DrawableSequence seq, String s, int j) { - return cs.findColour(null, s, -1, null); - } - public boolean fullConservation(int j) { - String tmp = conserve.getConsSequence().getSequence().substring(j,j+1); - if (tmp.equals("*")) return true; else return false; - } - public boolean aboveThreshold(DrawableSequence seq, int j, int threshold) { - String tmp = conserve.getConsSequence().getSequence().substring(j,j+1); - - if (Integer.parseInt(tmp) >= threshold || tmp.equals("*")) { - return true; - } else { - return false; + + c = cs.findColour(s, i); + + while (tmp >= t) + { + c = lighter(c, inc); + tmp--; + } + } + + return c; } - } - public Color lighter(Color c, int inc) { - int red = c.getRed(); - int blue = c.getBlue(); - int green = c.getGreen(); + /** + * DOCUMENT ME! + * + * @param c DOCUMENT ME! + * @param inc DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public Color lighter(Color c, int inc) + { + int red = c.getRed(); + int blue = c.getBlue(); + int green = c.getGreen(); + + if (red < (255 - inc)) + { + red = red + inc; + } + else + { + red = 255; + } - 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;} + if (blue < (255 - inc)) + { + blue = blue + inc; + } + else + { + blue = 255; + } - return new Color(red,green,blue); - } + if (green < (255 - inc)) + { + green = green + inc; + } + else + { + green = 255; + } + return new Color(red, green, blue); + } }