X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FClustalxColourScheme.java;h=9c0b9534ffed69e3a339ab9dc1bb39ffd9b9b7b9;hb=7d6bf4ac01167499c0f4e07de63edcdd72a6d595;hp=e726cb9442fdc7b54ca88803fec88f5aae17b7b4;hpb=a8f483d04205bb8273ee311c12968b7e86d205fa;p=jalview.git
diff --git a/src/jalview/schemes/ClustalxColourScheme.java b/src/jalview/schemes/ClustalxColourScheme.java
index e726cb9..9c0b953 100755
--- a/src/jalview/schemes/ClustalxColourScheme.java
+++ b/src/jalview/schemes/ClustalxColourScheme.java
@@ -1,19 +1,21 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ 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.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* 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 Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.schemes;
@@ -23,41 +25,64 @@ import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
import java.awt.Color;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import java.util.Vector;
-public class ClustalxColourScheme extends ResidueColourScheme // implements
-// IParameterizable
+public class ClustalxColourScheme extends ResidueColourScheme
{
- public static Hashtable colhash = new Hashtable();
+ private static final int EIGHTY_FIVE = 85;
- Hashtable[] cons;
+ private static final int FIFTY = 50;
- int[][] cons2;
+ private static final int EIGHTY = 80;
- ConsensusColour[] colours;
+ private static final int SIXTY = 60;
- ConsensusColour[] ResidueColour;
+ enum ClustalColour
+ {
+ RED(0.9f, 0.2f, 0.1f), BLUE(0.5f, 0.7f, 0.9f), GREEN(0.1f, 0.8f, 0.1f),
+ ORANGE(0.9f, 0.6f, 0.3f), CYAN(0.1f, 0.7f, 0.7f),
+ PINK(0.9f, 0.5f, 0.5f), MAGENTA(0.8f, 0.3f, 0.8f), YELLOW(0.8f, 0.8f,
+ 0.0f);
+
+ final Color colour;
+
+ ClustalColour(float r, float g, float b)
+ {
+ colour = new Color(r, g, b);
+ }
+ }
+ private class ConsensusColour
+ {
+ Consensus[] cons;
- int size;
+ Color c;
- Consensus[] conses = new Consensus[32];
+ public ConsensusColour(ClustalColour col, Consensus[] conses)
+ {
+ this.cons = conses;
+ this.c = col.colour;
+ }
+ }
- Vector colourTable = new Vector();
+ private int[][] cons2;
+
+ private ConsensusColour[] colours;
+
+ private ConsensusColour[] residueColour;
+
+ private int size;
+
+ private Consensus[] conses = new Consensus[32];
private boolean includeGaps = true;
+ /**
+ * Default constructor (required for Class.newInstance())
+ */
+ public ClustalxColourScheme()
{
- 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(AnnotatedCollectionI alignment,
@@ -66,6 +91,7 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
alignmentChanged(alignment, hiddenReps);
}
+ @Override
public void alignmentChanged(AnnotatedCollectionI alignment,
Map hiddenReps)
{
@@ -75,29 +101,15 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
includeGaps = isIncludeGaps(); // does nothing - TODO replace with call to
// get the current setting of the
// includeGaps param.
- int start = 0;
-
- // Initialize the array
- for (int j = 0; j < 24; j++)
- {
- for (int i = 0; i < maxWidth; i++)
- {
- cons2[i][j] = 0;
- }
- }
-
- int res;
- int i;
- int j = 0;
- char[] seq;
+ int res = 0;
for (SequenceI sq : seqs)
{
- seq = sq.getSequence();
+ char[] seq = sq.getSequence();
int end_j = seq.length - 1;
- for (i = start; i <= end_j; i++)
+ for (int i = 0; i <= end_j; i++)
{
if ((seq.length - 1) < i)
{
@@ -107,49 +119,46 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
{
res = ResidueProperties.aaIndex[seq[i]];
}
-
cons2[i][res]++;
}
-
- j++;
}
this.size = seqs.size();
makeColours();
}
- public void makeColours()
+ 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[0] = new Consensus("WLVIMAFCYHP", SIXTY);
+ conses[1] = new Consensus("WLVIMAFCYHP", EIGHTY);
+ conses[2] = new Consensus("ED", FIFTY);
+ conses[3] = new Consensus("KR", SIXTY);
+ conses[4] = new Consensus("G", FIFTY);
+ conses[5] = new Consensus("N", FIFTY);
+ conses[6] = new Consensus("QE", FIFTY);
+ conses[7] = new Consensus("P", FIFTY);
+ conses[8] = new Consensus("TS", FIFTY);
+
+ conses[26] = new Consensus("A", EIGHTY_FIVE);
+ conses[27] = new Consensus("C", EIGHTY_FIVE);
+ conses[10] = new Consensus("E", EIGHTY_FIVE);
+ conses[11] = new Consensus("F", EIGHTY_FIVE);
+ conses[12] = new Consensus("G", EIGHTY_FIVE);
+ conses[13] = new Consensus("H", EIGHTY_FIVE);
+ conses[14] = new Consensus("I", EIGHTY_FIVE);
+ conses[15] = new Consensus("L", EIGHTY_FIVE);
+ conses[16] = new Consensus("M", EIGHTY_FIVE);
+ conses[17] = new Consensus("N", EIGHTY_FIVE);
+ conses[18] = new Consensus("P", EIGHTY_FIVE);
+ conses[19] = new Consensus("Q", EIGHTY_FIVE);
+ conses[20] = new Consensus("R", EIGHTY_FIVE);
+ conses[21] = new Consensus("S", EIGHTY_FIVE);
+ conses[22] = new Consensus("T", EIGHTY_FIVE);
+ conses[23] = new Consensus("V", EIGHTY_FIVE);
+ conses[24] = new Consensus("W", EIGHTY_FIVE);
+ conses[25] = new Consensus("Y", EIGHTY_FIVE);
+ conses[28] = new Consensus("K", EIGHTY_FIVE);
+ conses[29] = new Consensus("D", EIGHTY_FIVE);
conses[30] = new Consensus("G", 0);
conses[31] = new Consensus("P", 0);
@@ -159,15 +168,15 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
Consensus[] tmp8 = new Consensus[1];
tmp8[0] = conses[30]; // G
- colours[7] = new ConsensusColour((Color) colhash.get("ORANGE"), tmp8);
+ colours[7] = new ConsensusColour(ClustalColour.ORANGE, tmp8);
Consensus[] tmp9 = new Consensus[1];
tmp9[0] = conses[31]; // P
- colours[8] = new ConsensusColour((Color) colhash.get("YELLOW"), tmp9);
+ colours[8] = new ConsensusColour(ClustalColour.YELLOW, tmp9);
Consensus[] tmp10 = new Consensus[1];
tmp10[0] = conses[27]; // C
- colours[9] = new ConsensusColour((Color) colhash.get("PINK"), tmp8);
+ colours[9] = new ConsensusColour(ClustalColour.PINK, tmp8);
Consensus[] tmp1 = new Consensus[14];
tmp1[0] = conses[0]; // %
@@ -184,9 +193,9 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
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(ClustalColour.BLUE, tmp1);
- colours[10] = new ConsensusColour((Color) colhash.get("CYAN"), tmp1);
+ colours[10] = new ConsensusColour(ClustalColour.CYAN, tmp1);
Consensus[] tmp2 = new Consensus[5];
tmp2[0] = conses[8]; // t
@@ -194,14 +203,14 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
tmp2[2] = conses[22]; // T
tmp2[3] = conses[0]; // %
tmp2[4] = conses[1]; // #
- colours[1] = new ConsensusColour((Color) colhash.get("GREEN"), tmp2);
+ colours[1] = new ConsensusColour(ClustalColour.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);
+ colours[2] = new ConsensusColour(ClustalColour.GREEN, tmp3);
Consensus[] tmp4 = new Consensus[6];
tmp4[0] = conses[6]; // q = QE
@@ -210,14 +219,14 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
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(ClustalColour.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);
+ colours[4] = new ConsensusColour(ClustalColour.RED, tmp5);
Consensus[] tmp6 = new Consensus[6];
tmp6[0] = conses[3]; // -
@@ -226,7 +235,7 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
tmp6[3] = conses[6]; // QE
tmp6[4] = conses[19]; // Q
tmp6[5] = conses[2]; // DE
- colours[5] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp6);
+ colours[5] = new ConsensusColour(ClustalColour.MAGENTA, tmp6);
Consensus[] tmp7 = new Consensus[5];
tmp7[0] = conses[3]; // -
@@ -234,30 +243,30 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
tmp7[2] = conses[10]; // E
tmp7[3] = conses[17]; // N
tmp7[4] = conses[2]; // DE
- colours[6] = new ConsensusColour((Color) colhash.get("MAGENTA"), tmp7);
+ colours[6] = new ConsensusColour(ClustalColour.MAGENTA, tmp7);
// Now attach the ConsensusColours to the residue letters
- ResidueColour = new ConsensusColour[20];
- ResidueColour[0] = colours[0]; // A
- ResidueColour[1] = colours[4]; // R
- ResidueColour[2] = colours[2]; // N
- ResidueColour[3] = colours[6]; // D
- ResidueColour[4] = colours[0]; // C
- ResidueColour[5] = colours[3]; // Q
- ResidueColour[6] = colours[5]; // E
- ResidueColour[7] = colours[7]; // G
- ResidueColour[8] = colours[10]; // H
- ResidueColour[9] = colours[0]; // I
- ResidueColour[10] = colours[0]; // L
- ResidueColour[11] = colours[4]; // K
- ResidueColour[12] = colours[0]; // M
- ResidueColour[13] = colours[0]; // F
- ResidueColour[14] = colours[8]; // P
- ResidueColour[15] = colours[1]; // S
- ResidueColour[16] = colours[1]; // T
- ResidueColour[17] = colours[0]; // W
- ResidueColour[18] = colours[10]; // Y
- ResidueColour[19] = colours[0]; // V
+ residueColour = new ConsensusColour[20];
+ residueColour[0] = colours[0]; // A
+ residueColour[1] = colours[4]; // R
+ residueColour[2] = colours[2]; // N
+ residueColour[3] = colours[6]; // D
+ residueColour[4] = colours[0]; // C
+ residueColour[5] = colours[3]; // Q
+ residueColour[6] = colours[5]; // E
+ residueColour[7] = colours[7]; // G
+ residueColour[8] = colours[10]; // H
+ residueColour[9] = colours[0]; // I
+ residueColour[10] = colours[0]; // L
+ residueColour[11] = colours[4]; // K
+ residueColour[12] = colours[0]; // M
+ residueColour[13] = colours[0]; // F
+ residueColour[14] = colours[8]; // P
+ residueColour[15] = colours[1]; // S
+ residueColour[16] = colours[1]; // T
+ residueColour[17] = colours[0]; // W
+ residueColour[18] = colours[10]; // Y
+ residueColour[19] = colours[0]; // V
}
@Override
@@ -286,20 +295,23 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
return currentColour;
}
- for (int k = 0; k < ResidueColour[i].conses.length; k++)
+ for (int k = 0; k < residueColour[i].cons.length; k++)
{
- if (ResidueColour[i].conses[k].isConserved(cons2, j, size,
+ if (residueColour[i].cons[k].isConserved(cons2, j, size,
includeGaps))
{
- currentColour = ResidueColour[i].c;
+ currentColour = residueColour[i].c;
}
}
if (i == 4)
{
+ /*
+ * override to colour C pink if 100% conserved
+ */
if (conses[27].isConserved(cons2, j, size, includeGaps))
{
- currentColour = (Color) colhash.get("PINK");
+ currentColour = ClustalColour.PINK.colour;
}
}
@@ -327,27 +339,32 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
{
this.includeGaps = includeGaps;
}
+
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
Map hiddenRepSequences)
{
- ClustalxColourScheme css= new ClustalxColourScheme(sg, hiddenRepSequences);
+ ClustalxColourScheme css = new ClustalxColourScheme(sg,
+ hiddenRepSequences);
css.includeGaps = includeGaps;
return css;
}
-}
-class ConsensusColour
-{
- Consensus[] conses;
-
- Color c;
+ @Override
+ public boolean isPeptideSpecific()
+ {
+ return true;
+ }
- public ConsensusColour(Color c, Consensus[] conses)
+ @Override
+ public String getSchemeName()
{
- this.conses = conses;
+ return JalviewColourScheme.Clustal.toString();
+ }
- // this.list = list;
- this.c = c;
+ @Override
+ public boolean isSimple()
+ {
+ return false;
}
}