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