2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.schemes;
21 import java.util.Hashtable;
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.datamodel.SequenceI;
27 * Looks at the information computed from an RNA Stockholm format file on the
28 * secondary structure of the alignment. Extracts the information on the
29 * positions of the helices present and assigns colors.
31 * @author Lauren Michelle Lui
34 public class RNAHelicesColour extends ResidueColourScheme
38 * Stores random colors generated for the number of helices
40 public Hashtable helixcolorhash = new Hashtable();
43 * Maps sequence positions to the RNA helix they belong to. Key: position,
46 public Hashtable positionsToHelix = new Hashtable();
49 * Number of helices in the RNA secondary structure
53 public AlignmentAnnotation annotation;
56 * Creates a new RNAHelicesColour object.
58 public RNAHelicesColour(AlignmentAnnotation annotation)
60 super(ResidueProperties.nucleotideIndex);
61 this.annotation = annotation;
65 private long lastrefresh = -1;
69 if (lastrefresh != annotation._rnasecstr.hashCode()
70 && annotation.isValidStruc())
72 annotation.getRNAStruc();
73 lastrefresh = annotation._rnasecstr.hashCode();
75 positionsToHelix = new Hashtable();
77 // Figure out number of helices
78 // Length of rnasecstr is the number of pairs of positions that base pair
79 // with each other in the secondary structure
80 for (int x = 0; x < this.annotation._rnasecstr.length; x++)
84 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
85 * this.annotation._rnasecstr[x].getBegin());
87 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
89 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
90 this.annotation._rnasecstr[x].getFeatureGroup());
91 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
92 this.annotation._rnasecstr[x].getFeatureGroup());
94 if (Integer.parseInt(this.annotation._rnasecstr[x]
95 .getFeatureGroup()) > numHelix)
97 numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
103 // Generate random colors and store
104 for (int j = 0; j <= numHelix; j++)
106 if (!helixcolorhash.containsKey(Integer.toString(j)))
108 helixcolorhash.put(Integer.toString(j),
109 jalview.util.ColorUtils.generateRandomColor(Color.white));
116 * Returns default color base on purinepyrimidineIndex in
117 * jalview.schemes.ResidueProperties (Allows coloring in sequence logo)
120 * Character in sequence
122 * @return color in RGB
125 public Color findColour(char c)
127 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
128 // random colors for all positions
129 // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
133 * Returns color based on helices
136 * Character in sequence
140 * @return Color in RGB
143 public Color findColour(char c, int j, SequenceI seq)
146 Color currentColour = Color.white;
147 String currentHelix = null;
148 currentHelix = (String) positionsToHelix.get(j);
150 if (currentHelix != null)
152 currentColour = (Color) helixcolorhash.get(currentHelix);
155 // System.out.println(c + " " + j + " helix " + currentHelix + " " +
157 return currentColour;