X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FClustalxColourScheme.java;h=8dd8994d8f61f93d7045b9513c27568bc381ce96;hb=684da8b2ac49893bb776763b317a2bf24b9e5501;hp=b28ac7679efe7e260671db6bdb1a6544f9cbe42c;hpb=0f530039f8c0ac9c6613063a576c3a13c8644fcd;p=jalview.git diff --git a/src/jalview/schemes/ClustalxColourScheme.java b/src/jalview/schemes/ClustalxColourScheme.java index b28ac76..8dd8994 100755 --- a/src/jalview/schemes/ClustalxColourScheme.java +++ b/src/jalview/schemes/ClustalxColourScheme.java @@ -1,5 +1,6 @@ -/* Jalview - a java multiple alignment editor - * Copyright (C) 1998 Michele Clamp +/* + * 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 @@ -13,115 +14,141 @@ * * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - package jalview.schemes; -import jalview.datamodel.*; import java.util.*; + import java.awt.*; -public class ClustalxColourScheme implements ColourSchemeI +import jalview.datamodel.*; + +public class ClustalxColourScheme + extends ResidueColourScheme { + public static Hashtable colhash = new Hashtable(); Hashtable[] cons; int[][] cons2; ConsensusColour[] colours; ConsensusColour[] ResidueColour; int size; - Consensus[] conses = new Consensus[32]; - public static Hashtable colhash = new Hashtable(); - - { - colhash.put("RED",new Color((float)0.9,(float)0.2,(float)0.1)); - colhash.put("BLUE",new Color((float)0.5,(float)0.7,(float)0.9)); - colhash.put("GREEN",new Color((float)0.1,(float)0.8,(float)0.1)); - colhash.put("ORANGE",new Color((float)0.9,(float)0.6,(float)0.3)); - colhash.put("CYAN",new Color((float)0.1,(float)0.7,(float)0.7)); - colhash.put("PINK",new Color((float)0.9,(float)0.5,(float)0.5)); - colhash.put("MAGENTA",new Color((float)0.8,(float)0.3,(float)0.8)); - colhash.put("YELLOW",new Color((float)0.8,(float)0.8,(float)0.0)); - - } + Consensus[] conses = new Consensus[32]; Vector colourTable = new Vector(); + { + colhash.put("RED", new Color( (float) 0.9, (float) 0.2, (float) 0.1)); + colhash.put("BLUE", new Color( (float) 0.5, (float) 0.7, (float) 0.9)); + colhash.put("GREEN", new Color( (float) 0.1, (float) 0.8, (float) 0.1)); + colhash.put("ORANGE", new Color( (float) 0.9, (float) 0.6, (float) 0.3)); + colhash.put("CYAN", new Color( (float) 0.1, (float) 0.7, (float) 0.7)); + colhash.put("PINK", new Color( (float) 0.9, (float) 0.5, (float) 0.5)); + colhash.put("MAGENTA", new Color( (float) 0.8, (float) 0.3, (float) 0.8)); + colhash.put("YELLOW", new Color( (float) 0.8, (float) 0.8, (float) 0.0)); + } public ClustalxColourScheme(Vector seqs, int maxWidth) { + resetClustalX(seqs, maxWidth); + } + + public void resetClustalX(Vector seqs, int maxWidth) + { cons2 = new int[maxWidth][24]; - int start = 0, end = maxWidth-1; + + int start = 0; // Initialize the array - for (int j=0;j<24;j++) - for (int i=0; i < maxWidth;i++) + for (int j = 0; j < 24; j++) + { + for (int i = 0; i < maxWidth; i++) + { cons2[i][j] = 0; + } + } - int res,i, j = 0; - String seq; - while(j < seqs.size()) + int res; + int i; + int j = 0; + char[] seq; + + while (j < seqs.size()) + { + seq = ( (SequenceI) seqs.elementAt(j)).getSequence(); + + int end_j = seq.length - 1; + + for (i = start; i <= end_j; i++) { - seq = ( (SequenceI) seqs.get(j)).getSequence(); - for (i = start; i <= end; i++) + if ( (seq.length - 1) < i) + { + res = 23; + } + else { - res = ( (Integer) ResidueProperties.aaHash.get(seq.charAt(i) + "")).intValue(); - cons2[i][res]++; + res = ResidueProperties.aaIndex[seq[i]]; } - j++; + + cons2[i][res]++; } + j++; + } + this.size = seqs.size(); makeColours(); } - public void makeColours() { - conses[0] = new Consensus("WLVIMAFCYHP",60); - conses[1] = new Consensus("WLVIMAFCYHP",80); - conses[2] = new Consensus("ED",50); - conses[3] = new Consensus("KR",60); - conses[4] = new Consensus("G",50); - conses[5] = new Consensus("N",50); - conses[6] = new Consensus("QE",50); - conses[7] = new Consensus("P",50); - conses[8] = new Consensus("TS",50); - - conses[26] = new Consensus("A",85); - conses[27] = new Consensus("C",85); - conses[10] = new Consensus("E",85); - conses[11] = new Consensus("F",85); - conses[12] = new Consensus("G",85); - conses[13] = new Consensus("H",85); - conses[14] = new Consensus("I",85); - conses[15] = new Consensus("L",85); - conses[16] = new Consensus("M",85); - conses[17] = new Consensus("N",85); - conses[18] = new Consensus("P",85); - conses[19] = new Consensus("Q",85); - conses[20] = new Consensus("R",85); - conses[21] = new Consensus("S",85); - conses[22] = new Consensus("T",85); - conses[23] = new Consensus("V",85); - conses[24] = new Consensus("W",85); - conses[25] = new Consensus("Y",85); - conses[28] = new Consensus("K",85); - conses[29] = new Consensus("D",85); - - conses[30] = new Consensus("G",0); - conses[31] = new Consensus("P",0); + + public void makeColours() + { + conses[0] = new Consensus("WLVIMAFCYHP", 60); + conses[1] = new Consensus("WLVIMAFCYHP", 80); + conses[2] = new Consensus("ED", 50); + conses[3] = new Consensus("KR", 60); + conses[4] = new Consensus("G", 50); + conses[5] = new Consensus("N", 50); + conses[6] = new Consensus("QE", 50); + conses[7] = new Consensus("P", 50); + conses[8] = new Consensus("TS", 50); + + conses[26] = new Consensus("A", 85); + conses[27] = new Consensus("C", 85); + conses[10] = new Consensus("E", 85); + conses[11] = new Consensus("F", 85); + conses[12] = new Consensus("G", 85); + conses[13] = new Consensus("H", 85); + conses[14] = new Consensus("I", 85); + conses[15] = new Consensus("L", 85); + conses[16] = new Consensus("M", 85); + conses[17] = new Consensus("N", 85); + conses[18] = new Consensus("P", 85); + conses[19] = new Consensus("Q", 85); + conses[20] = new Consensus("R", 85); + conses[21] = new Consensus("S", 85); + conses[22] = new Consensus("T", 85); + conses[23] = new Consensus("V", 85); + conses[24] = new Consensus("W", 85); + conses[25] = new Consensus("Y", 85); + conses[28] = new Consensus("K", 85); + conses[29] = new Consensus("D", 85); + + conses[30] = new Consensus("G", 0); + conses[31] = new Consensus("P", 0); // We now construct the colours colours = new ConsensusColour[11]; - Consensus[] tmp8 = new Consensus[1]; - tmp8[0] = conses[30];//G - colours[7] =new ConsensusColour((Color)colhash.get("ORANGE"),tmp8); + tmp8[0] = conses[30]; //G + colours[7] = new ConsensusColour( (Color) colhash.get("ORANGE"), tmp8); Consensus[] tmp9 = new Consensus[1]; - tmp9[0] = conses[31];//P - colours[8] =new ConsensusColour((Color)colhash.get("YELLOW"),tmp9); + tmp9[0] = conses[31]; //P + colours[8] = new ConsensusColour( (Color) colhash.get("YELLOW"), tmp9); Consensus[] tmp10 = new Consensus[1]; - tmp10[0] = conses[27];//C - colours[9] =new ConsensusColour((Color)colhash.get("PINK"),tmp8); + tmp10[0] = conses[27]; //C + colours[9] = new ConsensusColour( (Color) colhash.get("PINK"), tmp8); Consensus[] tmp1 = new Consensus[14]; tmp1[0] = conses[0]; //% @@ -138,54 +165,56 @@ public class ClustalxColourScheme implements ColourSchemeI tmp1[11] = conses[25]; //Y tmp1[12] = conses[18]; //P tmp1[13] = conses[19]; //p - colours[0] = new ConsensusColour((Color)colhash.get("BLUE"),tmp1); + colours[0] = new ConsensusColour( (Color) colhash.get("BLUE"), tmp1); - colours[10] = new ConsensusColour((Color)colhash.get("CYAN"),tmp1); + colours[10] = new ConsensusColour( (Color) colhash.get("CYAN"), tmp1); Consensus[] tmp2 = new Consensus[5]; - tmp2[0] = conses[8]; //t + tmp2[0] = conses[8]; //t tmp2[1] = conses[21]; //S tmp2[2] = conses[22]; //T - tmp2[3] = conses[0]; //% - tmp2[4] = conses[1]; //# - colours[1] = new ConsensusColour((Color)colhash.get("GREEN"),tmp2); + tmp2[3] = conses[0]; //% + tmp2[4] = conses[1]; //# + colours[1] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp2); Consensus[] tmp3 = new Consensus[3]; tmp3[0] = conses[17]; //N tmp3[1] = conses[29]; //D - tmp3[2] = conses[5]; //n - colours[2] = new ConsensusColour((Color)colhash.get("GREEN"),tmp3); + tmp3[2] = conses[5]; //n + colours[2] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp3); Consensus[] tmp4 = new Consensus[6]; - tmp4[0] = conses[6]; // q = QE + tmp4[0] = conses[6]; // q = QE tmp4[1] = conses[19]; //Q tmp4[2] = conses[22]; //E - tmp4[3] = conses[3]; //+ + tmp4[3] = conses[3]; //+ tmp4[4] = conses[28]; //K tmp4[5] = conses[20]; //R - colours[3] = new ConsensusColour((Color)colhash.get("GREEN"),tmp4); + colours[3] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp4); + Consensus[] tmp5 = new Consensus[4]; - tmp5[0] = conses[3]; //+ + tmp5[0] = conses[3]; //+ tmp5[1] = conses[28]; //K tmp5[2] = conses[20]; //R tmp5[3] = conses[19]; //Q - colours[4] = new ConsensusColour((Color)colhash.get("RED"),tmp5); + colours[4] = new ConsensusColour( (Color) colhash.get("RED"), tmp5); + Consensus[] tmp6 = new Consensus[5]; - tmp6[0] = conses[3]; //- + tmp6[0] = conses[3]; //- tmp6[1] = conses[29]; //D tmp6[2] = conses[10]; //E - tmp6[3] = conses[6]; //q + tmp6[3] = conses[6]; //q tmp6[4] = conses[19]; //Q - colours[5] = new ConsensusColour((Color)colhash.get("MAGENTA"),tmp6); + colours[5] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp6); Consensus[] tmp7 = new Consensus[5]; - tmp7[0] = conses[3]; //- + tmp7[0] = conses[3]; //- tmp7[1] = conses[29]; //D tmp7[2] = conses[10]; //E - tmp7[3] = conses[17]; //N + tmp7[3] = conses[17]; //N tmp7[4] = conses[2]; //DE - colours[6] = new ConsensusColour((Color)colhash.get("MAGENTA"),tmp7); + colours[6] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp7); // Now attach the ConsensusColours to the residue letters ResidueColour = new ConsensusColour[20]; @@ -211,77 +240,64 @@ public class ClustalxColourScheme implements ColourSchemeI ResidueColour[19] = colours[0]; // V } - public Color findColour(String s) + public Color findColour(char c) { return Color.pink; } - public void setGroupSizeChanged(int i) - { - size = i; - } - - public Color findColour(String s, int j, Vector seqs) - { - int i = ((Integer)ResidueProperties.aaHash.get(s)).intValue(); + public Color findColour(char c, int j) + { + Color currentColour; - Color c = Color.white; + if (cons2.length <= j || (threshold != 0 && !aboveThreshold(c, j))) + { + return Color.white; + } - if(i>20) - return c; + int i = ResidueProperties.aaIndex[c]; - for (int k=0; k < ResidueColour[i].conses.length ; k++) - if (ResidueColour[i].conses[k].isConserved(cons2,j,size)) - c = ResidueColour[i].c; + currentColour = Color.white; - if (i == 4) + if (i > 19) { - if (conses[27].isConserved(cons2, j, size)) - c = (Color) colhash.get("PINK"); + return currentColour; } + for (int k = 0; k < ResidueColour[i].conses.length; k++) + { + if (ResidueColour[i].conses[k].isConserved(cons2, j, size)) + { + currentColour = ResidueColour[i].c; + } + } - return c; - - } - + if (i == 4) + { + if (conses[27].isConserved(cons2, j, size)) + { + currentColour = (Color) colhash.get("PINK"); + } + } - public boolean canThreshold() - { - return false; - } + if (conservationColouring) + { + currentColour = applyConservation(currentColour, j); + } - public boolean isUserDefinable() - { - return false; + return currentColour; } - - } -class ConsensusColour { - +class ConsensusColour +{ Consensus[] conses; Color c; - public ConsensusColour(Color c,Consensus[] conses) { + public ConsensusColour(Color c, Consensus[] conses) + { this.conses = conses; + // this.list = list; this.c = c; } } - - - - - - - - - - - - - - -