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;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.AnnotatedCollectionI;
27 import jalview.datamodel.SequenceCollectionI;
28 import jalview.datamodel.SequenceI;
31 * Looks at the information computed from an RNA Stockholm format file on the
32 * secondary structure of the alignment. Extracts the information on the
33 * positions of the helices present and assigns colors.
35 * @author Lauren Michelle Lui
38 public class RNAHelicesColour extends ResidueColourScheme
42 * Stores random colors generated for the number of helices
44 public Hashtable helixcolorhash = new Hashtable();
47 * Maps sequence positions to the RNA helix they belong to. Key: position,
50 public Hashtable positionsToHelix = new Hashtable();
53 * Number of helices in the RNA secondary structure
57 public AlignmentAnnotation annotation;
60 * Creates a new RNAHelicesColour object.
62 public RNAHelicesColour(AlignmentAnnotation annotation)
64 super(ResidueProperties.nucleotideIndex);
65 this.annotation = annotation;
68 public RNAHelicesColour(AnnotatedCollectionI alignment)
70 super(ResidueProperties.nucleotideIndex);
71 alignmentChanged(alignment, null);
75 public void alignmentChanged(AnnotatedCollectionI alignment,
76 Map<SequenceI, SequenceCollectionI> hiddenReps)
79 // This loop will find the first rna structure annotation by which to colour
81 AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
82 for (int i = 0; i < annotations.length; i++) {
84 // is this a sensible way of determining type of annotation?
85 if (annotations[i].getRNAStruc() != null) {
86 annotation = annotations[i];
94 private long lastrefresh = -1;
99 if (annotation!=null && ((annotation._rnasecstr == null
100 || lastrefresh != annotation._rnasecstr.hashCode())
101 && annotation.isValidStruc()))
103 annotation.getRNAStruc();
104 lastrefresh = annotation._rnasecstr.hashCode();
106 positionsToHelix = new Hashtable();
108 // Figure out number of helices
109 // Length of rnasecstr is the number of pairs of positions that base pair
110 // with each other in the secondary structure
111 for (int x = 0; x < this.annotation._rnasecstr.length; x++)
115 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
116 * this.annotation._rnasecstr[x].getBegin());
118 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
120 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
121 this.annotation._rnasecstr[x].getFeatureGroup());
122 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
123 this.annotation._rnasecstr[x].getFeatureGroup());
125 if (Integer.parseInt(this.annotation._rnasecstr[x]
126 .getFeatureGroup()) > numHelix)
128 numHelix = Integer.parseInt(this.annotation._rnasecstr[x]
134 // Generate random colors and store
135 for (int j = 0; j <= numHelix; j++)
137 if (!helixcolorhash.containsKey(Integer.toString(j)))
139 helixcolorhash.put(Integer.toString(j),
140 jalview.util.ColorUtils.generateRandomColor(Color.white));
147 * Returns default color base on purinepyrimidineIndex in
148 * jalview.schemes.ResidueProperties (Allows coloring in sequence logo)
151 * Character in sequence
153 * @return color in RGB
156 public Color findColour(char c)
158 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
159 // random colors for all positions
160 // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
164 * Returns color based on helices
167 * Character in sequence
171 * @return Color in RGB
174 public Color findColour(char c, int j, SequenceI seq)
177 Color currentColour = Color.white;
178 String currentHelix = null;
179 currentHelix = (String) positionsToHelix.get(j);
181 if (currentHelix != null)
183 currentColour = (Color) helixcolorhash.get(currentHelix);
186 // System.out.println(c + " " + j + " helix " + currentHelix + " " +
188 return currentColour;