JAL-3148 add findColour(char) to ColourSchemeI
[jalview.git] / src / jalview / schemes / ColourSchemeI.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
27 import java.awt.Color;
28 import java.util.Map;
29
30 public interface ColourSchemeI
31 {
32   /**
33    * Returns the possibly context dependent colour for the given symbol at the
34    * aligned position in the given sequence. For example, the colour may depend
35    * on the symbol's relationship to the consensus residue for the column.
36    * 
37    * @param symbol
38    * @param position
39    * @param seq
40    * @param consensusResidue
41    *          the modal symbol (e.g. K) or symbols (e.g. KF) for the column
42    * @param pid
43    *          the percentage identity of the column's consensus (if known)
44    * @return
45    */
46   Color findColour(char symbol, int position, SequenceI seq,
47           String consensusResidue, float pid);
48   
49   /**
50    * Answers the colour for the specified residue character (for 'simple' colour
51    * schemes where residue alone determines the colour)
52    * 
53    * @param res
54    * @return
55    */
56   default Color findColour(char res) 
57   {
58         return Color.WHITE;
59   }
60
61   /**
62    * Recalculate dependent data using the given sequence collection, taking
63    * account of hidden rows
64    * 
65    * @param alignment
66    * @param hiddenReps
67    */
68   void alignmentChanged(AnnotatedCollectionI alignment,
69           Map<SequenceI, SequenceCollectionI> hiddenReps);
70
71   /**
72    * Creates and returns a new instance of the colourscheme configured to colour
73    * the given collection. Note that even simple colour schemes should return a
74    * new instance for each call to this method, as different instances may have
75    * differing shading by consensus or percentage identity applied.
76    * 
77    * @param sg
78    * @param hiddenRepSequences
79    * @return copy of current scheme with any inherited settings transferred
80    */
81   ColourSchemeI getInstance(AnnotatedCollectionI sg,
82           Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
83
84   /**
85    * Answers true if the colour scheme is suitable for the given data, else
86    * false. For example, some colour schemes are specific to either peptide or
87    * nucleotide, or only apply if certain kinds of annotation are present.
88    * 
89    * @param ac
90    * @return
91    */
92   // TODO can make this method static in Java 8
93   boolean isApplicableTo(AnnotatedCollectionI ac);
94
95   /**
96    * Answers the 'official' name of the colour scheme (as used, for example, as
97    * a Jalview startup parameter)
98    * 
99    * @return
100    */
101   String getSchemeName();
102
103   /**
104    * Answers true if the colour scheme depends only on the sequence symbol, and
105    * not on other information such as alignment consensus or annotation. (Note
106    * that simple colour schemes may have a fading by percentage identity or
107    * conservation overlaid.) Simple colour schemes can be propagated to
108    * structure viewers.
109    * 
110    * @return
111    */
112   boolean isSimple();
113
114   /**
115    * Answers true if the colour scheme has a colour specified for gaps.
116    * 
117    * @return
118    */
119   boolean hasGapColour();
120 }