Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.schemes

File RNAHelicesColour.java

 

Coverage histogram

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

Code metrics

16
44
13
1
249
133
27
0.61
3.38
13
2.08

Classes

Class Line # Actions
RNAHelicesColour 41 44 27 25
0.6575342465.8%
 

Contributing tests

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