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