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.api.AlignViewportI;
24 import jalview.bin.Instance;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.AnnotatedCollectionI;
28 import jalview.datamodel.SequenceCollectionI;
29 import jalview.datamodel.SequenceI;
31 import java.awt.Color;
32 import java.util.Hashtable;
36 * Looks at the information computed from an RNA Stockholm format file on the
37 * secondary structure of the alignment. Extracts the information on the
38 * positions of the helices present and assigns colors.
40 * @author Lauren Michelle Lui
43 public class RNAHelicesColour extends ResidueColourScheme
47 * Maps sequence positions to the RNA helix they belong to. Key: position,
48 * Value: helix TODO: Revise or drop in favour of annotation position numbers
50 public Hashtable<Integer, String> positionsToHelix = new Hashtable<>();
53 * Number of helices in the RNA secondary structure
57 public AlignmentAnnotation annotation;
60 * Default constructor (required for ColourSchemes cache)
62 public RNAHelicesColour()
68 * Creates a new RNAHelicesColour object.
70 public RNAHelicesColour(AlignmentAnnotation annotation)
72 super(ResidueProperties.nucleotideIndex);
73 this.annotation = annotation;
74 ColourSchemeProperty.resetRnaHelicesShading();
78 public RNAHelicesColour(AnnotatedCollectionI alignment)
80 super(ResidueProperties.nucleotideIndex);
81 ColourSchemeProperty.resetRnaHelicesShading();
82 alignmentChanged(alignment, null);
86 * clones colour settings and annotation row data
88 * @param rnaHelicesColour
90 public RNAHelicesColour(RNAHelicesColour rnaHelicesColour)
92 super(ResidueProperties.nucleotideIndex);
93 annotation = rnaHelicesColour.annotation;
98 public void alignmentChanged(AnnotatedCollectionI alignment,
99 Map<SequenceI, SequenceCollectionI> hiddenReps)
102 // This loop will find the first rna structure annotation by which to colour
104 AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
105 if (annotations == null)
109 for (int i = 0; i < annotations.length; i++)
112 // is this a sensible way of determining type of annotation?
113 if (annotations[i].visible && annotations[i].isRNA()
114 && annotations[i].isValidStruc())
116 annotation = annotations[i];
125 private long lastrefresh = -1;
127 public void refresh()
130 if (annotation != null && ((annotation._rnasecstr == null
131 || lastrefresh != annotation._rnasecstr.hashCode())
132 && annotation.isValidStruc()))
134 annotation.getRNAStruc();
135 lastrefresh = annotation._rnasecstr.hashCode();
137 positionsToHelix = new Hashtable<>();
139 // Figure out number of helices
140 // Length of rnasecstr is the number of pairs of positions that base pair
141 // with each other in the secondary structure
142 for (int x = 0; x < this.annotation._rnasecstr.length; x++)
146 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
147 * this.annotation._rnasecstr[x].getBegin());
149 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
151 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
152 this.annotation._rnasecstr[x].getFeatureGroup());
153 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
154 this.annotation._rnasecstr[x].getFeatureGroup());
156 if (Integer.parseInt(
157 this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix)
159 numHelix = Integer.parseInt(
160 this.annotation._rnasecstr[x].getFeatureGroup());
164 ColourSchemeProperty.initRnaHelicesShading(numHelix);
169 * Returns default color base on purinepyrimidineIndex in
170 * jalview.schemes.ResidueProperties (Allows coloring in sequence logo)
173 * Character in sequence
175 * @return color in RGB
178 public Color findColour(char c)
180 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
181 // random colors for all positions
182 // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
186 * Returns color based on helices
189 * Character in sequence
191 * position in sequence - used to locate helix
193 * @return Color in RGB
196 public Color findColour(char c, int j, SequenceI seq)
199 Color currentColour = Color.white;
200 String currentHelix = null;
201 currentHelix = positionsToHelix.get(j);
202 if (currentHelix != null)
204 currentColour = Instance.getInstance().rnaHelices[Integer
205 .parseInt(currentHelix)];
207 return currentColour;
211 public ColourSchemeI getInstance(AlignViewportI view,
212 AnnotatedCollectionI sg)
214 return new RNAHelicesColour(sg);
218 public boolean isNucleotideSpecific()
224 * Answers true if the data has RNA secondary structure annotation
227 public boolean isApplicableTo(AnnotatedCollectionI ac)
229 if (ac instanceof AlignmentI && ((AlignmentI) ac).hasRNAStructure())
235 * not currently supporting this option for group annotation / colouring
241 public String getSchemeName()
243 return JalviewColourScheme.RNAHelices.toString();
247 public boolean isSimple()