2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.schemes;
22 import java.util.Hashtable;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.datamodel.SequenceI;
28 * Looks at the information computed from an RNA Stockholm format file on the
29 * secondary structure of the alignment. Extracts the information on the
30 * positions of the helices present and assigns colors.
32 * @author Lauren Michelle Lui
35 public class RNAHelicesColour extends ResidueColourScheme
39 * Stores random colors generated for the number of helices
41 public Hashtable helixcolorhash = new Hashtable();
44 * Maps sequence positions to the RNA helix they belong to. Key: position,
47 public Hashtable positionsToHelix = new Hashtable();
50 * Number of helices in the RNA secondary structure
54 public AlignmentAnnotation annotation;
57 * Creates a new RNAHelicesColour object.
59 public RNAHelicesColour(AlignmentAnnotation annotation)
61 super(ResidueProperties.nucleotideIndex);
62 this.annotation = annotation;
66 private long lastrefresh = -1;
70 if (lastrefresh != annotation._rnasecstr.hashCode()
71 && annotation.isValidStruc())
73 annotation.getRNAStruc();
74 lastrefresh = annotation._rnasecstr.hashCode();
76 positionsToHelix = new Hashtable();
78 // Figure out number of helices
79 // Length of rnasecstr is the number of pairs of positions that base pair
80 // with each other in the secondary structure
81 for (int x = 0; x < this.annotation._rnasecstr.length; x++)
85 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
86 * this.annotation._rnasecstr[x].getBegin());
88 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
90 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
91 this.annotation._rnasecstr[x].getFeatureGroup());
92 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
93 this.annotation._rnasecstr[x].getFeatureGroup());
95 if (Integer.parseInt(this.annotation._rnasecstr[x]
96 .getFeatureGroup()) > numHelix)
98 numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
104 // Generate random colors and store
105 for (int j = 0; j <= numHelix; j++)
107 if (!helixcolorhash.containsKey(Integer.toString(j)))
109 helixcolorhash.put(Integer.toString(j),
110 jalview.util.ColorUtils.generateRandomColor(Color.white));
117 * Returns default color base on purinepyrimidineIndex in
118 * jalview.schemes.ResidueProperties (Allows coloring in sequence logo)
121 * Character in sequence
123 * @return color in RGB
126 public Color findColour(char c)
128 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
129 // random colors for all positions
130 // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
134 * Returns color based on helices
137 * Character in sequence
141 * @return Color in RGB
144 public Color findColour(char c, int j, SequenceI seq)
147 Color currentColour = Color.white;
148 String currentHelix = null;
149 currentHelix = (String) positionsToHelix.get(j);
151 if (currentHelix != null)
153 currentColour = (Color) helixcolorhash.get(currentHelix);
156 // System.out.println(c + " " + j + " helix " + currentHelix + " " +
158 return currentColour;