Clover icon

Coverage Report

  1. Project Clover database Thu Jun 4 2026 14:16:38 BST
  2. Package jalview.schemes

File RNAHelicesColour.java

 

Coverage histogram

../../img/srcFileCovDistChart8.png
21% of files have more coverage

Code metrics

16
45
13
1
250
134
26
0.58
3.46
13
2

Classes

Class Line # Actions
RNAHelicesColour 43 45 26
0.797297379.7%
 

Contributing tests

This file is covered by 202 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.schemes;
22   
23    import jalview.api.AlignViewportI;
24    import jalview.datamodel.AlignmentAnnotation;
25    import jalview.datamodel.AlignmentI;
26    import jalview.datamodel.AnnotatedCollectionI;
27    import jalview.datamodel.SequenceCollectionI;
28    import jalview.datamodel.SequenceFeature;
29    import jalview.datamodel.SequenceI;
30   
31    import java.awt.Color;
32    import java.util.Hashtable;
33    import java.util.Map;
34   
35    /**
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.
39    *
40    * @author Lauren Michelle Lui
41    * @version 2.5
42    */
 
43    public class RNAHelicesColour extends ResidueColourScheme
44    {
45   
46    /**
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
49    */
50    public Hashtable<Integer, String> positionsToHelix = new Hashtable<>();
51   
52    /**
53    * Number of helices in the RNA secondary structure
54    */
55    int numHelix = 0;
56   
57    public AlignmentAnnotation annotation;
58   
59    /**
60    * Default constructor (required for ColourSchemes cache)
61    */
 
62  54 toggle public RNAHelicesColour()
63    {
64   
65    }
66   
67    /**
68    * Creates a new RNAHelicesColour object.
69    */
 
70  0 toggle public RNAHelicesColour(AlignmentAnnotation annotation)
71    {
72  0 super(ResidueProperties.nucleotideIndex);
73  0 this.annotation = annotation;
74  0 ColourSchemeProperty.resetRnaHelicesShading();
75  0 refresh();
76    }
77   
 
78  9 toggle public RNAHelicesColour(AnnotatedCollectionI alignment)
79    {
80  9 super(ResidueProperties.nucleotideIndex);
81  9 ColourSchemeProperty.resetRnaHelicesShading();
82  9 alignmentChanged(alignment, null);
83    }
84   
85    /**
86    * clones colour settings and annotation row data
87    *
88    * @param rnaHelicesColour
89    */
 
90  0 toggle public RNAHelicesColour(RNAHelicesColour rnaHelicesColour)
91    {
92  0 super(ResidueProperties.nucleotideIndex);
93  0 annotation = rnaHelicesColour.annotation;
94  0 refresh();
95    }
96   
 
97  13 toggle @Override
98    public void alignmentChanged(AnnotatedCollectionI alignment,
99    Map<SequenceI, SequenceCollectionI> hiddenReps)
100    {
101   
102    // This loop will find the first rna structure annotation by which to colour
103    // the sequences.
104  13 AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
105  13 if (annotations == null)
106    {
107  3 return;
108    }
109  17 for (int i = 0; i < annotations.length; i++)
110    {
111   
112    // is this a sensible way of determining type of annotation?
113  14 if (annotations[i].isForDisplay() && annotations[i].isRNA()
114    && annotations[i].isValidStruc())
115    {
116  7 annotation = annotations[i];
117  7 break;
118    }
119    }
120   
121  10 refresh();
122   
123    }
124   
125    private long lastrefresh = -1;
126   
 
127  8163 toggle public void refresh()
128    {
129   
130  8163 if (annotation != null && annotation.isValidStruc() && lastrefresh!=annotation.getRnaStructure().getStructureHashcode())
131    {
132  8153 annotation.getRNAStruc();
133  8153 lastrefresh = annotation.getRnaStructure().hashCode();
134  8153 numHelix = 0;
135  8153 positionsToHelix = new Hashtable<>();
136   
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  8153 SequenceFeature sf[]=annotation.getRnaSecondaryStructure();
141  154907 for (int x = 0; x < sf.length; x++)
142    {
143   
144    /*
145    * jalview.bin.Console.outPrintln(this.annotation._rnasecstr[x] + " Begin" +
146    * this.annotation._rnasecstr[x].getBegin());
147    */
148    // jalview.bin.Console.outPrintln(this.annotation._rnasecstr[x].getFeatureGroup());
149   
150  146754 positionsToHelix.put(sf[x].getBegin(),
151    sf[x].getFeatureGroup());
152  146754 positionsToHelix.put(sf[x].getEnd(),
153    sf[x].getFeatureGroup());
154   
155  146754 if (Integer.parseInt(
156    sf[x].getFeatureGroup()) > numHelix)
157    {
158  0 numHelix = Integer.parseInt(
159    sf[x].getFeatureGroup());
160    }
161   
162    }
163  8153 ColourSchemeProperty.initRnaHelicesShading(numHelix);
164    }
165    }
166   
167    /**
168    * Returns default color base on purinepyrimidineIndex in
169    * jalview.schemes.ResidueProperties (Allows coloring in sequence logo)
170    *
171    * @param c
172    * Character in sequence
173    *
174    * @return color in RGB
175    */
 
176  0 toggle @Override
177    public Color findColour(char c)
178    {
179  0 return ResidueProperties.purinepyrimidine[ResidueProperties.purinepyrimidineIndex[c]];
180    // random colors for all positions
181    // jalview.util.ColorUtils.generateRandomColor(Color.white); If you want
182    }
183   
184    /**
185    * Returns color based on helices
186    *
187    * @param c
188    * Character in sequence
189    * @param j
190    * position in sequence - used to locate helix
191    *
192    * @return Color in RGB
193    */
 
194  8153 toggle @Override
195    public Color findColour(char c, int j, SequenceI seq)
196    {
197  8153 refresh();
198  8153 Color currentColour = Color.white;
199  8153 String currentHelix = null;
200  8153 currentHelix = positionsToHelix.get(j);
201  8153 if (currentHelix != null)
202    {
203  3236 currentColour = ColourSchemeProperty.rnaHelices[Integer
204    .parseInt(currentHelix)];
205    }
206  8153 return currentColour;
207    }
208   
 
209  4 toggle @Override
210    public ColourSchemeI getInstance(AlignViewportI view,
211    AnnotatedCollectionI sg)
212    {
213  4 return new RNAHelicesColour(sg);
214    }
215   
 
216  0 toggle @Override
217    public boolean isNucleotideSpecific()
218    {
219  0 return true;
220    }
221   
222    /**
223    * Answers true if the data has RNA secondary structure annotation
224    */
 
225  508 toggle @Override
226    public boolean isApplicableTo(AnnotatedCollectionI ac)
227    {
228  508 if (ac instanceof AlignmentI && ((AlignmentI) ac).hasRNAStructure())
229    {
230  5 return true;
231    }
232   
233    /*
234    * not currently supporting this option for group annotation / colouring
235    */
236  503 return false;
237    }
238   
 
239  633 toggle @Override
240    public String getSchemeName()
241    {
242  633 return JalviewColourScheme.RNAHelices.toString();
243    }
244   
 
245  55 toggle @Override
246    public boolean isSimple()
247    {
248  55 return false;
249    }
250    }