JAL-1503 update version in GPL header
[jalview.git] / src / jalview / schemes / PIDColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3  * Copyright (C) 2014 The Jalview Authors
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  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.schemes;
20
21 import jalview.analysis.AAFrequency;
22 import jalview.datamodel.SequenceGroup;
23 import jalview.datamodel.SequenceI;
24
25 import java.awt.Color;
26
27 public class PIDColourScheme extends ResidueColourScheme
28 {
29   public Color[] pidColours;
30
31   public float[] thresholds;
32
33   SequenceGroup group;
34
35   public PIDColourScheme()
36   {
37     this.pidColours = ResidueProperties.pidColours;
38     this.thresholds = ResidueProperties.pidThresholds;
39   }
40
41   @Override
42   public Color findColour(char c, int j, SequenceI seq)
43   {
44     if ('a' <= c && c <= 'z')
45     {
46       c -= ('a' - 'A');
47     }
48
49     if (consensus == null || j >= consensus.length || consensus[j] == null)
50     {
51       return Color.white;
52     }
53
54     if ((threshold != 0) && !aboveThreshold(c, j))
55     {
56       return Color.white;
57     }
58
59     Color currentColour = Color.white;
60
61     double sc = 0;
62
63     if (consensus.length <= j)
64     {
65       return Color.white;
66     }
67
68     if ((Integer
69             .parseInt(consensus[j].get(AAFrequency.MAXCOUNT).toString()) != -1)
70             && consensus[j].contains(String.valueOf(c)))
71     {
72       sc = ((Float) consensus[j].get(ignoreGaps)).floatValue();
73
74       if (!jalview.util.Comparison.isGap(c))
75       {
76         for (int i = 0; i < thresholds.length; i++)
77         {
78           if (sc > thresholds[i])
79           {
80             currentColour = pidColours[i];
81
82             break;
83           }
84         }
85       }
86     }
87
88     if (conservationColouring)
89     {
90       currentColour = applyConservation(currentColour, j);
91     }
92
93     return currentColour;
94   }
95 }