JAL-1066 - T-Coffee color scheme + signature change on findColour method
[jalview.git] / src / jalview / schemes / TCoffeeColourScheme.java
1 package jalview.schemes;
2
3 import jalview.io.TCoffeeScoreFile;
4
5 import java.awt.Color;
6
7 /**
8  * Defines the color score for T-Coffee MSA 
9  * <p>
10  * See http://tcoffee.org
11  * 
12  * 
13  * @author Paolo Di Tommaso
14  *
15  */
16 public class TCoffeeColourScheme extends ResidueColourScheme {
17
18         static final Color[] colors = {
19                 new Color( 102, 102, 255 ),     // #6666FF
20                 new Color( 0, 255, 0),          // #00FF00
21                 new Color( 102, 255, 0),        // #66FF00
22                 new Color( 204, 255, 0),        // #CCFF00
23                 new Color( 255, 255, 0),        // #FFFF00
24                 new Color( 255, 204, 0),        // #FFCC00
25                 new Color( 255, 153, 0),        // #FF9900
26                 new Color( 255, 102, 0),        // #FF6600
27                 new Color( 255, 51, 0),         // #FF3300
28                 new Color( 255, 34, 0)          // #FF2000
29         };
30
31
32         byte[][] scoreMatrix = null;
33
34         /**
35          * Initialize the color sheme based on the content of the T-Coffee score file 
36          * 
37          * @param scoreFile
38          */
39         public TCoffeeColourScheme(TCoffeeScoreFile scoreFile) {
40
41                 scoreMatrix = scoreFile != null ? scoreFile.getScoresArray() : null;
42
43         }
44
45         @Override
46         public Color findColour(char c, int j, int sequenceIndex) {
47
48                 if( scoreMatrix == null ) {
49                         return Color.white;
50                 }
51                 
52                 if( sequenceIndex<0  || sequenceIndex >= scoreMatrix.length ) {
53                         System.out.printf("Sequence index out of range for the T-Coffee color scheme. Index:  %s\n", sequenceIndex);
54                         return Color.white;
55                 }
56
57                 byte[] seqScores = scoreMatrix[sequenceIndex]; 
58                 if( j < 0 || j>= seqScores.length ) {
59                         System.out.printf("Residue index out of range for the T-Coffee color scheme. Sequence %s - residue: %s\n", sequenceIndex, j);
60                         return Color.white;
61                 }
62                 
63                 byte val = seqScores[j];
64                 return val >= 0 && val < colors.length ? colors[val] : Color.white;
65         }
66 }