JAL-98 use Profile to store consensus, ResidueCount for fast compact
[jalview.git] / src / jalview / schemes / PIDColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ 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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.schemes;
22
23 import jalview.datamodel.SequenceGroup;
24 import jalview.datamodel.SequenceI;
25
26 import java.awt.Color;
27
28 public class PIDColourScheme extends ResidueColourScheme
29 {
30   public Color[] pidColours;
31
32   public float[] thresholds;
33
34   SequenceGroup group;
35
36   public PIDColourScheme()
37   {
38     this.pidColours = ResidueProperties.pidColours;
39     this.thresholds = ResidueProperties.pidThresholds;
40   }
41
42   @Override
43   public Color findColour(char c, int j, SequenceI seq)
44   {
45     if ('a' <= c && c <= 'z')
46     {
47       c -= ('a' - 'A');
48     }
49
50     if (consensus == null || j >= consensus.length || consensus[j] == null)
51     {
52       return Color.white;
53     }
54
55     if ((threshold != 0) && !aboveThreshold(c, j))
56     {
57       return Color.white;
58     }
59
60     Color currentColour = Color.white;
61
62     double sc = 0;
63
64     if (consensus.length <= j)
65     {
66       return Color.white;
67     }
68
69     if (consensus[j].getMaxCount() > 0) //!= -1)
70             //&& consensus[j].contains(String.valueOf(c)))
71     {
72       sc = consensus[j].getPercentageIdentity(ignoreGaps);
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 }