Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.schemes

File RNAHelicesColour.java

 

Coverage histogram

../../img/srcFileCovDistChart7.png
29% of files have more coverage

Code metrics

16
44
13
1
250
134
27
0.61
3.38
13
2.08

Classes

Class Line # Actions
RNAHelicesColour 42 44 27
0.6575342465.8%
 

Contributing tests

This file is covered by 189 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.SequenceI;
29   
30    import java.awt.Color;
31    import java.util.Hashtable;
32    import java.util.Map;
33   
34    /**
35    * Looks at the information computed from an RNA Stockholm format file on the
36    * secondary structure of the alignment. Extracts the information on the
37    * positions of the helices present and assigns colors.
38    *
39    * @author Lauren Michelle Lui
40    * @version 2.5
41    */
 
42    public class RNAHelicesColour extends ResidueColourScheme
43    {
44   
45    /**
46    * Maps sequence positions to the RNA helix they belong to. Key: position,
47    * Value: helix TODO: Revise or drop in favour of annotation position numbers
48    */
49    public Hashtable<Integer, String> positionsToHelix = new Hashtable<>();
50   
51    /**
52    * Number of helices in the RNA secondary structure
53    */
54    int numHelix = 0;
55   
56    public AlignmentAnnotation annotation;
57   
58    /**
59    * Default constructor (required for ColourSchemes cache)
60    */
 
61  50 toggle public RNAHelicesColour()
62    {
63   
64    }
65   
66    /**
67    * Creates a new RNAHelicesColour object.
68    */
 
69  0 toggle public RNAHelicesColour(AlignmentAnnotation annotation)
70    {
71  0 super(ResidueProperties.nucleotideIndex);
72  0 this.annotation = annotation;
73  0 ColourSchemeProperty.resetRnaHelicesShading();
74  0 refresh();
75    }
76   
 
77  9 toggle public RNAHelicesColour(AnnotatedCollectionI alignment)
78    {
79  9 super(ResidueProperties.nucleotideIndex);
80  9 ColourSchemeProperty.resetRnaHelicesShading();
81  9 alignmentChanged(alignment, null);
82    }
83   
84    /**
85    * clones colour settings and annotation row data
86    *
87    * @param rnaHelicesColour
88    */
 
89  0 toggle public RNAHelicesColour(RNAHelicesColour rnaHelicesColour)
90    {
91  0 super(ResidueProperties.nucleotideIndex);
92  0 annotation = rnaHelicesColour.annotation;
93  0 refresh();
94    }
95   
 
96  13 toggle @Override
97    public void alignmentChanged(AnnotatedCollectionI alignment,
98    Map<SequenceI, SequenceCollectionI> hiddenReps)
99    {
100   
101    // This loop will find the first rna structure annotation by which to colour
102    // the sequences.
103  13 AlignmentAnnotation[] annotations = alignment.getAlignmentAnnotation();
104  13 if (annotations == null)
105    {
106  3 return;
107    }
108  17 for (int i = 0; i < annotations.length; i++)
109    {
110   
111    // is this a sensible way of determining type of annotation?
112  14 if (annotations[i].visible && annotations[i].isRNA()
113    && annotations[i].isValidStruc())
114    {
115  7 annotation = annotations[i];
116  7 break;
117    }
118    }
119   
120  10 refresh();
121   
122    }
123   
124    private long lastrefresh = -1;
125   
 
126  10 toggle public void refresh()
127    {
128   
129  10 if (annotation != null && ((annotation._rnasecstr == null
130    || lastrefresh != annotation._rnasecstr.hashCode())
131    && annotation.isValidStruc()))
132    {
133  3 annotation.getRNAStruc();
134  3 lastrefresh = annotation._rnasecstr.hashCode();
135  3 numHelix = 0;
136  3 positionsToHelix = new Hashtable<>();
137   
138    // Figure out number of helices
139    // Length of rnasecstr is the number of pairs of positions that base pair
140    // with each other in the secondary structure
141  40 for (int x = 0; x < this.annotation._rnasecstr.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  37 positionsToHelix.put(this.annotation._rnasecstr[x].getBegin(),
151    this.annotation._rnasecstr[x].getFeatureGroup());
152  37 positionsToHelix.put(this.annotation._rnasecstr[x].getEnd(),
153    this.annotation._rnasecstr[x].getFeatureGroup());
154   
155  37 if (Integer.parseInt(
156    this.annotation._rnasecstr[x].getFeatureGroup()) > numHelix)
157    {
158  0 numHelix = Integer.parseInt(
159    this.annotation._rnasecstr[x].getFeatureGroup());
160    }
161   
162    }
163  3 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  0 toggle @Override
195    public Color findColour(char c, int j, SequenceI seq)
196    {
197  0 refresh();
198  0 Color currentColour = Color.white;
199  0 String currentHelix = null;
200  0 currentHelix = positionsToHelix.get(j);
201  0 if (currentHelix != null)
202    {
203  0 currentColour = ColourSchemeProperty.rnaHelices[Integer
204    .parseInt(currentHelix)];
205    }
206  0 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  465 toggle @Override
226    public boolean isApplicableTo(AnnotatedCollectionI ac)
227    {
228  465 if (ac instanceof AlignmentI && ((AlignmentI) ac).hasRNAStructure())
229    {
230  3 return true;
231    }
232   
233    /*
234    * not currently supporting this option for group annotation / colouring
235    */
236  462 return false;
237    }
238   
 
239  571 toggle @Override
240    public String getSchemeName()
241    {
242  571 return JalviewColourScheme.RNAHelices.toString();
243    }
244   
 
245  47 toggle @Override
246    public boolean isSimple()
247    {
248  47 return false;
249    }
250    }