2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.schemes;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.AnnotatedCollectionI;
25 import jalview.datamodel.SequenceCollectionI;
26 import jalview.datamodel.SequenceI;
28 import java.awt.Color;
29 import java.util.Hashtable;
33 * Looks at the information computed from an RNA Stockholm format file on the
34 * secondary structure of the alignment. Extracts the information on the
35 * positions of the helices present and assigns colors.
37 * @author Lauren Michelle Lui
40 public class RNAHelicesColour extends ResidueColourScheme
44 * Stores random colors generated for the number of helices
46 public Hashtable helixcolorhash = new Hashtable();
49 * Maps sequence positions to the RNA helix they belong to. Key: position,
52 public Hashtable positionsToHelix = new Hashtable();
55 * Number of helices in the RNA secondary structure
59 public AlignmentAnnotation annotation;
62 * Creates a new RNAHelicesColour object.
64 public RNAHelicesColour(AlignmentAnnotation annotation)
66 super(ResidueProperties.nucleotideIndex);
67 this.annotation = annotation;
71 public RNAHelicesColour(AnnotatedCollectionI alignment)
73 super(ResidueProperties.nucleotideIndex);
74 alignmentChanged(alignment, null);
78 * clones colour settings and annotation row data
80 * @param rnaHelicesColour
82 public RNAHelicesColour(RNAHelicesColour rnaHelicesColour)
84 super(ResidueProperties.nucleotideIndex);
85 helixcolorhash = rnaHelicesColour.helixcolorhash;
86 annotation = rnaHelicesColour.annotation;
91 public void alignmentChanged(AnnotatedCollectionI alignment,
92 Map<SequenceI, SequenceCollectionI> hiddenReps)
95 // This loop will find the first rna structure annotation by which to colour
97 AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
98 for (int i = 0; i < annotations.length; i++)
101 // is this a sensible way of determining type of annotation?
102 if (annotations[i].visible && annotations[i].isRNA()
103 && annotations[i].isValidStruc())
105 annotation = annotations[i];
114 private long lastrefresh = -1;
116 public void refresh()
119 if (annotation != null
120 && ((annotation._rnasecstr == null || lastrefresh != annotation._rnasecstr
121 .hashCode()) && annotation.isValidStruc()))
123 annotation.getRNAStruc();
124 lastrefresh = annotation._rnasecstr.hashCode();
126 positionsToHelix = new Hashtable();
128 // Figure out number of helices
129 // Length of rnasecstr is the number of pairs of positions that base pair
130 // with each other in the secondary structure
131 for (int x = 0; x < this.annotation._rnasecstr.length; x++)
135 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
136 * this.annotation._rnasecstr[x].getBegin());
138 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
140 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
141 this.annotation._rnasecstr[x].getFeatureGroup());
142 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
143 this.annotation._rnasecstr[x].getFeatureGroup());
145 if (Integer.parseInt(this.annotation._rnasecstr[x]
146 .getFeatureGroup()) > numHelix)
148 numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
154 // Generate random colors and store
155 for (int j = 0; j <= numHelix; j++)
157 if (!helixcolorhash.containsKey(Integer.toString(j)))
159 helixcolorhash.put(Integer.toString(j),
160 jalview.util.ColorUtils.generateRandomColor(Color.white));
167 * Returns default color base on purinepyrimidineIndex in
168 * jalview.schemes.ResidueProperties (Allows coloring in sequence logo)
171 * Character in sequence
173 * @return color in RGB
176 public Color findColour(char c)
178 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
179 // random colors for all positions
180 // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
184 * Returns color based on helices
187 * Character in sequence
191 * @return Color in RGB
194 public Color findColour(char c, int j, SequenceI seq)
197 Color currentColour = Color.white;
198 String currentHelix = null;
199 currentHelix = (String) positionsToHelix.get(j);
201 if (currentHelix != null)
203 currentColour = (Color) helixcolorhash.get(currentHelix);
206 // System.out.println(c + " " + j + " helix " + currentHelix + " " +
208 return currentColour;
212 public ColourSchemeI applyTo(AnnotatedCollectionI sg,
213 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
215 return new RNAHelicesColour(this);