JAL-1620 version bump and release notes
[jalview.git] / src / jalview / schemes / Blosum62ColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
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
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.analysis.AAFrequency;
24
25 import java.awt.Color;
26 import java.util.Map;
27
28 import jalview.datamodel.AnnotatedCollectionI;
29 import jalview.datamodel.SequenceCollectionI;
30 import jalview.datamodel.SequenceI;
31
32 public class Blosum62ColourScheme extends ResidueColourScheme
33 {
34   public Blosum62ColourScheme()
35   {
36     super();
37   }
38
39   @Override
40   public Color findColour(char res, int j, SequenceI seq)
41   {
42     if ('a' <= res && res <= 'z')
43     {
44       // TO UPPERCASE !!!
45       res -= ('a' - 'A');
46     }
47
48     if (consensus == null || j >= consensus.length || consensus[j] == null
49             || (threshold != 0 && !aboveThreshold(res, j)))
50     {
51       return Color.white;
52     }
53
54     Color currentColour;
55
56     if (!jalview.util.Comparison.isGap(res))
57     {
58       String max = (String) consensus[j].get(AAFrequency.MAXRESIDUE);
59
60       if (max.indexOf(res) > -1)
61       {
62         currentColour = new Color(154, 154, 255);
63       }
64       else
65       {
66         int c = 0;
67         int max_aa = 0;
68         int n = max.length();
69
70         do
71         {
72           c += ResidueProperties.getBLOSUM62(max.charAt(max_aa), res);
73         } while (++max_aa < n);
74
75         if (c > 0)
76         {
77           currentColour = new Color(204, 204, 255);
78         }
79         else
80         {
81           currentColour = Color.white;
82         }
83       }
84
85       if (conservationColouring)
86       {
87         currentColour = applyConservation(currentColour, j);
88       }
89     }
90     else
91     {
92       return Color.white;
93     }
94
95     return currentColour;
96   }
97
98   @Override
99   public ColourSchemeI applyTo(AnnotatedCollectionI sg,
100           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
101   {
102     ColourSchemeI newcs = super.applyTo(sg, hiddenRepSequences);
103     return newcs;
104   }
105 }