JAL-2360 structure viewers now using ColourMenuHelper, obsolete methods
[jalview.git] / src / jalview / schemes / Blosum62ColourScheme.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.SequenceCollectionI;
25 import jalview.datamodel.SequenceI;
26 import jalview.util.Comparison;
27
28 import java.awt.Color;
29 import java.util.Map;
30
31 public class Blosum62ColourScheme extends ResidueColourScheme
32 {
33   private static final Color LIGHT_BLUE = new Color(204, 204, 255);
34   private static final Color DARK_BLUE = new Color(154, 154, 255);
35
36   public Blosum62ColourScheme()
37   {
38     super();
39   }
40
41   /**
42    * Returns a new instance of this colour scheme with which the given data may
43    * be coloured
44    */
45   @Override
46   public ColourSchemeI getInstance(AnnotatedCollectionI coll,
47           Map<SequenceI, SequenceCollectionI> hrs)
48   {
49     return new Blosum62ColourScheme();
50   }
51
52   @Override
53   public Color findColour(char res, int j, SequenceI seq)
54   {
55     if ('a' <= res && res <= 'z')
56     {
57       // TO UPPERCASE !!!
58       res -= ('a' - 'A');
59     }
60
61     if (consensus == null || consensus.get(j) == null
62             || (threshold != 0 && !aboveThreshold(res, j)))
63     {
64       return Color.white;
65     }
66
67     Color currentColour;
68
69     if (!Comparison.isGap(res))
70     {
71       /*
72        * test if this is the consensus (or joint consensus) residue
73        */
74       String max = consensus.get(j).getModalResidue();
75
76       if (max.indexOf(res) > -1)
77       {
78         currentColour = DARK_BLUE;
79       }
80       else
81       {
82         int c = 0;
83         int max_aa = 0;
84         int n = max.length();
85
86         do
87         {
88           c += ResidueProperties.getBLOSUM62(max.charAt(max_aa), res);
89         } while (++max_aa < n);
90
91         if (c > 0)
92         {
93           currentColour = LIGHT_BLUE;
94         }
95         else
96         {
97           currentColour = Color.white;
98         }
99       }
100
101       if (conservationColouring)
102       {
103         currentColour = applyConservation(currentColour, j);
104       }
105     }
106     else
107     {
108       return Color.white;
109     }
110
111     return currentColour;
112   }
113
114   @Override
115   public boolean isPeptideSpecific()
116   {
117     return true;
118   }
119
120   @Override
121   public String getSchemeName()
122   {
123     return JalviewColourScheme.Blosum62.toString();
124   }
125
126   @Override
127   public boolean isSimple()
128   {
129     return false;
130   }
131 }