JAL-2360 structure viewers now using ColourMenuHelper, obsolete methods
[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.AnnotatedCollectionI;
24 import jalview.datamodel.ProfileI;
25 import jalview.datamodel.SequenceCollectionI;
26 import jalview.datamodel.SequenceGroup;
27 import jalview.datamodel.SequenceI;
28 import jalview.util.Comparison;
29
30 import java.awt.Color;
31 import java.util.Map;
32
33 public class PIDColourScheme extends ResidueColourScheme
34 {
35   public Color[] pidColours;
36
37   public float[] thresholds;
38
39   SequenceGroup group;
40
41   public PIDColourScheme()
42   {
43     this.pidColours = ResidueProperties.pidColours;
44     this.thresholds = ResidueProperties.pidThresholds;
45   }
46
47   @Override
48   public Color findColour(char c, int j, SequenceI seq)
49   {
50     if ('a' <= c && c <= 'z')
51     {
52       c -= ('a' - 'A');
53     }
54
55     if (consensus == null || consensus.get(j) == null)
56     {
57       return Color.white;
58     }
59
60     if ((threshold != 0) && !aboveThreshold(c, j))
61     {
62       return Color.white;
63     }
64
65     Color currentColour = Color.white;
66
67     double sc = 0;
68
69
70     /*
71      * test whether this is the consensus (or joint consensus) residue
72      */
73     ProfileI profile = consensus.get(j);
74     boolean matchesConsensus = profile.getModalResidue().contains(
75             String.valueOf(c));
76     if (matchesConsensus)
77     {
78       sc = profile.getPercentageIdentity(ignoreGaps);
79
80       if (!Comparison.isGap(c))
81       {
82         for (int i = 0; i < thresholds.length; i++)
83         {
84           if (sc > thresholds[i])
85           {
86             currentColour = pidColours[i];
87             break;
88           }
89         }
90       }
91     }
92
93     if (conservationColouring)
94     {
95       currentColour = applyConservation(currentColour, j);
96     }
97
98     return currentColour;
99   }
100
101   @Override
102   public String getSchemeName()
103   {
104     return JalviewColourScheme.PID.toString();
105   }
106
107   /**
108    * Returns a new instance of this colour scheme with which the given data may
109    * be coloured
110    */
111   @Override
112   public ColourSchemeI getInstance(AnnotatedCollectionI coll,
113           Map<SequenceI, SequenceCollectionI> hrs)
114   {
115     return new PIDColourScheme();
116   }
117
118   @Override
119   public boolean isSimple()
120   {
121     return false;
122   }
123 }