49d5dee5bc47f737306e5c7acde653b11cca01e0
[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
25 import java.awt.Color;
26 import java.util.Hashtable;
27
28 /**
29  * Became RNAHelicesColour.java. Placeholder for true covariation color scheme
30  * 
31  * @author Lauren Michelle Lui
32  * @version 2.5
33  */
34 public class CovariationColourScheme extends ResidueColourScheme
35 {
36   public Hashtable helixcolorhash = new Hashtable();
37
38   public Hashtable positionsToHelix = new Hashtable();
39
40   int numHelix = 0;
41
42   public AlignmentAnnotation annotation;
43
44   /**
45    * Creates a new CovariationColourScheme object.
46    */
47   public CovariationColourScheme(AlignmentAnnotation annotation)
48   {
49     this.annotation = annotation;
50
51     for (int x = 0; x < this.annotation._rnasecstr.length; x++)
52     {
53       // System.out.println(this.annotation._rnasecstr[x] + " Begin" +
54       // this.annotation._rnasecstr[x].getBegin());
55       // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
56       // pairs.put(this.annotation._rnasecstr[x].getBegin(),
57       // this.annotation._rnasecstr[x].getEnd());
58
59       positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
60               this.annotation._rnasecstr[x].getFeatureGroup());
61       positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
62               this.annotation._rnasecstr[x].getFeatureGroup());
63
64       if (Integer.parseInt(this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix)
65       {
66         numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
67                 .getFeatureGroup());
68       }
69
70     }
71
72     for (int j = 0; j <= numHelix; j++)
73     {
74       helixcolorhash.put(Integer.toString(j),
75               jalview.util.ColorUtils.generateRandomColor(Color.white));
76     }
77
78   }
79
80   /**
81    * DOCUMENT ME!
82    * 
83    * @param n
84    *          DOCUMENT ME!
85    * 
86    * @return DOCUMENT ME!
87    */
88   public Color findColour(char c)
89   {
90     // System.out.println("called"); log.debug
91     // Generate a random pastel color
92
93     return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];// jalview.util.ColorUtils.generateRandomColor(Color.white);
94   }
95
96   /**
97    * DOCUMENT ME!
98    * 
99    * @param n
100    *          DOCUMENT ME!
101    * @param j
102    *          DOCUMENT ME!
103    * 
104    * @return DOCUMENT ME!
105    */
106   public Color findColour(char c, int j)
107   {
108     Color currentColour = Color.white;
109     String currentHelix = null;
110     // System.out.println(c + " " + j);
111     currentHelix = (String) positionsToHelix.get(j);
112     // System.out.println(positionsToHelix.get(j));
113
114     if (currentHelix != null)
115     {
116       currentColour = (Color) helixcolorhash.get(currentHelix);
117     }
118
119     // System.out.println(c + " " + j + " helix " + currentHelix + " " +
120     // currentColour);
121     return currentColour;
122   }
123
124 }