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