cbd082da854aa466e5ddc2192528b4341e342a93
[jalview.git] / src / jalview / schemes / PIDColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.schemes;
19
20 import jalview.analysis.AAFrequency;
21 import jalview.datamodel.SequenceGroup;
22 import jalview.datamodel.SequenceI;
23
24 import java.awt.Color;
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   @Override
41   public Color findColour(char c, int j, SequenceI seq)
42   {
43     if ('a' <= c && c <= 'z')
44     {
45       c -= ('a' - 'A');
46     }
47
48     if (consensus == null || j >= consensus.length || consensus[j] == null)
49     {
50       return Color.white;
51     }
52
53     if ((threshold != 0) && !aboveThreshold(c, j))
54     {
55       return Color.white;
56     }
57
58     Color currentColour = Color.white;
59
60     double sc = 0;
61
62     if (consensus.length <= j)
63     {
64       return Color.white;
65     }
66
67     if ((Integer
68             .parseInt(consensus[j].get(AAFrequency.MAXCOUNT).toString()) != -1)
69             && consensus[j].contains(String.valueOf(c)))
70     {
71       sc = ((Float) consensus[j].get(ignoreGaps)).floatValue();
72
73       if (!jalview.util.Comparison.isGap(c))
74       {
75         for (int i = 0; i < thresholds.length; i++)
76         {
77           if (sc > thresholds[i])
78           {
79             currentColour = pidColours[i];
80
81             break;
82           }
83         }
84       }
85     }
86
87     if (conservationColouring)
88     {
89       currentColour = applyConservation(currentColour, j);
90     }
91
92     return currentColour;
93   }
94 }