Merge branch 'develop' into features/JAL-2360colourSchemeApplicability
[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.analysis.Conservation;
24 import jalview.datamodel.AnnotatedCollectionI;
25 import jalview.datamodel.ProfilesI;
26 import jalview.datamodel.SequenceCollectionI;
27 import jalview.datamodel.SequenceI;
28
29 import java.awt.Color;
30 import java.util.Map;
31
32 public interface ColourSchemeI
33 {
34   /**
35    * Returns the colour for the given character. For use when the colour depends
36    * only on the symbol.
37    * 
38    * @param c
39    * @return
40    */
41   Color findColour(char c);
42
43   /**
44    * Returns the possibly context dependent colour for the given symbol at the
45    * aligned position in the given sequence. For example, the colour may depend
46    * on the symbol's relationship to the consensus residue for the column.
47    * 
48    * @param symbol
49    * @param position
50    * @param seq
51    * @return
52    */
53   Color findColour(char symbol, int position, SequenceI seq);
54
55   /**
56    * Assigns the given consensus profile for the colourscheme
57    */
58   void setConsensus(ProfilesI hconsensus);
59
60   /**
61    * Assigns the given conservation to the colourscheme
62    * 
63    * @param c
64    */
65   void setConservation(Conservation c);
66
67   /**
68    * Enable or disable conservation shading for this colourscheme
69    * 
70    * @param conservationApplied
71    */
72   void setConservationApplied(boolean conservationApplied);
73
74   /**
75    * Answers true if conservation shading is enabled for this colourscheme
76    * 
77    * @return
78    */
79   boolean conservationApplied();
80
81   /**
82    * Sets the scale factor for bleaching of colour in unconserved regions
83    * 
84    * @param i
85    */
86   void setConservationInc(int i);
87
88   /**
89    * Returns the scale factor for bleaching colour in unconserved regions
90    * 
91    * @return
92    */
93   int getConservationInc();
94
95   /**
96    * Returns the percentage identity threshold for applying colourscheme
97    * 
98    * @return
99    */
100   int getThreshold();
101
102   /**
103    * Sets the percentage identity threshold and type of %age identity
104    * calculation for shading
105    * 
106    * @param pct
107    *          0..100 percentage identity for applying this colourscheme
108    * @param ignoreGaps
109    *          when true, calculate PID without including gapped positions
110    */
111   void setThreshold(int pct, boolean ignoreGaps);
112
113   /**
114    * Recalculate dependent data using the given sequence collection, taking
115    * account of hidden rows
116    * 
117    * @param alignment
118    * @param hiddenReps
119    */
120   void alignmentChanged(AnnotatedCollectionI alignment,
121           Map<SequenceI, SequenceCollectionI> hiddenReps);
122
123   /**
124    * Creates and returns a new instance of the colourscheme configured to colour
125    * the given collection. Note that even simple colour schemes should return a
126    * new instance for each call to this method, as different instances may have
127    * differing shading by consensus or percentage identity applied.
128    * 
129    * @param sg
130    * @param hiddenRepSequences
131    * @return copy of current scheme with any inherited settings transferred
132    */
133   ColourSchemeI getInstance(AnnotatedCollectionI sg,
134           Map<SequenceI, SequenceCollectionI> hiddenRepSequences);
135
136   /**
137    * Answers true if the colour scheme is suitable for the given data, else
138    * false. For example, some colour schemes are specific to either peptide or
139    * nucleotide, or only apply if certain kinds of annotation are present.
140    * 
141    * @param ac
142    * @return
143    */
144   // TODO can make this method static in Java 8
145   boolean isApplicableTo(AnnotatedCollectionI ac);
146
147   /**
148    * Answers the 'official' name of the colour scheme (as used, for example, as
149    * a Jalview startup parameter)
150    * 
151    * @return
152    */
153   String getSchemeName();
154
155   /**
156    * Answers true if the colour scheme depends only on the sequence symbol, and
157    * not on other information such as alignment consensus or annotation. (Note
158    * that simple colour schemes may have a fading by percentage identity or
159    * conservation overlaid.) Simple colour schemes can be propagated to
160    * structure viewers.
161    * 
162    * @return
163    */
164   boolean isSimple();
165 }