merge from 2_4_Release branch
[jalview.git] / src / jalview / schemes / PIDColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.schemes;
20
21 import java.awt.*;
22
23 import jalview.analysis.*;
24 import jalview.datamodel.*;
25
26 public class PIDColourScheme extends ResidueColourScheme
27 {
28   public Color[] pidColours;
29
30   public float[] thresholds;
31
32   SequenceGroup group;
33
34   public PIDColourScheme()
35   {
36     this.pidColours = ResidueProperties.pidColours;
37     this.thresholds = ResidueProperties.pidThresholds;
38   }
39
40   public Color findColour(char c, int j)
41   {
42     if ('a' <= c && c <= 'z')
43     {
44       c -= ('a' - 'A');
45     }
46
47     if (consensus == null || j >= consensus.length || consensus[j] == null)
48     {
49       return Color.white;
50     }
51
52     if ((threshold != 0) && !aboveThreshold(c, j))
53     {
54       return Color.white;
55     }
56
57     Color currentColour = Color.white;
58
59     double sc = 0;
60
61     if (consensus.length <= j)
62     {
63       return Color.white;
64     }
65
66     if ((Integer
67             .parseInt(consensus[j].get(AAFrequency.MAXCOUNT).toString()) != -1)
68             && consensus[j].contains(String.valueOf(c)))
69     {
70       sc = ((Float) consensus[j].get(ignoreGaps)).floatValue();
71
72       if (!jalview.util.Comparison.isGap(c))
73       {
74         for (int i = 0; i < thresholds.length; i++)
75         {
76           if (sc > thresholds[i])
77           {
78             currentColour = pidColours[i];
79
80             break;
81           }
82         }
83       }
84     }
85
86     if (conservationColouring)
87     {
88       currentColour = applyConservation(currentColour, j);
89     }
90
91     return currentColour;
92   }
93 }