| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.analysis; |
| 22 |
|
|
| 23 |
|
import jalview.api.AlignViewportI; |
| 24 |
|
import jalview.datamodel.AlignedCodon; |
| 25 |
|
import jalview.datamodel.AlignedCodonFrame; |
| 26 |
|
import jalview.datamodel.Alignment; |
| 27 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 28 |
|
import jalview.datamodel.AlignmentI; |
| 29 |
|
import jalview.datamodel.Annotation; |
| 30 |
|
import jalview.datamodel.DBRefEntry; |
| 31 |
|
import jalview.datamodel.DBRefSource; |
| 32 |
|
import jalview.datamodel.FeatureProperties; |
| 33 |
|
import jalview.datamodel.GraphLine; |
| 34 |
|
import jalview.datamodel.Mapping; |
| 35 |
|
import jalview.datamodel.Sequence; |
| 36 |
|
import jalview.datamodel.SequenceFeature; |
| 37 |
|
import jalview.datamodel.SequenceI; |
| 38 |
|
import jalview.schemes.ResidueProperties; |
| 39 |
|
import jalview.util.Comparison; |
| 40 |
|
import jalview.util.DBRefUtils; |
| 41 |
|
import jalview.util.MapList; |
| 42 |
|
import jalview.util.ShiftList; |
| 43 |
|
|
| 44 |
|
import java.util.ArrayList; |
| 45 |
|
import java.util.Arrays; |
| 46 |
|
import java.util.Comparator; |
| 47 |
|
import java.util.Iterator; |
| 48 |
|
import java.util.List; |
| 49 |
|
|
| |
|
| 64.9% |
Uncovered Elements: 189 (539) |
Complexity: 139 |
Complexity Density: 0.37 |
|
| 50 |
|
public class Dna |
| 51 |
|
{ |
| 52 |
|
private static final String STOP_ASTERIX = "*"; |
| 53 |
|
|
| 54 |
|
private static final Comparator<AlignedCodon> comparator = new CodonComparator(); |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
private final List<SequenceI> selection; |
| 61 |
|
|
| 62 |
|
private final String[] seqstring; |
| 63 |
|
|
| 64 |
|
private final Iterator<int[]> contigs; |
| 65 |
|
|
| 66 |
|
private final char gapChar; |
| 67 |
|
|
| 68 |
|
private final AlignmentAnnotation[] annotations; |
| 69 |
|
|
| 70 |
|
private final int dnaWidth; |
| 71 |
|
|
| 72 |
|
private final AlignmentI dataset; |
| 73 |
|
|
| 74 |
|
private ShiftList vismapping; |
| 75 |
|
|
| 76 |
|
private int[] startcontigs; |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
private int aaWidth = 0; |
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
private AlignedCodon[] alignedCodons; |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
@param |
| 97 |
|
@param |
| 98 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 99 |
24 |
public Dna(AlignViewportI viewport, Iterator<int[]> visibleContigs)... |
| 100 |
|
{ |
| 101 |
24 |
this.selection = Arrays.asList(viewport.getSequenceSelection()); |
| 102 |
24 |
this.seqstring = viewport.getViewAsString(true); |
| 103 |
24 |
this.contigs = visibleContigs; |
| 104 |
24 |
this.gapChar = viewport.getGapCharacter(); |
| 105 |
24 |
this.annotations = viewport.getAlignment().getAlignmentAnnotation(); |
| 106 |
24 |
this.dnaWidth = viewport.getAlignment().getWidth(); |
| 107 |
24 |
this.dataset = viewport.getAlignment().getDataset(); |
| 108 |
24 |
initContigs(); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 3 |
Complexity Density: 0.17 |
|
| 114 |
24 |
private void initContigs()... |
| 115 |
|
{ |
| 116 |
24 |
vismapping = new ShiftList(); |
| 117 |
|
|
| 118 |
|
|
| 119 |
24 |
int npos = 0; |
| 120 |
24 |
int[] lastregion = null; |
| 121 |
24 |
ArrayList<Integer> tempcontigs = new ArrayList<>(); |
| 122 |
50 |
while (contigs.hasNext()) |
| 123 |
|
{ |
| 124 |
26 |
int[] region = contigs.next(); |
| 125 |
26 |
if (lastregion == null) |
| 126 |
|
{ |
| 127 |
24 |
vismapping.addShift(npos, region[0]); |
| 128 |
|
} |
| 129 |
|
else |
| 130 |
|
{ |
| 131 |
|
|
| 132 |
2 |
vismapping.addShift(npos, region[0] - lastregion[1] + 1); |
| 133 |
|
} |
| 134 |
26 |
lastregion = region; |
| 135 |
26 |
tempcontigs.add(region[0]); |
| 136 |
26 |
tempcontigs.add(region[1]); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
24 |
startcontigs = new int[tempcontigs.size()]; |
| 140 |
24 |
int i = 0; |
| 141 |
24 |
for (Integer val : tempcontigs) |
| 142 |
|
{ |
| 143 |
52 |
startcontigs[i] = val; |
| 144 |
52 |
i++; |
| 145 |
|
} |
| 146 |
24 |
tempcontigs = null; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
@param |
| 163 |
|
@param |
| 164 |
|
@return |
| 165 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 166 |
3347 |
public static final int compareCodonPos(AlignedCodon ac1,... |
| 167 |
|
AlignedCodon ac2) |
| 168 |
|
{ |
| 169 |
3347 |
return comparator.compare(ac1, ac2); |
| 170 |
|
|
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
@param |
| 178 |
|
@param |
| 179 |
|
@return |
| 180 |
|
|
| |
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 7 |
Complexity Density: 1.4 |
|
| 181 |
0 |
private static int jalview_2_8_2compare(AlignedCodon ac1,... |
| 182 |
|
AlignedCodon ac2) |
| 183 |
|
{ |
| 184 |
0 |
if (ac1 == null || ac2 == null || (ac1.equals(ac2))) |
| 185 |
|
{ |
| 186 |
0 |
return 0; |
| 187 |
|
} |
| 188 |
0 |
if (ac1.pos1 < ac2.pos1 || ac1.pos2 < ac2.pos2 || ac1.pos3 < ac2.pos3) |
| 189 |
|
{ |
| 190 |
|
|
| 191 |
0 |
return -1; |
| 192 |
|
} |
| 193 |
|
|
| 194 |
0 |
return 1; |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
@return |
| 201 |
|
|
| |
|
| 96.6% |
Uncovered Elements: 1 (29) |
Complexity: 5 |
Complexity Density: 0.24 |
|
| 202 |
23 |
public AlignmentI translateCdna(GeneticCodeI codeTable)... |
| 203 |
|
{ |
| 204 |
23 |
AlignedCodonFrame acf = new AlignedCodonFrame(); |
| 205 |
|
|
| 206 |
23 |
alignedCodons = new AlignedCodon[dnaWidth]; |
| 207 |
|
|
| 208 |
23 |
int s; |
| 209 |
23 |
int sSize = selection.size(); |
| 210 |
23 |
List<SequenceI> pepseqs = new ArrayList<>(); |
| 211 |
240 |
for (s = 0; s < sSize; s++) |
| 212 |
|
{ |
| 213 |
217 |
SequenceI newseq = translateCodingRegion(selection.get(s), |
| 214 |
|
seqstring[s], acf, pepseqs, codeTable); |
| 215 |
|
|
| 216 |
217 |
if (newseq != null) |
| 217 |
|
{ |
| 218 |
217 |
pepseqs.add(newseq); |
| 219 |
217 |
SequenceI ds = newseq; |
| 220 |
217 |
if (dataset != null) |
| 221 |
|
{ |
| 222 |
2 |
while (ds.getDatasetSequence() != null) |
| 223 |
|
{ |
| 224 |
1 |
ds = ds.getDatasetSequence(); |
| 225 |
|
} |
| 226 |
1 |
dataset.addSequence(ds); |
| 227 |
|
} |
| 228 |
|
} |
| 229 |
|
} |
| 230 |
|
|
| 231 |
23 |
SequenceI[] newseqs = pepseqs.toArray(new SequenceI[pepseqs.size()]); |
| 232 |
23 |
AlignmentI al = new Alignment(newseqs); |
| 233 |
|
|
| 234 |
23 |
al.padGaps(); |
| 235 |
|
|
| 236 |
23 |
al.setDataset(dataset); |
| 237 |
23 |
translateAlignedAnnotations(al, acf); |
| 238 |
23 |
al.addCodonFrame(acf); |
| 239 |
23 |
return al; |
| 240 |
|
} |
| 241 |
|
|
| 242 |
|
|
| 243 |
|
|
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
@param |
| 248 |
|
@param |
| 249 |
|
@return |
| 250 |
|
|
| |
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 12 |
Complexity Density: 0.63 |
|
| 251 |
0 |
public static boolean canTranslate(SequenceI[] selection,... |
| 252 |
|
int viscontigs[]) |
| 253 |
|
{ |
| 254 |
0 |
for (int gd = 0; gd < selection.length; gd++) |
| 255 |
|
{ |
| 256 |
0 |
SequenceI dna = selection[gd]; |
| 257 |
0 |
List<DBRefEntry> dnarefs = DBRefUtils.selectRefs(dna.getDBRefs(), |
| 258 |
|
jalview.datamodel.DBRefSource.DNACODINGDBS); |
| 259 |
0 |
if (dnarefs != null) |
| 260 |
|
{ |
| 261 |
|
|
| 262 |
0 |
List<DBRefEntry> mappedrefs = new ArrayList<>(); |
| 263 |
0 |
List<DBRefEntry> refs = dna.getDBRefs(); |
| 264 |
0 |
for (int d = 0, nd = refs.size(); d < nd; d++) |
| 265 |
|
{ |
| 266 |
0 |
DBRefEntry ref = refs.get(d); |
| 267 |
0 |
if (ref.getMap() != null && ref.getMap().getMap() != null |
| 268 |
|
&& ref.getMap().getMap().getFromRatio() == 3 |
| 269 |
|
&& ref.getMap().getMap().getToRatio() == 1) |
| 270 |
|
{ |
| 271 |
0 |
mappedrefs.add(ref); |
| 272 |
|
} |
| 273 |
|
} |
| 274 |
0 |
dnarefs = mappedrefs; |
| 275 |
0 |
for (int d = 0, nd = dnarefs.size(); d < nd; d++) |
| 276 |
|
{ |
| 277 |
0 |
Mapping mp = dnarefs.get(d).getMap(); |
| 278 |
0 |
if (mp != null) |
| 279 |
|
{ |
| 280 |
0 |
for (int vc = 0, nv = viscontigs.length; vc < nv; vc += 2) |
| 281 |
|
{ |
| 282 |
0 |
int[] mpr = mp.locateMappedRange(viscontigs[vc], |
| 283 |
|
viscontigs[vc + 1]); |
| 284 |
0 |
if (mpr != null) |
| 285 |
|
{ |
| 286 |
0 |
return true; |
| 287 |
|
} |
| 288 |
|
} |
| 289 |
|
} |
| 290 |
|
} |
| 291 |
|
} |
| 292 |
|
} |
| 293 |
0 |
return false; |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
|
| 297 |
|
|
| 298 |
|
|
| 299 |
|
|
| 300 |
|
@param |
| 301 |
|
|
| 302 |
|
|
| |
|
| 12.8% |
Uncovered Elements: 41 (47) |
Complexity: 15 |
Complexity Density: 0.56 |
|
| 303 |
23 |
protected void translateAlignedAnnotations(AlignmentI al,... |
| 304 |
|
AlignedCodonFrame acf) |
| 305 |
|
{ |
| 306 |
|
|
| 307 |
|
|
| 308 |
|
|
| 309 |
23 |
if (annotations != null) |
| 310 |
|
{ |
| 311 |
23 |
for (AlignmentAnnotation annotation : annotations) |
| 312 |
|
{ |
| 313 |
|
|
| 314 |
|
|
| 315 |
|
|
| 316 |
|
|
| 317 |
|
|
| 318 |
|
|
| 319 |
318 |
if (annotation.autoCalculated || !annotation.isForDisplay() |
| 320 |
|
|| annotation.isRNA()) |
| 321 |
|
{ |
| 322 |
318 |
continue; |
| 323 |
|
} |
| 324 |
|
|
| 325 |
0 |
int aSize = aaWidth; |
| 326 |
0 |
Annotation[] anots = (annotation.annotations == null) ? null |
| 327 |
|
: new Annotation[aSize]; |
| 328 |
0 |
if (anots != null) |
| 329 |
|
{ |
| 330 |
0 |
for (int a = 0; a < aSize; a++) |
| 331 |
|
{ |
| 332 |
|
|
| 333 |
0 |
if (a < alignedCodons.length && alignedCodons[a] != null |
| 334 |
|
&& alignedCodons[a].pos1 == (alignedCodons[a].pos3 - 2)) |
| 335 |
|
{ |
| 336 |
0 |
anots[a] = getCodonAnnotation(alignedCodons[a], |
| 337 |
|
annotation.annotations); |
| 338 |
|
} |
| 339 |
|
} |
| 340 |
|
} |
| 341 |
|
|
| 342 |
0 |
AlignmentAnnotation aa = new AlignmentAnnotation(annotation.label, |
| 343 |
|
annotation.description, anots); |
| 344 |
0 |
aa.graph = annotation.graph; |
| 345 |
0 |
aa.graphGroup = annotation.graphGroup; |
| 346 |
0 |
aa.graphHeight = annotation.graphHeight; |
| 347 |
0 |
if (annotation.getThreshold() != null) |
| 348 |
|
{ |
| 349 |
0 |
aa.setThreshold(new GraphLine(annotation.getThreshold())); |
| 350 |
|
} |
| 351 |
0 |
if (annotation.hasScore) |
| 352 |
|
{ |
| 353 |
0 |
aa.setScore(annotation.getScore()); |
| 354 |
|
} |
| 355 |
|
|
| 356 |
0 |
final SequenceI seqRef = annotation.sequenceRef; |
| 357 |
0 |
if (seqRef != null) |
| 358 |
|
{ |
| 359 |
0 |
SequenceI aaSeq = acf.getAaForDnaSeq(seqRef); |
| 360 |
0 |
if (aaSeq != null) |
| 361 |
|
{ |
| 362 |
|
|
| 363 |
|
|
| 364 |
0 |
aa.setSequenceRef(aaSeq); |
| 365 |
|
|
| 366 |
0 |
aa.createSequenceMapping(aaSeq, aaSeq.getStart(), true); |
| 367 |
0 |
aa.adjustForAlignment(); |
| 368 |
0 |
aaSeq.addAlignmentAnnotation(aa); |
| 369 |
|
} |
| 370 |
|
} |
| 371 |
0 |
al.addAnnotation(aa); |
| 372 |
|
} |
| 373 |
|
} |
| 374 |
|
} |
| 375 |
|
|
| |
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 10 |
Complexity Density: 0.45 |
|
| 376 |
0 |
private static Annotation getCodonAnnotation(AlignedCodon is,... |
| 377 |
|
Annotation[] annotations) |
| 378 |
|
{ |
| 379 |
|
|
| 380 |
|
|
| 381 |
0 |
int contrib = 0; |
| 382 |
0 |
Annotation annot = null; |
| 383 |
0 |
for (int p = 1; p <= 3; p++) |
| 384 |
|
{ |
| 385 |
0 |
int dnaCol = is.getBaseColumn(p); |
| 386 |
0 |
if (annotations[dnaCol] != null) |
| 387 |
|
{ |
| 388 |
0 |
if (annot == null) |
| 389 |
|
{ |
| 390 |
0 |
annot = new Annotation(annotations[dnaCol]); |
| 391 |
0 |
contrib = 1; |
| 392 |
|
} |
| 393 |
|
else |
| 394 |
|
{ |
| 395 |
|
|
| 396 |
0 |
Annotation cpy = new Annotation(annotations[dnaCol]); |
| 397 |
0 |
if (annot.colour == null) |
| 398 |
|
{ |
| 399 |
0 |
annot.colour = cpy.colour; |
| 400 |
|
} |
| 401 |
0 |
if (annot.description == null || annot.description.length() == 0) |
| 402 |
|
{ |
| 403 |
0 |
annot.description = cpy.description; |
| 404 |
|
} |
| 405 |
0 |
if (annot.displayCharacter == null) |
| 406 |
|
{ |
| 407 |
0 |
annot.displayCharacter = cpy.displayCharacter; |
| 408 |
|
} |
| 409 |
0 |
if (annot.secondaryStructure == 0) |
| 410 |
|
{ |
| 411 |
0 |
annot.secondaryStructure = cpy.secondaryStructure; |
| 412 |
|
} |
| 413 |
0 |
annot.value += cpy.value; |
| 414 |
0 |
contrib++; |
| 415 |
|
} |
| 416 |
|
} |
| 417 |
|
} |
| 418 |
0 |
if (contrib > 1) |
| 419 |
|
{ |
| 420 |
0 |
annot.value /= contrib; |
| 421 |
|
} |
| 422 |
0 |
return annot; |
| 423 |
|
} |
| 424 |
|
|
| 425 |
|
|
| 426 |
|
|
| 427 |
|
|
| 428 |
|
@param |
| 429 |
|
|
| 430 |
|
@param |
| 431 |
|
|
| 432 |
|
@param |
| 433 |
|
|
| 434 |
|
@param |
| 435 |
|
@param |
| 436 |
|
@return |
| 437 |
|
|
| |
|
| 73% |
Uncovered Elements: 51 (189) |
Complexity: 39 |
Complexity Density: 0.31 |
|
| 438 |
217 |
protected SequenceI translateCodingRegion(SequenceI selection,... |
| 439 |
|
String seqstring, AlignedCodonFrame acf, |
| 440 |
|
List<SequenceI> proteinSeqs, GeneticCodeI codeTable) |
| 441 |
|
{ |
| 442 |
217 |
List<int[]> skip = new ArrayList<>(); |
| 443 |
217 |
int[] skipint = null; |
| 444 |
|
|
| 445 |
217 |
int npos = 0; |
| 446 |
217 |
int vc = 0; |
| 447 |
|
|
| 448 |
217 |
int[] scontigs = new int[startcontigs.length]; |
| 449 |
217 |
System.arraycopy(startcontigs, 0, scontigs, 0, startcontigs.length); |
| 450 |
|
|
| 451 |
|
|
| 452 |
217 |
StringBuilder protein = new StringBuilder(seqstring.length() / 2); |
| 453 |
217 |
String seq = seqstring.replace('U', 'T').replace('u', 'T'); |
| 454 |
217 |
char codon[] = new char[3]; |
| 455 |
217 |
int cdp[] = new int[3]; |
| 456 |
217 |
int rf = 0; |
| 457 |
217 |
int lastnpos = 0; |
| 458 |
217 |
int nend; |
| 459 |
217 |
int aspos = 0; |
| 460 |
217 |
int resSize = 0; |
| 461 |
6275 |
for (npos = 0, nend = seq.length(); npos < nend; npos++) |
| 462 |
|
{ |
| 463 |
6058 |
if (!Comparison.isGap(seq.charAt(npos))) |
| 464 |
|
{ |
| 465 |
6028 |
cdp[rf] = npos; |
| 466 |
6028 |
codon[rf++] = seq.charAt(npos); |
| 467 |
|
} |
| 468 |
6058 |
if (rf == 3) |
| 469 |
|
{ |
| 470 |
|
|
| 471 |
|
|
| 472 |
|
|
| 473 |
1888 |
AlignedCodon alignedCodon = new AlignedCodon(cdp[0], cdp[1], |
| 474 |
|
cdp[2]); |
| 475 |
1888 |
String aa = codeTable.translate(new String(codon)); |
| 476 |
1888 |
rf = 0; |
| 477 |
1888 |
final String gapString = String.valueOf(gapChar); |
| 478 |
1888 |
if (aa == null) |
| 479 |
|
{ |
| 480 |
1 |
aa = gapString; |
| 481 |
1 |
if (skipint == null) |
| 482 |
|
{ |
| 483 |
1 |
skipint = new int[] { alignedCodon.pos1, |
| 484 |
|
alignedCodon.pos3 |
| 485 |
|
|
| 486 |
|
|
| 487 |
|
}; |
| 488 |
|
} |
| 489 |
1 |
skipint[1] = alignedCodon.pos3; |
| 490 |
|
} |
| 491 |
|
else |
| 492 |
|
{ |
| 493 |
1887 |
if (skipint != null) |
| 494 |
|
{ |
| 495 |
|
|
| 496 |
1 |
skipint[0] = vismapping.shift(skipint[0]); |
| 497 |
1 |
skipint[1] = vismapping.shift(skipint[1]); |
| 498 |
2 |
for (vc = 0; vc < scontigs.length;) |
| 499 |
|
{ |
| 500 |
1 |
if (scontigs[vc + 1] < skipint[0]) |
| 501 |
|
{ |
| 502 |
|
|
| 503 |
0 |
vc += 2; |
| 504 |
0 |
continue; |
| 505 |
|
} |
| 506 |
1 |
if (scontigs[vc] > skipint[1]) |
| 507 |
|
{ |
| 508 |
|
|
| 509 |
0 |
break; |
| 510 |
|
} |
| 511 |
|
|
| 512 |
|
|
| 513 |
1 |
int[] t; |
| 514 |
|
|
| 515 |
|
|
| 516 |
|
|
| 517 |
|
|
| 518 |
|
|
| 519 |
1 |
if (scontigs[vc] <= skipint[0]) |
| 520 |
|
{ |
| 521 |
1 |
if (skipint[0] == scontigs[vc]) |
| 522 |
|
{ |
| 523 |
|
|
| 524 |
|
|
| 525 |
0 |
if (scontigs[vc + 1] > skipint[1]) |
| 526 |
|
{ |
| 527 |
0 |
scontigs[vc] = skipint[1]; |
| 528 |
0 |
vc += 2; |
| 529 |
|
} |
| 530 |
|
else |
| 531 |
|
{ |
| 532 |
0 |
if (scontigs[vc + 1] == skipint[1]) |
| 533 |
|
{ |
| 534 |
|
|
| 535 |
0 |
t = new int[scontigs.length - 2]; |
| 536 |
0 |
if (vc > 0) |
| 537 |
|
{ |
| 538 |
0 |
System.arraycopy(scontigs, 0, t, 0, vc - 1); |
| 539 |
|
} |
| 540 |
0 |
if (vc + 2 < t.length) |
| 541 |
|
{ |
| 542 |
0 |
System.arraycopy(scontigs, vc + 2, t, vc, |
| 543 |
|
t.length - vc + 2); |
| 544 |
|
} |
| 545 |
0 |
scontigs = t; |
| 546 |
|
} |
| 547 |
|
else |
| 548 |
|
{ |
| 549 |
|
|
| 550 |
0 |
scontigs[vc + 1] = skipint[0] - 1; |
| 551 |
0 |
vc += 2; |
| 552 |
|
} |
| 553 |
|
} |
| 554 |
|
} |
| 555 |
|
else |
| 556 |
|
{ |
| 557 |
|
|
| 558 |
1 |
if (scontigs[vc + 1] < skipint[1]) |
| 559 |
|
{ |
| 560 |
|
|
| 561 |
0 |
scontigs[vc + 1] = skipint[0] - 1; |
| 562 |
0 |
vc += 2; |
| 563 |
|
} |
| 564 |
|
else |
| 565 |
|
{ |
| 566 |
|
|
| 567 |
1 |
t = new int[scontigs.length + 2]; |
| 568 |
1 |
System.arraycopy(scontigs, 0, t, 0, vc + 1); |
| 569 |
1 |
t[vc + 1] = skipint[0]; |
| 570 |
1 |
t[vc + 2] = skipint[1]; |
| 571 |
1 |
System.arraycopy(scontigs, vc + 1, t, vc + 3, |
| 572 |
|
scontigs.length - (vc + 1)); |
| 573 |
1 |
scontigs = t; |
| 574 |
1 |
vc += 4; |
| 575 |
|
} |
| 576 |
|
} |
| 577 |
|
} |
| 578 |
|
} |
| 579 |
1 |
skip.add(skipint); |
| 580 |
1 |
skipint = null; |
| 581 |
|
} |
| 582 |
1887 |
if (aa.equals(ResidueProperties.STOP)) |
| 583 |
|
{ |
| 584 |
0 |
aa = STOP_ASTERIX; |
| 585 |
|
} |
| 586 |
1887 |
resSize++; |
| 587 |
|
} |
| 588 |
1888 |
boolean findpos = true; |
| 589 |
5150 |
while (findpos) |
| 590 |
|
{ |
| 591 |
|
|
| 592 |
|
|
| 593 |
|
|
| 594 |
|
|
| 595 |
3262 |
final int compareCodonPos = (aspos < alignedCodons.length) |
| 596 |
|
? compareCodonPos(alignedCodon, alignedCodons[aspos]) |
| 597 |
|
: -1; |
| 598 |
3262 |
switch (compareCodonPos) |
| 599 |
|
{ |
| 600 |
178 |
case -1: |
| 601 |
|
|
| 602 |
|
|
| 603 |
|
|
| 604 |
|
|
| 605 |
|
|
| 606 |
178 |
insertAAGap(aspos, proteinSeqs); |
| 607 |
178 |
findpos = false; |
| 608 |
178 |
break; |
| 609 |
|
|
| 610 |
1374 |
case +1: |
| 611 |
|
|
| 612 |
|
|
| 613 |
|
|
| 614 |
|
|
| 615 |
|
|
| 616 |
1374 |
aa = gapString + aa; |
| 617 |
1374 |
aspos++; |
| 618 |
1374 |
break; |
| 619 |
|
|
| 620 |
1710 |
case 0: |
| 621 |
|
|
| 622 |
|
|
| 623 |
|
|
| 624 |
|
|
| 625 |
1710 |
findpos = false; |
| 626 |
|
} |
| 627 |
|
} |
| 628 |
1888 |
protein.append(aa); |
| 629 |
1888 |
lastnpos = npos; |
| 630 |
1888 |
if (alignedCodons[aspos] == null) |
| 631 |
|
{ |
| 632 |
|
|
| 633 |
466 |
alignedCodons[aspos] = alignedCodon; |
| 634 |
|
} |
| 635 |
1422 |
else if (!alignedCodons[aspos].equals(alignedCodon)) |
| 636 |
|
{ |
| 637 |
0 |
throw new IllegalStateException( |
| 638 |
|
"Tried to coalign " + alignedCodons[aspos].toString() |
| 639 |
|
+ " with " + alignedCodon.toString()); |
| 640 |
|
} |
| 641 |
1888 |
if (aspos >= aaWidth) |
| 642 |
|
{ |
| 643 |
|
|
| 644 |
449 |
aaWidth = aspos; |
| 645 |
|
} |
| 646 |
|
|
| 647 |
1888 |
aspos++; |
| 648 |
|
} |
| 649 |
|
} |
| 650 |
217 |
if (resSize > 0) |
| 651 |
|
{ |
| 652 |
217 |
SequenceI newseq = new Sequence(selection.getName(), |
| 653 |
|
protein.toString()); |
| 654 |
217 |
if (rf != 0) |
| 655 |
|
{ |
| 656 |
188 |
final String errMsg = "trimming contigs for incomplete terminal codon."; |
| 657 |
188 |
jalview.bin.Console.errPrintln(errMsg); |
| 658 |
|
|
| 659 |
188 |
vc = scontigs.length - 1; |
| 660 |
188 |
lastnpos = vismapping.shift(lastnpos); |
| 661 |
|
|
| 662 |
|
|
| 663 |
|
|
| 664 |
|
|
| 665 |
376 |
while (vc >= 0 && scontigs[vc] > lastnpos) |
| 666 |
|
{ |
| 667 |
188 |
if (vc > 0 && scontigs[vc - 1] > lastnpos) |
| 668 |
|
{ |
| 669 |
0 |
vc -= 2; |
| 670 |
|
} |
| 671 |
|
else |
| 672 |
|
{ |
| 673 |
|
|
| 674 |
188 |
scontigs[vc] = lastnpos; |
| 675 |
|
} |
| 676 |
|
} |
| 677 |
|
|
| 678 |
188 |
if (vc > 0 && (vc + 1) < scontigs.length) |
| 679 |
|
{ |
| 680 |
|
|
| 681 |
0 |
int t[] = new int[vc + 1]; |
| 682 |
0 |
System.arraycopy(scontigs, 0, t, 0, vc + 1); |
| 683 |
0 |
scontigs = t; |
| 684 |
|
} |
| 685 |
188 |
if (vc <= 0) |
| 686 |
|
{ |
| 687 |
0 |
scontigs = null; |
| 688 |
|
} |
| 689 |
|
} |
| 690 |
217 |
if (scontigs != null) |
| 691 |
|
{ |
| 692 |
217 |
npos = 0; |
| 693 |
|
|
| 694 |
412 |
for (vc = 0; vc < scontigs.length; vc += 2) |
| 695 |
|
{ |
| 696 |
220 |
scontigs[vc] = selection.findPosition(scontigs[vc]); |
| 697 |
220 |
scontigs[vc + 1] = selection.findPosition(scontigs[vc + 1]); |
| 698 |
220 |
if (scontigs[vc + 1] == selection.getEnd()) |
| 699 |
|
{ |
| 700 |
25 |
break; |
| 701 |
|
} |
| 702 |
|
} |
| 703 |
|
|
| 704 |
217 |
if ((vc + 2) < scontigs.length) |
| 705 |
|
{ |
| 706 |
0 |
int t[] = new int[vc + 2]; |
| 707 |
0 |
System.arraycopy(scontigs, 0, t, 0, vc + 2); |
| 708 |
0 |
scontigs = t; |
| 709 |
|
} |
| 710 |
|
|
| 711 |
|
|
| 712 |
|
|
| 713 |
|
|
| 714 |
|
|
| 715 |
|
|
| 716 |
|
|
| 717 |
|
|
| 718 |
|
|
| 719 |
|
|
| 720 |
|
|
| 721 |
|
|
| 722 |
|
|
| 723 |
|
|
| 724 |
217 |
MapList map = new MapList(scontigs, new int[] { 1, resSize }, 3, 1); |
| 725 |
|
|
| 726 |
217 |
transferCodedFeatures(selection, newseq, map); |
| 727 |
|
|
| 728 |
|
|
| 729 |
|
|
| 730 |
|
|
| 731 |
217 |
SequenceI rseq = newseq.deriveSequence(); |
| 732 |
|
|
| 733 |
|
|
| 734 |
|
|
| 735 |
|
|
| 736 |
|
|
| 737 |
|
|
| 738 |
217 |
acf.addMap(selection, rseq, map); |
| 739 |
217 |
return rseq; |
| 740 |
|
} |
| 741 |
|
} |
| 742 |
|
|
| 743 |
|
|
| 744 |
0 |
return null; |
| 745 |
|
} |
| 746 |
|
|
| 747 |
|
|
| 748 |
|
|
| 749 |
|
|
| 750 |
|
@param |
| 751 |
|
@param |
| 752 |
|
@return |
| 753 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 754 |
178 |
protected void insertAAGap(int pos, List<SequenceI> proteinSeqs)... |
| 755 |
|
{ |
| 756 |
178 |
aaWidth++; |
| 757 |
178 |
for (SequenceI seq : proteinSeqs) |
| 758 |
|
{ |
| 759 |
598 |
seq.insertCharAt(pos, gapChar); |
| 760 |
|
} |
| 761 |
|
|
| 762 |
178 |
checkCodonFrameWidth(); |
| 763 |
178 |
if (pos < aaWidth) |
| 764 |
|
{ |
| 765 |
178 |
aaWidth++; |
| 766 |
|
|
| 767 |
|
|
| 768 |
|
|
| 769 |
|
|
| 770 |
178 |
System.arraycopy(alignedCodons, pos, alignedCodons, pos + 1, |
| 771 |
|
alignedCodons.length - pos - 1); |
| 772 |
178 |
alignedCodons[pos] = null; |
| 773 |
|
} |
| 774 |
|
} |
| 775 |
|
|
| 776 |
|
|
| 777 |
|
|
| 778 |
|
|
| 779 |
|
|
| |
|
| 33.3% |
Uncovered Elements: 4 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 780 |
178 |
protected void checkCodonFrameWidth()... |
| 781 |
|
{ |
| 782 |
178 |
if (alignedCodons[alignedCodons.length - 1] != null) |
| 783 |
|
{ |
| 784 |
|
|
| 785 |
|
|
| 786 |
|
|
| 787 |
0 |
AlignedCodon[] c = new AlignedCodon[alignedCodons.length + 10]; |
| 788 |
0 |
System.arraycopy(alignedCodons, 0, c, 0, alignedCodons.length); |
| 789 |
0 |
alignedCodons = c; |
| 790 |
|
} |
| 791 |
|
} |
| 792 |
|
|
| 793 |
|
|
| 794 |
|
|
| 795 |
|
|
| 796 |
|
|
| 797 |
|
@param |
| 798 |
|
@param |
| 799 |
|
@param |
| 800 |
|
|
| |
|
| 25% |
Uncovered Elements: 3 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 801 |
217 |
private static void transferCodedFeatures(SequenceI dna, SequenceI pep,... |
| 802 |
|
MapList map) |
| 803 |
|
{ |
| 804 |
|
|
| 805 |
|
|
| 806 |
|
|
| 807 |
|
|
| 808 |
|
|
| 809 |
|
|
| 810 |
|
|
| 811 |
|
|
| 812 |
|
|
| 813 |
|
|
| 814 |
|
|
| 815 |
|
|
| 816 |
|
|
| 817 |
|
|
| 818 |
217 |
for (SequenceFeature sf : dna.getFeatures().getAllFeatures()) |
| 819 |
|
{ |
| 820 |
0 |
if (FeatureProperties.isCodingFeature(null, sf.getType())) |
| 821 |
|
{ |
| 822 |
|
|
| 823 |
|
{ |
| 824 |
|
|
| 825 |
|
} |
| 826 |
|
} |
| 827 |
|
} |
| 828 |
|
} |
| 829 |
|
|
| 830 |
|
|
| 831 |
|
|
| 832 |
|
|
| 833 |
|
|
| 834 |
|
@param |
| 835 |
|
@return |
| 836 |
|
|
| |
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 837 |
1 |
public AlignmentI reverseCdna(boolean complement)... |
| 838 |
|
{ |
| 839 |
1 |
int sSize = selection.size(); |
| 840 |
1 |
List<SequenceI> reversed = new ArrayList<>(); |
| 841 |
2 |
for (int s = 0; s < sSize; s++) |
| 842 |
|
{ |
| 843 |
1 |
SequenceI newseq = reverseSequence(selection.get(s).getName(), |
| 844 |
|
seqstring[s], complement); |
| 845 |
|
|
| 846 |
1 |
if (newseq != null) |
| 847 |
|
{ |
| 848 |
1 |
reversed.add(newseq); |
| 849 |
|
} |
| 850 |
|
} |
| 851 |
|
|
| 852 |
1 |
SequenceI[] newseqs = reversed.toArray(new SequenceI[reversed.size()]); |
| 853 |
1 |
AlignmentI al = new Alignment(newseqs); |
| 854 |
1 |
((Alignment) al).createDatasetAlignment(); |
| 855 |
1 |
return al; |
| 856 |
|
} |
| 857 |
|
|
| 858 |
|
|
| 859 |
|
|
| 860 |
|
|
| 861 |
|
|
| 862 |
|
|
| 863 |
|
|
| 864 |
|
@param |
| 865 |
|
@param |
| 866 |
|
@return |
| 867 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
| 868 |
3 |
public static SequenceI reverseSequence(String seqName, String sequence,... |
| 869 |
|
boolean complement) |
| 870 |
|
{ |
| 871 |
3 |
String newName = seqName + "|rev" + (complement ? "comp" : ""); |
| 872 |
3 |
char[] originalSequence = sequence.toCharArray(); |
| 873 |
3 |
int length = originalSequence.length; |
| 874 |
3 |
char[] reversedSequence = new char[length]; |
| 875 |
3 |
int bases = 0; |
| 876 |
63 |
for (int i = 0; i < length; i++) |
| 877 |
|
{ |
| 878 |
60 |
char c = complement ? getComplement(originalSequence[i]) |
| 879 |
|
: originalSequence[i]; |
| 880 |
60 |
reversedSequence[length - i - 1] = c; |
| 881 |
60 |
if (!Comparison.isGap(c)) |
| 882 |
|
{ |
| 883 |
45 |
bases++; |
| 884 |
|
} |
| 885 |
|
} |
| 886 |
3 |
SequenceI reversed = new Sequence(newName, reversedSequence, 1, bases); |
| 887 |
3 |
return reversed; |
| 888 |
|
} |
| 889 |
|
|
| 890 |
|
|
| 891 |
|
|
| 892 |
|
|
| 893 |
|
@see |
| 894 |
|
@param |
| 895 |
|
@return |
| 896 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 897 |
36 |
public static String reverseComplement(String s)... |
| 898 |
|
{ |
| 899 |
36 |
StringBuilder sb = new StringBuilder(s.length()); |
| 900 |
76 |
for (int i = s.length() - 1; i >= 0; i--) |
| 901 |
|
{ |
| 902 |
40 |
sb.append(Dna.getComplement(s.charAt(i))); |
| 903 |
|
} |
| 904 |
36 |
return sb.toString(); |
| 905 |
|
} |
| 906 |
|
|
| 907 |
|
|
| 908 |
|
|
| 909 |
|
|
| 910 |
|
|
| 911 |
|
|
| 912 |
|
@param |
| 913 |
|
@return |
| 914 |
|
|
| |
|
| 97.6% |
Uncovered Elements: 2 (85) |
Complexity: 30 |
Complexity Density: 0.35 |
|
| 915 |
106 |
public static char getComplement(char c)... |
| 916 |
|
{ |
| 917 |
106 |
char result = c; |
| 918 |
106 |
switch (c) |
| 919 |
|
{ |
| 920 |
7 |
case '-': |
| 921 |
0 |
case '.': |
| 922 |
0 |
case ' ': |
| 923 |
7 |
break; |
| 924 |
2 |
case 'a': |
| 925 |
2 |
result = 't'; |
| 926 |
2 |
break; |
| 927 |
13 |
case 'A': |
| 928 |
13 |
result = 'T'; |
| 929 |
13 |
break; |
| 930 |
3 |
case 'c': |
| 931 |
3 |
result = 'g'; |
| 932 |
3 |
break; |
| 933 |
22 |
case 'C': |
| 934 |
22 |
result = 'G'; |
| 935 |
22 |
break; |
| 936 |
3 |
case 'g': |
| 937 |
3 |
result = 'c'; |
| 938 |
3 |
break; |
| 939 |
17 |
case 'G': |
| 940 |
17 |
result = 'C'; |
| 941 |
17 |
break; |
| 942 |
3 |
case 't': |
| 943 |
3 |
result = 'a'; |
| 944 |
3 |
break; |
| 945 |
6 |
case 'T': |
| 946 |
6 |
result = 'A'; |
| 947 |
6 |
break; |
| 948 |
1 |
case 'u': |
| 949 |
1 |
result = 'a'; |
| 950 |
1 |
break; |
| 951 |
2 |
case 'U': |
| 952 |
2 |
result = 'A'; |
| 953 |
2 |
break; |
| 954 |
2 |
case 'r': |
| 955 |
2 |
result = 'y'; |
| 956 |
2 |
break; |
| 957 |
1 |
case 'R': |
| 958 |
1 |
result = 'Y'; |
| 959 |
1 |
break; |
| 960 |
1 |
case 'y': |
| 961 |
1 |
result = 'r'; |
| 962 |
1 |
break; |
| 963 |
2 |
case 'Y': |
| 964 |
2 |
result = 'R'; |
| 965 |
2 |
break; |
| 966 |
2 |
case 'k': |
| 967 |
2 |
result = 'm'; |
| 968 |
2 |
break; |
| 969 |
1 |
case 'K': |
| 970 |
1 |
result = 'M'; |
| 971 |
1 |
break; |
| 972 |
1 |
case 'm': |
| 973 |
1 |
result = 'k'; |
| 974 |
1 |
break; |
| 975 |
2 |
case 'M': |
| 976 |
2 |
result = 'K'; |
| 977 |
2 |
break; |
| 978 |
2 |
case 'b': |
| 979 |
2 |
result = 'v'; |
| 980 |
2 |
break; |
| 981 |
1 |
case 'B': |
| 982 |
1 |
result = 'V'; |
| 983 |
1 |
break; |
| 984 |
1 |
case 'v': |
| 985 |
1 |
result = 'b'; |
| 986 |
1 |
break; |
| 987 |
2 |
case 'V': |
| 988 |
2 |
result = 'B'; |
| 989 |
2 |
break; |
| 990 |
2 |
case 'd': |
| 991 |
2 |
result = 'h'; |
| 992 |
2 |
break; |
| 993 |
1 |
case 'D': |
| 994 |
1 |
result = 'H'; |
| 995 |
1 |
break; |
| 996 |
1 |
case 'h': |
| 997 |
1 |
result = 'd'; |
| 998 |
1 |
break; |
| 999 |
2 |
case 'H': |
| 1000 |
2 |
result = 'D'; |
| 1001 |
2 |
break; |
| 1002 |
|
} |
| 1003 |
|
|
| 1004 |
106 |
return result; |
| 1005 |
|
} |
| 1006 |
|
} |