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.AlignmentI;
25 import jalview.datamodel.AnnotatedCollectionI;
26 import jalview.datamodel.SequenceCollectionI;
27 import jalview.datamodel.SequenceI;
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 * Maps sequence positions to the RNA helix they belong to. Key: position,
46 * Value: helix TODO: Revise or drop in favour of annotation position numbers
48 public Hashtable<Integer, String> positionsToHelix = new Hashtable<Integer, String>();
51 * Number of helices in the RNA secondary structure
55 public AlignmentAnnotation annotation;
58 * Default constructor (required for ColourSchemes cache)
60 public RNAHelicesColour()
66 * Creates a new RNAHelicesColour object.
68 public RNAHelicesColour(AlignmentAnnotation annotation)
70 super(ResidueProperties.nucleotideIndex);
71 this.annotation = annotation;
72 ColourSchemeProperty.resetRnaHelicesShading();
76 public RNAHelicesColour(AnnotatedCollectionI alignment)
78 super(ResidueProperties.nucleotideIndex);
79 ColourSchemeProperty.resetRnaHelicesShading();
80 alignmentChanged(alignment, null);
84 * clones colour settings and annotation row data
86 * @param rnaHelicesColour
88 public RNAHelicesColour(RNAHelicesColour rnaHelicesColour)
90 super(ResidueProperties.nucleotideIndex);
91 annotation = rnaHelicesColour.annotation;
96 public void alignmentChanged(AnnotatedCollectionI alignment,
97 Map<SequenceI, SequenceCollectionI> hiddenReps)
100 // This loop will find the first rna structure annotation by which to colour
102 AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
103 if (annotations == null)
107 for (int i = 0; i < annotations.length; i++)
110 // is this a sensible way of determining type of annotation?
111 if (annotations[i].visible && annotations[i].isRNA()
112 && annotations[i].isValidStruc())
114 annotation = annotations[i];
123 private long lastrefresh = -1;
125 public void refresh()
128 if (annotation != null && ((annotation._rnasecstr == null
129 || lastrefresh != annotation._rnasecstr.hashCode())
130 && annotation.isValidStruc()))
132 annotation.getRNAStruc();
133 lastrefresh = annotation._rnasecstr.hashCode();
135 positionsToHelix = new Hashtable<Integer, String>();
137 // Figure out number of helices
138 // Length of rnasecstr is the number of pairs of positions that base pair
139 // with each other in the secondary structure
140 for (int x = 0; x < this.annotation._rnasecstr.length; x++)
144 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
145 * this.annotation._rnasecstr[x].getBegin());
147 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
149 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
150 this.annotation._rnasecstr[x].getFeatureGroup());
151 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
152 this.annotation._rnasecstr[x].getFeatureGroup());
154 if (Integer.parseInt(
155 this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix)
157 numHelix = Integer.parseInt(
158 this.annotation._rnasecstr[x].getFeatureGroup());
162 ColourSchemeProperty.initRnaHelicesShading(numHelix);
167 * Returns default color base on purinepyrimidineIndex in
168 * jalview.schemes.ResidueProperties (Allows coloring in sequence logo)
171 * Character in sequence
173 * @return color in RGB
176 public Color findColour(char c)
178 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
179 // random colors for all positions
180 // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
184 * Returns color based on helices
187 * Character in sequence
189 * position in sequence - used to locate helix
191 * @return Color in RGB
194 public Color findColour(char c, int j, SequenceI seq)
197 Color currentColour = Color.white;
198 String currentHelix = null;
199 currentHelix = positionsToHelix.get(j);
200 if (currentHelix != null)
202 currentColour = ColourSchemeProperty.rnaHelices[Integer
203 .parseInt(currentHelix)];
205 return currentColour;
209 public ColourSchemeI getInstance(AnnotatedCollectionI sg,
210 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
212 return new RNAHelicesColour(sg);
216 public boolean isNucleotideSpecific()
222 * Answers true if the data has RNA secondary structure annotation
225 public boolean isApplicableTo(AnnotatedCollectionI ac)
227 if (ac instanceof AlignmentI && ((AlignmentI) ac).hasRNAStructure())
233 * not currently supporting this option for group annotation / colouring
239 public String getSchemeName()
241 return JalviewColourScheme.RNAHelices.toString();
245 public boolean isSimple()