JAL-2360 ColourSchemes holds configured schemes, AlignFrame colour menu
[jalview.git] / src / jalview / schemes / CovariationColourScheme.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.AlignmentAnnotation;
24 import jalview.datamodel.AnnotatedCollectionI;
25 import jalview.datamodel.SequenceCollectionI;
26 import jalview.datamodel.SequenceI;
27
28 import java.awt.Color;
29 import java.util.Hashtable;
30 import java.util.Map;
31
32 /**
33  * Became RNAHelicesColour.java. Placeholder for true covariation color scheme
34  * 
35  * @author Lauren Michelle Lui
36  * @version 2.5
37  */
38 public class CovariationColourScheme extends ResidueColourScheme
39 {
40   public Hashtable helixcolorhash = new Hashtable();
41
42   public Hashtable positionsToHelix = new Hashtable();
43
44   int numHelix = 0;
45
46   public AlignmentAnnotation annotation;
47
48   /**
49    * Returns a new instance of this colour scheme with which the given data may
50    * be coloured
51    */
52   @Override
53   public ColourSchemeI getInstance(AnnotatedCollectionI coll,
54           Map<SequenceI, SequenceCollectionI> hrs)
55   {
56     return new CovariationColourScheme(coll.getAlignmentAnnotation()[0]);
57   }
58
59   /**
60    * Creates a new CovariationColourScheme object.
61    */
62   public CovariationColourScheme(AlignmentAnnotation annotation)
63   {
64     this.annotation = annotation;
65
66     for (int x = 0; x < this.annotation._rnasecstr.length; x++)
67     {
68       // System.out.println(this.annotation._rnasecstr[x] + " Begin" +
69       // this.annotation._rnasecstr[x].getBegin());
70       // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
71       // pairs.put(this.annotation._rnasecstr[x].getBegin(),
72       // this.annotation._rnasecstr[x].getEnd());
73
74       positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
75               this.annotation._rnasecstr[x].getFeatureGroup());
76       positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
77               this.annotation._rnasecstr[x].getFeatureGroup());
78
79       if (Integer.parseInt(this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix)
80       {
81         numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
82                 .getFeatureGroup());
83       }
84
85     }
86
87     for (int j = 0; j <= numHelix; j++)
88     {
89       helixcolorhash.put(Integer.toString(j),
90               jalview.util.ColorUtils.generateRandomColor(Color.white));
91     }
92
93   }
94
95   /**
96    * DOCUMENT ME!
97    * 
98    * @param n
99    *          DOCUMENT ME!
100    * 
101    * @return DOCUMENT ME!
102    */
103   @Override
104   public Color findColour(char c)
105   {
106     // System.out.println("called"); log.debug
107     // Generate a random pastel color
108
109     return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];// jalview.util.ColorUtils.generateRandomColor(Color.white);
110   }
111
112   /**
113    * DOCUMENT ME!
114    * 
115    * @param n
116    *          DOCUMENT ME!
117    * @param j
118    *          DOCUMENT ME!
119    * 
120    * @return DOCUMENT ME!
121    */
122   public Color findColour(char c, int j)
123   {
124     Color currentColour = Color.white;
125     String currentHelix = null;
126     // System.out.println(c + " " + j);
127     currentHelix = (String) positionsToHelix.get(j);
128     // System.out.println(positionsToHelix.get(j));
129
130     if (currentHelix != null)
131     {
132       currentColour = (Color) helixcolorhash.get(currentHelix);
133     }
134
135     // System.out.println(c + " " + j + " helix " + currentHelix + " " +
136     // currentColour);
137     return currentColour;
138   }
139
140   @Override
141   public boolean isNucleotideSpecific()
142   {
143     return true;
144   }
145
146   @Override
147   public String getSchemeName()
148   {
149     return "Covariation";
150   }
151 }