X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FClustalxColourScheme.java;h=6eb2ac1ef3b98862193381831be86d3c1a7dd0d0;hb=ab43013b7e357b84b4abade0dba949668dfb2a0e;hp=bc2f9ead956ec33d61ec4098ec2d35f98500ba1b;hpb=067a6494124d4f1d0fe8b6d758b593145393b7dd;p=jalview.git diff --git a/src/jalview/schemes/ClustalxColourScheme.java b/src/jalview/schemes/ClustalxColourScheme.java index bc2f9ea..6eb2ac1 100755 --- a/src/jalview/schemes/ClustalxColourScheme.java +++ b/src/jalview/schemes/ClustalxColourScheme.java @@ -1,62 +1,82 @@ /* - * 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 + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1) + * Copyright (C) 2014 The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview 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 3 * 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 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 + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.schemes; -import java.util.*; +import jalview.datamodel.AnnotatedCollectionI; +import jalview.datamodel.SequenceCollectionI; +import jalview.datamodel.SequenceI; -import java.awt.*; +import java.awt.Color; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Vector; -import jalview.datamodel.*; - -public class ClustalxColourScheme - extends ResidueColourScheme // implements IParameterizable +public class ClustalxColourScheme extends ResidueColourScheme // implements +// IParameterizable { public static Hashtable colhash = new Hashtable(); + Hashtable[] cons; + int[][] cons2; + ConsensusColour[] colours; + ConsensusColour[] ResidueColour; + int size; + Consensus[] conses = new Consensus[32]; + Vector colourTable = new Vector(); - private boolean includeGaps=true; - + + private boolean includeGaps = true; + { - 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)); + 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) + public ClustalxColourScheme(AnnotatedCollectionI alignment, + Map hiddenReps) { - resetClustalX(seqs, maxWidth); + alignmentChanged(alignment, hiddenReps); } - public void resetClustalX(Vector seqs, int maxWidth) + public void alignmentChanged(AnnotatedCollectionI alignment, + Map hiddenReps) { + int maxWidth = alignment.getWidth(); + List seqs = alignment.getSequences(hiddenReps); cons2 = new int[maxWidth][24]; - includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to get the current setting of the includeGaps param. + includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to + // get the current setting of the + // includeGaps param. int start = 0; // Initialize the array @@ -73,15 +93,15 @@ public class ClustalxColourScheme int j = 0; char[] seq; - while (j < seqs.size()) + for (SequenceI sq : seqs) { - seq = ( (SequenceI) seqs.elementAt(j)).getSequence(); + seq = sq.getSequence(); int end_j = seq.length - 1; for (i = start; i <= end_j; i++) { - if ( (seq.length - 1) < i) + if ((seq.length - 1) < i) { res = 23; } @@ -95,7 +115,7 @@ public class ClustalxColourScheme j++; } - + this.size = seqs.size(); makeColours(); } @@ -140,82 +160,83 @@ public class ClustalxColourScheme 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]; //% - tmp1[1] = conses[1]; //# - tmp1[2] = conses[26]; //A - tmp1[3] = conses[27]; //C - tmp1[4] = conses[11]; //F - tmp1[5] = conses[13]; //H - tmp1[6] = conses[14]; //I - tmp1[7] = conses[15]; //L - tmp1[8] = conses[16]; //M - tmp1[9] = conses[23]; //V - tmp1[10] = conses[24]; //W - 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[10] = new ConsensusColour( (Color) colhash.get("CYAN"), tmp1); + tmp1[0] = conses[0]; // % + tmp1[1] = conses[1]; // # + tmp1[2] = conses[26]; // A + tmp1[3] = conses[27]; // C + tmp1[4] = conses[11]; // F + tmp1[5] = conses[13]; // H + tmp1[6] = conses[14]; // I + tmp1[7] = conses[15]; // L + tmp1[8] = conses[16]; // M + tmp1[9] = conses[23]; // V + tmp1[10] = conses[24]; // W + 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[10] = new ConsensusColour((Color) colhash.get("CYAN"), tmp1); Consensus[] tmp2 = new Consensus[5]; - 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[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); 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[0] = conses[17]; // N + tmp3[1] = conses[29]; // D + 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[1] = conses[19]; //Q - tmp4[2] = conses[22]; //E - tmp4[3] = conses[3]; //+ - tmp4[4] = conses[28]; //K - tmp4[5] = conses[20]; //R - colours[3] = new ConsensusColour( (Color) colhash.get("GREEN"), tmp4); + tmp4[1] = conses[19]; // Q + tmp4[2] = conses[22]; // E + tmp4[3] = conses[3]; // + + tmp4[4] = conses[28]; // K + tmp4[5] = conses[20]; // R + colours[3] = new ConsensusColour((Color) colhash.get("GREEN"), tmp4); Consensus[] tmp5 = new Consensus[4]; - 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); - - Consensus[] tmp6 = new Consensus[5]; - tmp6[0] = conses[3]; //- - tmp6[1] = conses[29]; //D - tmp6[2] = conses[10]; //E - tmp6[3] = conses[6]; //q - tmp6[4] = conses[19]; //Q - colours[5] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp6); + 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); + + Consensus[] tmp6 = new Consensus[6]; + tmp6[0] = conses[3]; // - + tmp6[1] = conses[29]; // D + tmp6[2] = conses[10]; // E + tmp6[3] = conses[6]; // QE + tmp6[4] = conses[19]; // Q + tmp6[5] = conses[2]; // DE + colours[5] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp6); Consensus[] tmp7 = new Consensus[5]; - tmp7[0] = conses[3]; //- - tmp7[1] = conses[29]; //D - tmp7[2] = conses[10]; //E - tmp7[3] = conses[17]; //N - tmp7[4] = conses[2]; //DE - colours[6] = new ConsensusColour( (Color) colhash.get("MAGENTA"), tmp7); + tmp7[0] = conses[3]; // - + tmp7[1] = conses[29]; // D + tmp7[2] = conses[10]; // E + tmp7[3] = conses[17]; // N + tmp7[4] = conses[2]; // DE + colours[6] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp7); // Now attach the ConsensusColours to the residue letters ResidueColour = new ConsensusColour[20]; @@ -241,16 +262,19 @@ public class ClustalxColourScheme ResidueColour[19] = colours[0]; // V } + @Override public Color findColour(char c) { return Color.pink; } - public Color findColour(char c, int j) + @Override + public Color findColour(char c, int j, SequenceI seq) { Color currentColour; - if (cons2.length <= j || (includeGaps && threshold != 0 && !aboveThreshold(c, j))) + if (cons2.length <= j + || (includeGaps && threshold != 0 && !aboveThreshold(c, j))) { return Color.white; } @@ -266,7 +290,8 @@ public class ClustalxColourScheme for (int k = 0; k < ResidueColour[i].conses.length; k++) { - if (ResidueColour[i].conses[k].isConserved(cons2, j, size, includeGaps)) + if (ResidueColour[i].conses[k].isConserved(cons2, j, size, + includeGaps)) { currentColour = ResidueColour[i].c; } @@ -297,24 +322,36 @@ public class ClustalxColourScheme } /** - * @param includeGaps the includeGaps to set + * @param includeGaps + * the includeGaps to set */ protected void setIncludeGaps(boolean includeGaps) { this.includeGaps = includeGaps; } + + @Override + public ColourSchemeI applyTo(AnnotatedCollectionI sg, + Map hiddenRepSequences) + { + ClustalxColourScheme css = new ClustalxColourScheme(sg, + hiddenRepSequences); + css.includeGaps = includeGaps; + return css; + } } class ConsensusColour { Consensus[] conses; + Color c; public ConsensusColour(Color c, Consensus[] conses) { this.conses = conses; - // this.list = list; + // this.list = list; this.c = c; } }