Jalview Imported Sources
[jalview.git] / src / jalview / gui / ColourKey.java
1 package jalview.gui;\r
2 \r
3 import jalview.jbgui.GColourKey;\r
4 import jalview.schemes.*;\r
5 import javax.swing.*;\r
6 import java.awt.*;\r
7 import java.awt.event.*;\r
8 \r
9 \r
10 public class ColourKey extends GColourKey\r
11 {\r
12 \r
13  Color midBlue = new Color(100,100,255);\r
14  public ColourKey(ColourSchemeI current)\r
15  {\r
16    if(current==null)\r
17         zappoMenuItem_actionPerformed(null);\r
18 \r
19    else if(current instanceof Blosum62ColourScheme)\r
20         blosumMenuItem_actionPerformed(null);\r
21 \r
22   else if(current instanceof BuriedColourScheme)\r
23     buriedMenuItem_actionPerformed(null);\r
24 \r
25 //  else if(current instanceof ClustalxColourScheme)\r
26  //   cl\r
27   else if(current instanceof HelixColourScheme)\r
28     helixMenuItem_actionPerformed(null);\r
29 \r
30   else if(current instanceof HydrophobicColourScheme)\r
31     hydroMenuItem_actionPerformed(null);\r
32 \r
33   else if(current instanceof StrandColourScheme)\r
34     strandMenuItem_actionPerformed(null);\r
35 \r
36   else if(current instanceof TaylorColourScheme)\r
37     taylorMenuItem_actionPerformed(null);\r
38 \r
39   else if(current instanceof TurnColourScheme)\r
40     turnMenuItem_actionPerformed(null);\r
41 \r
42   else // default\r
43      zappoMenuItem_actionPerformed(null);\r
44  }\r
45 \r
46  void displayKey(String [] residue, String [] description, Color []  colour, String comment)\r
47  {\r
48    this.getContentPane().removeAll();\r
49 \r
50    for(int i=0; i<colour.length; i++)\r
51    {\r
52      JPanel rowPanel = new JPanel();\r
53      JLabel residueLabel = new JLabel();\r
54      JLabel textLabel = new JLabel();\r
55      JPanel colourPanel = new JPanel();\r
56      rowPanel.setLayout(new BorderLayout());\r
57      residueLabel.setFont(new java.awt.Font("Verdana", Font.BOLD, 12));\r
58      residueLabel.setPreferredSize(new Dimension(80, 20));\r
59      if(residue!=null)\r
60        residueLabel.setText(residue[i]);\r
61      residueLabel.setOpaque(false);\r
62      residueLabel.setHorizontalAlignment(SwingConstants.CENTER);\r
63      residueLabel.setHorizontalTextPosition(SwingConstants.CENTER);\r
64      textLabel.setFont(new java.awt.Font("Verdana", 0, 12));\r
65      textLabel.setPreferredSize(new Dimension(250,20));\r
66      textLabel.setBackground(Color.white);\r
67      if(description != null)\r
68         textLabel.setText(description[i]);\r
69 \r
70      colourPanel.setBackground(colour[i]);\r
71      colourPanel.setBorder(BorderFactory.createRaisedBevelBorder());\r
72      colourPanel.setPreferredSize(new Dimension(80, 20));\r
73      colourPanel.setLayout(new BorderLayout());\r
74      colourPanel.add(residueLabel, BorderLayout.CENTER);\r
75 \r
76      rowPanel.add(colourPanel, BorderLayout.CENTER);\r
77      if(description!=null)\r
78        rowPanel.add(textLabel, BorderLayout.WEST);\r
79      this.getContentPane().add(rowPanel);\r
80    }\r
81 \r
82    if(comment!=null)\r
83    {\r
84      JTextArea ta = new JTextArea(comment);\r
85      ta.setLineWrap(true);\r
86      ta.setWrapStyleWord(true);\r
87      ta.setPreferredSize( new Dimension(this.getWidth()-20, 120) );\r
88      this.getContentPane().add(ta);\r
89    }\r
90    validate();\r
91    repaint();\r
92  }\r
93 \r
94 \r
95 protected void clustalMenuItem_actionPerformed(ActionEvent e)\r
96 {\r
97   menu.setText("ClustalX colour scheme");\r
98   this.getContentPane().removeAll();\r
99   repaint();\r
100 }\r
101 \r
102 protected void zappoMenuItem_actionPerformed(ActionEvent e)\r
103 {\r
104     menu.setText("Zappo colour scheme");\r
105     displayKey(\r
106         new String[]{"ILVAM", "FWY", "KRH", "DE", "STNQ", "PG", "C"},\r
107         new String[]{"Aliphatic/hydrophobic residues", "Aromatic",\r
108         "Positive", "Negative", "Hydrophilic", "conformationally special", "Cysteine"},\r
109         new Color[]{ Color.pink, Color.orange, midBlue, Color.red, Color.green, Color.magenta, Color.yellow}\r
110         ,null\r
111         );\r
112 \r
113 }\r
114 \r
115 protected void taylorMenuItem_actionPerformed(ActionEvent e)\r
116 {\r
117   menu.setText("Taylor colour scheme");\r
118   String [] res = new String[]{"A","V","I","L","M","F","Y","W","H","R","K","N","Q","E","D","S","T","G","P","C"};\r
119   Color [] col = new Color[20];\r
120   for (int i=0; i<20; i++)\r
121     col[i] = ResidueProperties.taylor[ ((Integer)ResidueProperties.aaHash.get(res[i])).intValue() ];\r
122 \r
123 \r
124   displayKey( res, null, col, "These colours were invented by Willie Taylor and an entertaining description of their birth can be found in Protein Engineering, Vol 10 , 743-746 (1997)"\r
125  );\r
126 }\r
127 \r
128 protected void hydroMenuItem_actionPerformed(ActionEvent e)\r
129 {\r
130 \r
131   menu.setText("Hydrophobicity colour scheme");\r
132   String [] res = new String[]{"I","V","L","F","C","M","A","G","X","T","S","W","Y","P","H","E","Z","Q","D","B","N","K","R"};\r
133   Color [] col = new Color[20];\r
134   HydrophobicColourScheme cs = new HydrophobicColourScheme();\r
135   for (int i=0; i<20; i++)\r
136     col[i] = cs.findColour(null,  res[i], -1,  null);\r
137 \r
138   displayKey( res, null, col, "According to the hydrophobicity table of  Kyte, J., and Doolittle, R.F., J. Mol. Biol. 1157, 105-132, 1982.  The most hydrophobic residues according to this table are coloured red and the most hydrophilic ones are coloured blue.");\r
139 \r
140 }\r
141 \r
142 protected void helixMenuItem_actionPerformed(ActionEvent e)\r
143 {\r
144   menu.setText("Helix propensity colour scheme");\r
145   String[] res = new String[]\r
146       {"E","M","A","Z","L","K","F","Q","I","W","V","D","X","H","R","B","T","S","C","Y","N","G","P"};\r
147   Color[] col = new Color[res.length];\r
148   HelixColourScheme cs = new HelixColourScheme();\r
149   for (int i = 0; i < res.length; i++)\r
150     col[i] = cs.findColour(null, res[i], -1, null);\r
151 \r
152   displayKey(res, null, col, null);\r
153 }\r
154 \r
155 protected void strandMenuItem_actionPerformed(ActionEvent e)\r
156 {\r
157   menu.setText("Strand propensity colour scheme");\r
158   String[] res = new String[]\r
159     {"V","I","Y","F","W","L","T","C","Q","M","X","R","N","H","A","S","G","Z","K","B","P","D","E"};\r
160 Color[] col = new Color[res.length];\r
161 StrandColourScheme cs = new StrandColourScheme();\r
162 for (int i = 0; i < res.length; i++)\r
163   col[i] = cs.findColour(null, res[i], -1, null);\r
164   displayKey(res, null, col, null);\r
165 }\r
166 \r
167 protected void turnMenuItem_actionPerformed(ActionEvent e)\r
168 {\r
169   menu.setText("Turn propensity colour scheme");\r
170   String[] res = new String[]\r
171     {"N","G","P","B","D","S","C","Y","K","X","Q","W","T","R","H","Z","E","A","F","M","L","V","I"};\r
172 Color[] col = new Color[res.length];\r
173 TurnColourScheme cs = new TurnColourScheme();\r
174 for (int i = 0; i < res.length; i++)\r
175   col[i] = cs.findColour(null, res[i], -1, null);\r
176 \r
177   displayKey(res, null, col, null);\r
178 }\r
179 \r
180 protected void buriedMenuItem_actionPerformed(ActionEvent e)\r
181 {\r
182   menu.setText("Buried Index colour scheme");\r
183   String[] res = new String[]\r
184     {"C","I","V","L","F","M","G","A","W","X","S","H","T","P","Y","N","B","D","Q","Z","E","R","K"};\r
185 Color[] col = new Color[res.length];\r
186 BuriedColourScheme cs = new BuriedColourScheme();\r
187 for (int i = 0; i < res.length; i++)\r
188   col[i] = cs.findColour(null, res[i], -1, null);\r
189 \r
190   displayKey(res, null, col, null);\r
191 }\r
192 \r
193 protected void blosumMenuItem_actionPerformed(ActionEvent e)\r
194 {\r
195   menu.setText("BLOSUM62 colour scheme");\r
196   displayKey( null,\r
197               new String[]{"Consensus","+ve Blosum62", " "},\r
198               new Color[]{ new Color(154, 154, 255), new Color(204, 204, 255),  Color.white },\r
199               "Gaps are coloured white. If a residue matchs the consensus sequence residue at that position"\r
200              +" it is colored dark blue. If it does not match the consensus residue but the 2 residues have a positive Blosum62 score, it is colored light blue.");\r
201 \r
202 }\r
203 }\r
204 \r
205 \r
206 /*\r
207 Blosum62 - Sequence positions which are gaps are colored white. For sequence positions which are non-gaps,\r
208 if a residue matchs the consensus sequence residue at that position, it is colored dark blue.\r
209 If it does not match the consensus residue but the 2 residues have a positive Blosum62 score, it is colored light blue.\r
210 Otherwise, it is colored white.\r
211 Percentage Identity - Sequence positions which are gaps are colored white. For sequence positions which are non-gaps,\r
212 if the residue at a given position is conserved in less than 40% of the sequences in the alignment, it is colored white.\r
213 For residues conserved in greater than 40% of the sequences in the alignment, a shade of blue is assigned depending on\r
214 the level of conservation, with darker blues corresponding to residues that are more conserver.\r
215 */\r
216 \r
217    /*\r
218    This depends on the applet having performed a consensus calculation on the alignment.  This is done automatically when the applet first starts up but is not done for subsequent alignment windows.  If the consensus seuqence is calculated again by selecting 'Consensus' from the Calculate menu then the consensus is calculated for the selected sequences only  and all the alignment sequences are coloured according to that consensus.  This can be useful to display how similar all the other sequences in the alignment are compared to one (or a few) selected sequences.\r
219 The PID option colours the residues (boxes and/or text) according to the percentage of the residues in each column that agree with the consensus sequence.  Only the residues that agree with the consensus residue for each column are coloured.\r
220 \r
221   Percentage agreement Colour\r
222 > 80 % Mid blue\r
223 > 60 % Light blue\r
224 > 40 % Light grey\r
225 <= 40% White\r
226 */\r
227 \r
228 \r
229 \r
230 \r
231 \r
232 \r
233 \r
234 \r
235 \r
236 \r
237 \r
238 \r
239 \r
240 \r