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;
27 import jalview.util.ColorUtils;
29 import java.awt.Color;
30 import java.util.Hashtable;
34 * Looks at the information computed from an RNA Stockholm format file on the
35 * secondary structure of the alignment. Extracts the information on the
36 * positions of the helices present and assigns colors.
38 * @author Lauren Michelle Lui
41 public class RNAHelicesColour extends ResidueColourScheme
45 * Stores random colors generated for the number of helices
47 public Hashtable helixcolorhash = new Hashtable();
50 * Maps sequence positions to the RNA helix they belong to. Key: position,
53 public Hashtable positionsToHelix = new Hashtable();
56 * Number of helices in the RNA secondary structure
60 public AlignmentAnnotation annotation;
63 * Creates a new RNAHelicesColour object.
65 public RNAHelicesColour(AlignmentAnnotation annotation)
67 super(ResidueProperties.nucleotideIndex);
68 this.annotation = annotation;
72 public RNAHelicesColour(AnnotatedCollectionI alignment)
74 super(ResidueProperties.nucleotideIndex);
75 alignmentChanged(alignment, null);
79 public void alignmentChanged(AnnotatedCollectionI alignment,
80 Map<SequenceI, SequenceCollectionI> hiddenReps)
83 // This loop will find the first rna structure annotation by which to colour
85 AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
86 for (int i = 0; i < annotations.length; i++)
89 // is this a sensible way of determining type of annotation?
90 if (annotations[i].getRNAStruc() != null)
92 annotation = annotations[i];
101 private long lastrefresh = -1;
103 public void refresh()
106 if (annotation != null
107 && ((annotation._rnasecstr == null || lastrefresh != annotation._rnasecstr
108 .hashCode()) && annotation.isValidStruc()))
110 annotation.getRNAStruc();
111 lastrefresh = annotation._rnasecstr.hashCode();
113 positionsToHelix = new Hashtable();
115 // Figure out number of helices
116 // Length of rnasecstr is the number of pairs of positions that base pair
117 // with each other in the secondary structure
118 for (int x = 0; x < this.annotation._rnasecstr.length; x++)
122 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
123 * this.annotation._rnasecstr[x].getBegin());
125 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
127 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
128 this.annotation._rnasecstr[x].getFeatureGroup());
129 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
130 this.annotation._rnasecstr[x].getFeatureGroup());
132 if (Integer.parseInt(this.annotation._rnasecstr[x]
133 .getFeatureGroup()) > numHelix)
135 numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
141 // Generate random colors and store
142 for (int j = 0; j <= numHelix; j++)
144 if (!helixcolorhash.containsKey(Integer.toString(j)))
146 helixcolorhash.put(Integer.toString(j),
147 ColorUtils.generateRandomColor(Color.white));
154 * Returns default color base on purinepyrimidineIndex in
155 * ResidueProperties (Allows coloring in sequence logo)
158 * Character in sequence
160 * @return color in RGB
163 public Color findColour(char c)
165 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
166 // random colors for all positions
167 // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
171 * Returns color based on helices
174 * Character in sequence
178 * @return Color in RGB
181 public Color findColour(char c, int j, SequenceI seq)
184 Color currentColour = Color.white;
185 String currentHelix = null;
186 currentHelix = (String) positionsToHelix.get(j);
188 if (currentHelix != null)
190 currentColour = (Color) helixcolorhash.get(currentHelix);
193 // System.out.println(c + " " + j + " helix " + currentHelix + " " +
195 return currentColour;