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;
24 import java.util.Hashtable;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AnnotatedCollectionI;
29 import jalview.datamodel.SequenceCollectionI;
30 import jalview.datamodel.SequenceI;
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 public void alignmentChanged(AnnotatedCollectionI alignment,
79 Map<SequenceI, SequenceCollectionI> hiddenReps)
82 // This loop will find the first rna structure annotation by which to colour
84 AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
85 for (int i = 0; i < annotations.length; i++)
88 // is this a sensible way of determining type of annotation?
89 if (annotations[i].getRNAStruc() != null)
91 annotation = annotations[i];
100 private long lastrefresh = -1;
102 public void refresh()
105 if (annotation != null
106 && ((annotation._rnasecstr == null || lastrefresh != annotation._rnasecstr
107 .hashCode()) && annotation.isValidStruc()))
109 annotation.getRNAStruc();
110 lastrefresh = annotation._rnasecstr.hashCode();
112 positionsToHelix = new Hashtable();
114 // Figure out number of helices
115 // Length of rnasecstr is the number of pairs of positions that base pair
116 // with each other in the secondary structure
117 for (int x = 0; x < this.annotation._rnasecstr.length; x++)
121 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
122 * this.annotation._rnasecstr[x].getBegin());
124 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
126 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
127 this.annotation._rnasecstr[x].getFeatureGroup());
128 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
129 this.annotation._rnasecstr[x].getFeatureGroup());
131 if (Integer.parseInt(this.annotation._rnasecstr[x]
132 .getFeatureGroup()) > numHelix)
134 numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
140 // Generate random colors and store
141 for (int j = 0; j <= numHelix; j++)
143 if (!helixcolorhash.containsKey(Integer.toString(j)))
145 helixcolorhash.put(Integer.toString(j),
146 jalview.util.ColorUtils.generateRandomColor(Color.white));
153 * Returns default color base on purinepyrimidineIndex in
154 * jalview.schemes.ResidueProperties (Allows coloring in sequence logo)
157 * Character in sequence
159 * @return color in RGB
162 public Color findColour(char c)
164 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
165 // random colors for all positions
166 // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
170 * Returns color based on helices
173 * Character in sequence
177 * @return Color in RGB
180 public Color findColour(char c, int j, SequenceI seq)
183 Color currentColour = Color.white;
184 String currentHelix = null;
185 currentHelix = (String) positionsToHelix.get(j);
187 if (currentHelix != null)
189 currentColour = (Color) helixcolorhash.get(currentHelix);
192 // System.out.println(c + " " + j + " helix " + currentHelix + " " +
194 return currentColour;