| 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 |
|
|
| 16 |
|
|
| |
|
| 85.1% |
Uncovered Elements: 14 (94) |
Complexity: 31 |
Complexity Density: 0.55 |
|
| 17 |
|
public class NucStructure implements NucStructureI |
| 18 |
|
{ |
| 19 |
|
boolean isrna=false; |
| 20 |
|
|
| 21 |
|
public List<SimpleBP> bps = null; |
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
public SequenceFeature[] _rnasecstr = null; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
private long invalidrnastruc = -2; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@param |
| 39 |
|
|
| |
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 40 |
1049 |
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 |
|
|
| 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 |
|
|
| 59 |
748 |
isrna = true; |
| 60 |
748 |
aa.showAllColLabels = true; |
| 61 |
748 |
aa.scaleColLabel = true; |
| 62 |
748 |
_markRnaHelices(aa); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
} |
| 68 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 69 |
748 |
private void _markRnaHelices(AlignmentAnnotation aa)... |
| 70 |
|
{ |
| 71 |
748 |
int mxval = 0; |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
13846 |
for (int x = 0; x < _rnasecstr.length; x++) |
| 76 |
|
{ |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 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 |
|
|
| 100 |
|
|
| 101 |
|
} |
| 102 |
748 |
aa.setScore(mxval); |
| 103 |
|
} |
| 104 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 105 |
8171 |
@Override... |
| 106 |
|
public SequenceFeature[] getRnaSecondaryStructure() |
| 107 |
|
{ |
| 108 |
8171 |
return this._rnasecstr; |
| 109 |
|
} |
| 110 |
|
|
| |
|
| 70.3% |
Uncovered Elements: 11 (37) |
Complexity: 13 |
Complexity Density: 0.62 |
|
| 111 |
4 |
@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()); |
| 125 |
|
|
| 126 |
3 |
Arrays.sort(thatSfArray, new SFSortByEnd()); |
| 127 |
|
|
| 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 |
|
|
| |
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 162 |
8159 |
@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 |
|
|
| 171 |
4 |
_lastrnaannot = rnastruc.hashCode(); |
| 172 |
4 |
_updateRnaSecStr(aa, rnastruc); |
| 173 |
|
} |
| 174 |
8159 |
return rnastruc; |
| 175 |
|
} |
| 176 |
0 |
return null; |
| 177 |
|
} |
| 178 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 179 |
1045 |
@Override... |
| 180 |
|
public void update(AlignmentAnnotation alignmentAnnotation) |
| 181 |
|
{ |
| 182 |
1045 |
_updateRnaSecStr(alignmentAnnotation,new AnnotCharSequence(alignmentAnnotation.annotations)); |
| 183 |
|
} |
| 184 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 185 |
8371 |
@Override... |
| 186 |
|
public boolean isValidStruc() |
| 187 |
|
{ |
| 188 |
8371 |
return invalidrnastruc == -1; |
| 189 |
|
} |
| 190 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 191 |
5960 |
@Override... |
| 192 |
|
public long getInvalidStrucPos() |
| 193 |
|
{ |
| 194 |
5960 |
return invalidrnastruc; |
| 195 |
|
} |
| 196 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 197 |
455 |
@Override... |
| 198 |
|
public boolean hasNaStruc() |
| 199 |
|
{ |
| 200 |
455 |
return invalidrnastruc>=-1 && _rnasecstr!=null; |
| 201 |
|
} |
| 202 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 203 |
8160 |
@Override... |
| 204 |
|
public long getStructureHashcode() |
| 205 |
|
{ |
| 206 |
8160 |
return _lastrnaannot; |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
} |
| 210 |
|
|
| 211 |
|
|
| 212 |
|
|
| 213 |
|
|
| 214 |
|
|
| 215 |
|
@author |
| 216 |
|
|
| 217 |
|
|
| |
|
| 89.3% |
Uncovered Elements: 3 (28) |
Complexity: 17 |
Complexity Density: 1.42 |
|
| 218 |
|
class AnnotCharSequence implements CharSequence |
| 219 |
|
{ |
| 220 |
|
int offset = 0; |
| 221 |
|
|
| 222 |
|
int max = 0; |
| 223 |
|
|
| 224 |
|
private Annotation[] annotations; |
| 225 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 226 |
9204 |
public AnnotCharSequence(Annotation[] annotations)... |
| 227 |
|
{ |
| 228 |
9204 |
this(annotations, 0, annotations.length); |
| 229 |
|
} |
| 230 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 231 |
9204 |
private AnnotCharSequence(Annotation[] annotations, int start, int end)... |
| 232 |
|
{ |
| 233 |
9204 |
this.annotations = annotations; |
| 234 |
9204 |
offset = start; |
| 235 |
9204 |
max = end; |
| 236 |
|
} |
| 237 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 238 |
0 |
@Override... |
| 239 |
|
public CharSequence subSequence(int start, int end) |
| 240 |
|
{ |
| 241 |
0 |
return new AnnotCharSequence(annotations, offset + start, offset + end); |
| 242 |
|
} |
| 243 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 244 |
71745 |
@Override... |
| 245 |
|
public int length() |
| 246 |
|
{ |
| 247 |
71745 |
return max - offset; |
| 248 |
|
} |
| 249 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 7 |
Complexity Density: 7 |
|
| 250 |
70700 |
@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 |
|
|
| |
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 6 |
Complexity Density: 1.2 |
|
| 268 |
8159 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 290 |
|
class SFSortByEnd implements Comparator<SequenceFeature> |
| 291 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 292 |
32 |
@Override... |
| 293 |
|
public int compare(SequenceFeature a, SequenceFeature b) |
| 294 |
|
{ |
| 295 |
32 |
return a.getEnd() - b.getEnd(); |
| 296 |
|
} |
| 297 |
|
} |
| 298 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
| 299 |
|
class SFSortByBegin implements Comparator<SequenceFeature> |
| 300 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 301 |
0 |
@Override... |
| 302 |
|
public int compare(SequenceFeature a, SequenceFeature b) |
| 303 |
|
{ |
| 304 |
0 |
return a.getBegin() - b.getBegin(); |
| 305 |
|
} |
| 306 |
|
} |
| 307 |
|
|