Clover icon

Coverage Report

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

File NucStructure.java

 

Coverage histogram

../../../img/srcFileCovDistChart9.png
13% of files have more coverage

Code metrics

38
70
18
4
307
230
50
0.71
3.89
4.5
2.78

Classes

Class Line # Actions
NucStructure 17 56 31
0.8510638585.1%
AnnotCharSequence 218 12 17
0.8928571389.3%
SFSortByEnd 290 1 1
1.0100%
SFSortByBegin 299 1 1
0.00%
 

Contributing tests

This file is covered by 14 tests. .

Source view

1    package jalview.datamodel.rna;
2   
3    import java.util.Arrays;
4    import java.util.Comparator;
5    import java.util.List;
6   
7    import jalview.analysis.Rna;
8    import jalview.analysis.WUSSParseException;
9    import jalview.analysis.SecStrConsensus.SimpleBP;
10    import jalview.datamodel.AlignmentAnnotation;
11    import jalview.datamodel.Annotation;
12    import jalview.datamodel.SequenceFeature;
13   
14    /**
15    * container and associated methods for working with a set of nucleic acid interactions on a shared coordinate system
16    */
 
17    public class NucStructure implements NucStructureI
18    {
19    boolean isrna=false;
20   
21    public List<SimpleBP> bps = null;
22   
23    /**
24    * RNA secondary structure contact positions
25    */
26    public SequenceFeature[] _rnasecstr = null;
27   
28    /**
29    * position of annotation resulting in invalid WUSS parsing or -1. -2 means
30    * there was no RNA structure in this annotation
31    */
32    private long invalidrnastruc = -2;
33   
34    /**
35    * Updates the _rnasecstr field Determines the positions that base pair and
36    * the positions of helices based on secondary structure from a Stockholm file
37    *
38    * @param rnaAnnotation
39    */
 
40  1049 toggle private void _updateRnaSecStr(AlignmentAnnotation aa, CharSequence rnaAnnotation)
41    {
42  1049 try
43    {
44  1049 _rnasecstr = Rna.getHelixMap(rnaAnnotation);
45  748 invalidrnastruc = -1;
46    } catch (WUSSParseException px)
47    {
48    // DEBUG jalview.bin.Console.outPrintln(px);
49  301 invalidrnastruc = px.getProblemPos();
50    }
51  1049 if (invalidrnastruc > -1)
52    {
53  301 return;
54    }
55   
56  748 if (_rnasecstr != null && _rnasecstr.length > 0)
57    {
58    // show all the RNA secondary structure annotation symbols.
59  748 isrna = true;
60  748 aa.showAllColLabels = true;
61  748 aa.scaleColLabel = true;
62  748 _markRnaHelices(aa);
63    }
64    // jalview.bin.Console.outPrintln("featuregroup " +
65    // _rnasecstr[0].getFeatureGroup());
66   
67    }
68   
 
69  748 toggle private void _markRnaHelices(AlignmentAnnotation aa)
70    {
71  748 int mxval = 0;
72    // Figure out number of helices
73    // Length of rnasecstr is the number of pairs of positions that base pair
74    // with each other in the secondary structure
75  13846 for (int x = 0; x < _rnasecstr.length; x++)
76    {
77   
78    /*
79    * jalview.bin.Console.outPrintln(this.annotation._rnasecstr[x] + " Begin" +
80    * this.annotation._rnasecstr[x].getBegin());
81    */
82    // jalview.bin.Console.outPrintln(this.annotation._rnasecstr[x].getFeatureGroup());
83  13098 int val = 0;
84  13098 try
85    {
86  13098 val = Integer.valueOf(_rnasecstr[x].getFeatureGroup());
87  13098 if (mxval < val)
88    {
89  248 mxval = val;
90    }
91    } catch (NumberFormatException q)
92    {
93    }
94  13098 ;
95   
96  13098 aa.annotations[_rnasecstr[x].getBegin()].value = val;
97  13098 aa.annotations[_rnasecstr[x].getEnd()].value = val;
98   
99    // annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val;
100    // annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val;
101    }
102  748 aa.setScore(mxval);
103    }
104   
 
105  8171 toggle @Override
106    public SequenceFeature[] getRnaSecondaryStructure()
107    {
108  8171 return this._rnasecstr;
109    }
110   
 
111  4 toggle @Override
112    public boolean rnaSecondaryStructureEquivalent(AlignmentAnnotation alignmentAnnotation, AlignmentAnnotation that, boolean compareType)
113    {
114  4 SequenceFeature[] thisSfArray = alignmentAnnotation.getRnaSecondaryStructure();
115  4 SequenceFeature[] thatSfArray = that.getRnaSecondaryStructure();
116  4 if (thisSfArray == null || thatSfArray == null)
117    {
118  0 return thisSfArray == null && thatSfArray == null;
119    }
120  4 if (thisSfArray.length != thatSfArray.length)
121    {
122  1 return false;
123    }
124  3 Arrays.sort(thisSfArray, new SFSortByEnd()); // probably already sorted
125    // like this
126  3 Arrays.sort(thatSfArray, new SFSortByEnd()); // probably already sorted
127    // like this
128  15 for (int i = 0; i < thisSfArray.length; i++)
129    {
130  13 SequenceFeature thisSf = thisSfArray[i];
131  13 SequenceFeature thatSf = thatSfArray[i];
132  13 if (compareType)
133    {
134  13 if (thisSf.getType() == null || thatSf.getType() == null)
135    {
136  0 if (thisSf.getType() == null && thatSf.getType() == null)
137    {
138  0 continue;
139    }
140    else
141    {
142  0 return false;
143    }
144    }
145  13 if (!thisSf.getType().equals(thatSf.getType()))
146    {
147  0 return false;
148    }
149    }
150  13 if (!(thisSf.getBegin() == thatSf.getBegin()
151    && thisSf.getEnd() == thatSf.getEnd()))
152    {
153  1 return false;
154    }
155    }
156  2 return true;
157   
158    }
159   
160    private long _lastrnaannot = -1;
161   
 
162  8159 toggle @Override
163    public String getRNAStruc(AlignmentAnnotation aa)
164    {
165  8159 if (isrna)
166    {
167  8159 String rnastruc = new AnnotCharSequence(aa.annotations).toString();
168  8159 if (_lastrnaannot != rnastruc.hashCode())
169    {
170    // ensure rna structure contacts are up to date
171  4 _lastrnaannot = rnastruc.hashCode();
172  4 _updateRnaSecStr(aa, rnastruc);
173    }
174  8159 return rnastruc;
175    }
176  0 return null;
177    }
178   
 
179  1045 toggle @Override
180    public void update(AlignmentAnnotation alignmentAnnotation)
181    {
182  1045 _updateRnaSecStr(alignmentAnnotation,new AnnotCharSequence(alignmentAnnotation.annotations));
183    }
184   
 
185  8371 toggle @Override
186    public boolean isValidStruc()
187    {
188  8371 return invalidrnastruc == -1;
189    }
190   
 
191  5960 toggle @Override
192    public long getInvalidStrucPos()
193    {
194  5960 return invalidrnastruc;
195    }
196   
 
197  455 toggle @Override
198    public boolean hasNaStruc()
199    {
200  455 return invalidrnastruc>=-1 && _rnasecstr!=null;
201    }
202   
 
203  8160 toggle @Override
204    public long getStructureHashcode()
205    {
206  8160 return _lastrnaannot;
207    }
208   
209    }
210   
211    /**
212    * flyweight access to positions in the alignment annotation row for RNA
213    * processing
214    *
215    * @author jimp
216    *
217    */
 
