fe533ed690184a8d2105b9dd86ff99a0a8a9c9be
[jalview.git] / src / jalview / schemes / CovariationColourScheme.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.schemes;
19
20 import java.awt.*;
21 import java.util.Hashtable;
22
23 import jalview.datamodel.AlignmentAnnotation;
24
25 /**
26  * Became RNAHelicesColour.java. Placeholder for true covariation color scheme
27  * 
28  * @author Lauren Michelle Lui
29  * @version 2.5
30  */
31 public class CovariationColourScheme extends ResidueColourScheme
32 {
33   public Hashtable helixcolorhash = new Hashtable();
34
35   public Hashtable positionsToHelix = new Hashtable();
36
37   int numHelix = 0;
38
39   public AlignmentAnnotation annotation;
40
41   /**
42    * Creates a new CovariationColourScheme object.
43    */
44   public CovariationColourScheme(AlignmentAnnotation annotation)
45   {
46     this.annotation = annotation;
47
48     for (int x = 0; x < this.annotation._rnasecstr.length; x++)
49     {
50       // System.out.println(this.annotation._rnasecstr[x] + " Begin" +
51       // this.annotation._rnasecstr[x].getBegin());
52       // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
53       // pairs.put(this.annotation._rnasecstr[x].getBegin(),
54       // this.annotation._rnasecstr[x].getEnd());
55
56       positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
57               this.annotation._rnasecstr[x].getFeatureGroup());
58       positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
59               this.annotation._rnasecstr[x].getFeatureGroup());
60
61       if (Integer.parseInt(this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix)
62       {
63         numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
64                 .getFeatureGroup());
65       }
66
67     }
68
69     for (int j = 0; j <= numHelix; j++)
70     {
71       helixcolorhash.put(Integer.toString(j), jalview.util.ColorUtils
72               .generateRandomColor(Color.white));
73     }
74
75   }
76
77   /**
78    * DOCUMENT ME!
79    * 
80    * @param n
81    *          DOCUMENT ME!
82    * 
83    * @return DOCUMENT ME!
84    */
85   public Color findColour(char c)
86   {
87     // System.out.println("called"); log.debug
88     // Generate a random pastel color
89
90     return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];// jalview.util.ColorUtils.generateRandomColor(Color.white);
91   }
92
93   /**
94    * DOCUMENT ME!
95    * 
96    * @param n
97    *          DOCUMENT ME!
98    * @param j
99    *          DOCUMENT ME!
100    * 
101    * @return DOCUMENT ME!
102    */
103   public Color findColour(char c, int j)
104   {
105     Color currentColour = Color.white;
106     String currentHelix = null;
107     // System.out.println(c + " " + j);
108     currentHelix = (String) positionsToHelix.get(j);
109     // System.out.println(positionsToHelix.get(j));
110
111     if (currentHelix != null)
112     {
113       currentColour = (Color) helixcolorhash.get(currentHelix);
114     }
115
116     // System.out.println(c + " " + j + " helix " + currentHelix + " " +
117     // currentColour);
118     return currentColour;
119   }
120
121 }