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