218    class AnnotCharSequence implements CharSequence
219    {
220    int offset = 0;
221   
222    int max = 0;
223   
224    private Annotation[] annotations;
225   
 
226  9204 toggle public AnnotCharSequence(Annotation[] annotations)
227    {
228  9204 this(annotations, 0, annotations.length);
229    }
230   
 
231  9204 toggle private AnnotCharSequence(Annotation[] annotations, int start, int end)
232    {
233  9204 this.annotations = annotations;
234  9204 offset = start;
235  9204 max = end;
236    }
237   
 
238  0 toggle @Override
239    public CharSequence subSequence(int start, int end)
240    {
241  0 return new AnnotCharSequence(annotations, offset + start, offset + end);
242    }
243   
 
244  71745 toggle @Override
245    public int length()
246    {
247  71745 return max - offset;
248    }
249   
 
250  70700 toggle @Override
251    public char charAt(int index)
252    {
253  70700 return ((index + offset < 0) || (index + offset) >= max
254    || annotations[index + offset] == null
255    || (annotations[index + offset].secondaryStructure <= ' ')
256    ? ' '
257  28040 : annotations[index + offset].displayCharacter == null
258    || annotations[index
259    + offset].displayCharacter
260    .length() == 0
261    ? annotations[index
262    + offset].secondaryStructure
263    : annotations[index
264    + offset].displayCharacter
265    .charAt(0));
266    }
267   
 
268  8159 toggle @Override
269    public String toString()
270    {
271  8159 char[] string = new char[max - offset];
272  8159 int mx = annotations.length;
273   
274  766810 for (int i = offset; i < mx; i++)
275    {
276  758651 string[i] = (annotations[i] == null
277    || (annotations[i].secondaryStructure <= 32))
278    ? ' '
279  293716 : (annotations[i].displayCharacter == null
280    || annotations[i].displayCharacter
281    .length() == 0
282    ? annotations[i].secondaryStructure
283    : annotations[i].displayCharacter
284    .charAt(0));
285    }
286  8159 return new String(string);
287    }
288    }
289   
 
290    class SFSortByEnd implements Comparator<SequenceFeature>
291    {
 
292  32 toggle @Override
293    public int compare(SequenceFeature a, SequenceFeature b)
294    {
295  32 return a.getEnd() - b.getEnd();
296    }
297    }
298   
 
299    class SFSortByBegin implements Comparator<SequenceFeature>
300    {
 
301  0 toggle @Override
302    public int compare(SequenceFeature a, SequenceFeature b)
303    {
304  0 return a.getBegin() - b.getBegin();
305    }
306    }
307