| 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 java.util.ArrayList; |
| 24 |
|
import java.util.Collections; |
| 25 |
|
import java.util.Iterator; |
| 26 |
|
import java.util.List; |
| 27 |
|
|
| 28 |
|
import jalview.analysis.scoremodels.PIDModel; |
| 29 |
|
import jalview.analysis.scoremodels.SimilarityParams; |
| 30 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 31 |
|
import jalview.datamodel.AlignmentI; |
| 32 |
|
import jalview.datamodel.AlignmentOrder; |
| 33 |
|
import jalview.datamodel.BinaryNode; |
| 34 |
|
import jalview.datamodel.SequenceFeature; |
| 35 |
|
import jalview.datamodel.SequenceGroup; |
| 36 |
|
import jalview.datamodel.SequenceI; |
| 37 |
|
import jalview.datamodel.SequenceNode; |
| 38 |
|
import jalview.util.QuickSort; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| |
|
| 52.9% |
Uncovered Elements: 197 (418) |
Complexity: 104 |
Complexity Density: 0.42 |
|
| 55 |
|
public class AlignmentSorter |
| 56 |
|
{ |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
static boolean sortIdAscending = true; |
| 62 |
|
|
| 63 |
|
static boolean sortDescripionAscending = true; |
| 64 |
|
|
| 65 |
|
static int lastGroupHash = 0; |
| 66 |
|
|
| 67 |
|
static boolean sortGroupAscending = true; |
| 68 |
|
|
| 69 |
|
static AlignmentOrder lastOrder = null; |
| 70 |
|
|
| 71 |
|
static boolean sortOrderAscending = true; |
| 72 |
|
|
| 73 |
|
static TreeModel lastTree = null; |
| 74 |
|
|
| 75 |
|
static boolean sortTreeAscending = true; |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
private static String lastSortByAnnotation; |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
private static String sortByFeatureCriteria; |
| 87 |
|
|
| 88 |
|
private static boolean sortByFeatureAscending = true; |
| 89 |
|
|
| 90 |
|
private static boolean sortLengthAscending; |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
@param |
| 97 |
|
|
| 98 |
|
@param |
| 99 |
|
|
| 100 |
|
@param |
| 101 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 102 |
0 |
public static void sortByPID(AlignmentI align, SequenceI s)... |
| 103 |
|
{ |
| 104 |
0 |
int nSeq = align.getHeight(); |
| 105 |
|
|
| 106 |
0 |
float[] scores = new float[nSeq]; |
| 107 |
0 |
SequenceI[] seqs = new SequenceI[nSeq]; |
| 108 |
0 |
String refSeq = s.getSequenceAsString(); |
| 109 |
|
|
| 110 |
0 |
SimilarityParams pidParams = new SimilarityParams(true, true, true, |
| 111 |
|
true); |
| 112 |
0 |
for (int i = 0; i < nSeq; i++) |
| 113 |
|
{ |
| 114 |
0 |
scores[i] = (float) PIDModel.computePID( |
| 115 |
|
align.getSequenceAt(i).getSequenceAsString(), refSeq, |
| 116 |
|
pidParams); |
| 117 |
0 |
seqs[i] = align.getSequenceAt(i); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
0 |
QuickSort.sort(scores, seqs); |
| 121 |
|
|
| 122 |
0 |
setReverseOrder(align, seqs); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
@param |
| 129 |
|
|
| 130 |
|
@param |
| 131 |
|
|
| 132 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 133 |
2 |
private static void setReverseOrder(AlignmentI align, SequenceI[] seqs)... |
| 134 |
|
{ |
| 135 |
2 |
int nSeq = seqs.length; |
| 136 |
|
|
| 137 |
2 |
int len = 0; |
| 138 |
|
|
| 139 |
2 |
if ((nSeq % 2) == 0) |
| 140 |
|
{ |
| 141 |
0 |
len = nSeq / 2; |
| 142 |
|
} |
| 143 |
|
else |
| 144 |
|
{ |
| 145 |
2 |
len = (nSeq + 1) / 2; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
|
| 149 |
2 |
List<SequenceI> asq = align.getSequences(); |
| 150 |
2 |
synchronized (asq) |
| 151 |
|
{ |
| 152 |
36 |
for (int i = 0; i < len; i++) |
| 153 |
|
{ |
| 154 |
|
|
| 155 |
34 |
asq.set(i, seqs[nSeq - i - 1]); |
| 156 |
34 |
asq.set(nSeq - i - 1, seqs[i]); |
| 157 |
|
} |
| 158 |
|
} |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
|
| 162 |
|
|
| 163 |
|
|
| 164 |
|
@param |
| 165 |
|
|
| 166 |
|
@param |
| 167 |
|
|
| 168 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 169 |
3 |
private static void setOrder(AlignmentI align, List<SequenceI> tmp)... |
| 170 |
|
{ |
| 171 |
3 |
setOrder(align, vectorSubsetToArray(tmp, align.getSequences())); |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
@param |
| 178 |
|
|
| 179 |
|
@param |
| 180 |
|
|
| 181 |
|
|
| |
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 182 |
9 |
public static void setOrder(AlignmentI align, SequenceI[] seqs)... |
| 183 |
|
{ |
| 184 |
|
|
| 185 |
9 |
List<SequenceI> algn = align.getSequences(); |
| 186 |
9 |
synchronized (algn) |
| 187 |
|
{ |
| 188 |
9 |
List<SequenceI> tmp = new ArrayList<>(); |
| 189 |
|
|
| 190 |
125 |
for (int i = 0; i < seqs.length; i++) |
| 191 |
|
{ |
| 192 |
116 |
if (algn.contains(seqs[i])) |
| 193 |
|
{ |
| 194 |
116 |
tmp.add(seqs[i]); |
| 195 |
|
} |
| 196 |
|
} |
| 197 |
|
|
| 198 |
9 |
algn.clear(); |
| 199 |
|
|
| 200 |
125 |
for (int i = 0; i < tmp.size(); i++) |
| 201 |
|
{ |
| 202 |
116 |
algn.add(tmp.get(i)); |
| 203 |
|
} |
| 204 |
|
} |
| 205 |
|
} |
| 206 |
|
|
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
| 210 |
|
@param |
| 211 |
|
|
| 212 |
|
|
| |
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 213 |
0 |
public static void sortByID(AlignmentI align)... |
| 214 |
|
{ |
| 215 |
0 |
int nSeq = align.getHeight(); |
| 216 |
|
|
| 217 |
0 |
String[] ids = new String[nSeq]; |
| 218 |
0 |
SequenceI[] seqs = new SequenceI[nSeq]; |
| 219 |
|
|
| 220 |
0 |
for (int i = 0; i < nSeq; i++) |
| 221 |
|
{ |
| 222 |
0 |
ids[i] = align.getSequenceAt(i).getName(); |
| 223 |
0 |
seqs[i] = align.getSequenceAt(i); |
| 224 |
|
} |
| 225 |
|
|
| 226 |
0 |
QuickSort.sort(ids, seqs); |
| 227 |
|
|
| 228 |
0 |
if (sortIdAscending) |
| 229 |
|
{ |
| 230 |
0 |
setReverseOrder(align, seqs); |
| 231 |
|
} |
| 232 |
|
else |
| 233 |
|
{ |
| 234 |
0 |
setOrder(align, seqs); |
| 235 |
|
} |
| 236 |
|
|
| 237 |
0 |
sortIdAscending = !sortIdAscending; |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
|
|
| 243 |
|
@param |
| 244 |
|
|
| 245 |
|
|
| |
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 246 |
0 |
public static void sortByDescription(AlignmentI align)... |
| 247 |
|
{ |
| 248 |
0 |
int nSeq = align.getHeight(); |
| 249 |
|
|
| 250 |
0 |
String[] ids = new String[nSeq]; |
| 251 |
0 |
SequenceI[] seqs = new SequenceI[nSeq]; |
| 252 |
|
|
| 253 |
0 |
for (int i = 0; i < nSeq; i++) |
| 254 |
|
{ |
| 255 |
0 |
ids[i] = align.getSequenceAt(i).getDescription() != null |
| 256 |
|
? align.getSequenceAt(i).getDescription() |
| 257 |
|
: ""; |
| 258 |
0 |
seqs[i] = align.getSequenceAt(i); |
| 259 |
|
} |
| 260 |
|
|
| 261 |
0 |
QuickSort.sort(ids, seqs); |
| 262 |
|
|
| 263 |
0 |
if (sortIdAscending) |
| 264 |
|
{ |
| 265 |
0 |
setReverseOrder(align, seqs); |
| 266 |
|
} |
| 267 |
|
else |
| 268 |
|
{ |
| 269 |
0 |
setOrder(align, seqs); |
| 270 |
|
} |
| 271 |
|
|
| 272 |
0 |
sortDescripionAscending = !sortDescripionAscending; |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
|
| 276 |
|
|
| 277 |
|
|
| 278 |
|
@param |
| 279 |
|
|
| 280 |
|
|
| |
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 281 |
0 |
public static void sortByLength(AlignmentI align)... |
| 282 |
|
{ |
| 283 |
0 |
int nSeq = align.getHeight(); |
| 284 |
|
|
| 285 |
0 |
float[] length = new float[nSeq]; |
| 286 |
0 |
SequenceI[] seqs = new SequenceI[nSeq]; |
| 287 |
|
|
| 288 |
0 |
for (int i = 0; i < nSeq; i++) |
| 289 |
|
{ |
| 290 |
0 |
seqs[i] = align.getSequenceAt(i); |
| 291 |
0 |
length[i] = (seqs[i].getEnd() - seqs[i].getStart()); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
0 |
QuickSort.sort(length, seqs); |
| 295 |
|
|
| 296 |
0 |
if (sortLengthAscending) |
| 297 |
|
{ |
| 298 |
0 |
setReverseOrder(align, seqs); |
| 299 |
|
} |
| 300 |
|
else |
| 301 |
|
{ |
| 302 |
0 |
setOrder(align, seqs); |
| 303 |
|
} |
| 304 |
|
|
| 305 |
0 |
sortLengthAscending = !sortLengthAscending; |
| 306 |
|
} |
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
|
| 311 |
|
|
| 312 |
|
|
| 313 |
|
@param |
| 314 |
|
|
| 315 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 8 |
Complexity Density: 0.36 |
|
| 316 |
4 |
public static void sortByGroup(AlignmentI align)... |
| 317 |
|
{ |
| 318 |
|
|
| 319 |
|
|
| 320 |
4 |
List<SequenceGroup> groups = new ArrayList<>(); |
| 321 |
|
|
| 322 |
4 |
if (groups.hashCode() != lastGroupHash) |
| 323 |
|
{ |
| 324 |
1 |
sortGroupAscending = true; |
| 325 |
1 |
lastGroupHash = groups.hashCode(); |
| 326 |
|
} |
| 327 |
|
else |
| 328 |
|
{ |
| 329 |
3 |
sortGroupAscending = !sortGroupAscending; |
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
|
| 333 |
|
|
| 334 |
4 |
for (SequenceGroup sg : align.getGroups()) |
| 335 |
|
{ |
| 336 |
44 |
for (int j = 0; j < groups.size(); j++) |
| 337 |
|
{ |
| 338 |
32 |
SequenceGroup sg2 = groups.get(j); |
| 339 |
|
|
| 340 |
32 |
if (sg.getSize() > sg2.getSize()) |
| 341 |
|
{ |
| 342 |
8 |
groups.add(j, sg); |
| 343 |
|
|
| 344 |
8 |
break; |
| 345 |
|
} |
| 346 |
|
} |
| 347 |
|
|
| 348 |
20 |
if (!groups.contains(sg)) |
| 349 |
|
{ |
| 350 |
12 |
groups.add(sg); |
| 351 |
|
} |
| 352 |
|
} |
| 353 |
|
|
| 354 |
|
|
| 355 |
|
|
| 356 |
4 |
List<SequenceI> seqs = new ArrayList<>(); |
| 357 |
|
|
| 358 |
24 |
for (int i = 0; i < groups.size(); i++) |
| 359 |
|
{ |
| 360 |
20 |
SequenceGroup sg = groups.get(i); |
| 361 |
20 |
SequenceI[] orderedseqs = sg.getSequencesInOrder(align); |
| 362 |
|
|
| 363 |
152 |
for (int j = 0; j < orderedseqs.length; j++) |
| 364 |
|
{ |
| 365 |
132 |
seqs.add(orderedseqs[j]); |
| 366 |
|
} |
| 367 |
|
} |
| 368 |
|
|
| 369 |
4 |
if (sortGroupAscending) |
| 370 |
|
{ |
| 371 |
2 |
setOrder(align, seqs); |
| 372 |
|
} |
| 373 |
|
else |
| 374 |
|
{ |
| 375 |
2 |
setReverseOrder(align, |
| 376 |
|
vectorSubsetToArray(seqs, align.getSequences())); |
| 377 |
|
} |
| 378 |
|
} |
| 379 |
|
|
| 380 |
|
|
| 381 |
|
|
| 382 |
|
|
| 383 |
|
|
| 384 |
|
@param |
| 385 |
|
|
| 386 |
|
@param |
| 387 |
|
|
| 388 |
|
|
| 389 |
|
@return |
| 390 |
|
|
| |
|
| 88% |
Uncovered Elements: 3 (25) |
Complexity: 7 |
Complexity Density: 0.47 |
|
| 391 |
5 |
private static SequenceI[] vectorSubsetToArray(List<SequenceI> tmp,... |
| 392 |
|
List<SequenceI> mask) |
| 393 |
|
{ |
| 394 |
|
|
| 395 |
|
|
| 396 |
|
|
| 397 |
|
|
| 398 |
5 |
ArrayList<SequenceI> seqs = new ArrayList<>(); |
| 399 |
5 |
int i, idx; |
| 400 |
5 |
boolean[] tmask = new boolean[mask.size()]; |
| 401 |
|
|
| 402 |
152 |
for (i = 0; i < mask.size(); i++) |
| 403 |
|
{ |
| 404 |
147 |
tmask[i] = true; |
| 405 |
|
} |
| 406 |
|
|
| 407 |
152 |
for (i = 0; i < tmp.size(); i++) |
| 408 |
|
{ |
| 409 |
147 |
SequenceI sq = tmp.get(i); |
| 410 |
147 |
idx = mask.indexOf(sq); |
| 411 |
147 |
if (idx > -1 && tmask[idx]) |
| 412 |
|
{ |
| 413 |
147 |
tmask[idx] = false; |
| 414 |
147 |
seqs.add(sq); |
| 415 |
|
} |
| 416 |
|
} |
| 417 |
|
|
| 418 |
152 |
for (i = 0; i < tmask.length; i++) |
| 419 |
|
{ |
| 420 |
147 |
if (tmask[i]) |
| 421 |
|
{ |
| 422 |
0 |
seqs.add(mask.get(i)); |
| 423 |
|
} |
| 424 |
|
} |
| 425 |
|
|
| 426 |
5 |
return seqs.toArray(new SequenceI[seqs.size()]); |
| 427 |
|
} |
| 428 |
|
|
| 429 |
|
|
| 430 |
|
|
| 431 |
|
|
| 432 |
|
@param |
| 433 |
|
|
| 434 |
|
@param |
| 435 |
|
|
| 436 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 437 |
0 |
public static void sortBy(AlignmentI align, AlignmentOrder order)... |
| 438 |
|
{ |
| 439 |
|
|
| 440 |
0 |
List<SequenceI> tmp = order.getOrder(); |
| 441 |
|
|
| 442 |
0 |
if (lastOrder == order) |
| 443 |
|
{ |
| 444 |
0 |
sortOrderAscending = !sortOrderAscending; |
| 445 |
|
} |
| 446 |
|
else |
| 447 |
|
{ |
| 448 |
0 |
sortOrderAscending = true; |
| 449 |
|
} |
| 450 |
|
|
| 451 |
0 |
if (sortOrderAscending) |
| 452 |
|
{ |
| 453 |
0 |
setOrder(align, tmp); |
| 454 |
|
} |
| 455 |
|
else |
| 456 |
|
{ |
| 457 |
0 |
setReverseOrder(align, |
| 458 |
|
vectorSubsetToArray(tmp, align.getSequences())); |
| 459 |
|
} |
| 460 |
|
} |
| 461 |
|
|
| 462 |
|
|
| 463 |
|
|
| 464 |
|
|
| 465 |
|
@param |
| 466 |
|
|
| 467 |
|
@param |
| 468 |
|
|
| 469 |
|
|
| 470 |
|
@return |
| 471 |
|
|
| |
|
| 40% |
Uncovered Elements: 9 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 472 |
1 |
private static List<SequenceI> getOrderByTree(AlignmentI align,... |
| 473 |
|
TreeModel tree) |
| 474 |
|
{ |
| 475 |
1 |
int nSeq = align.getHeight(); |
| 476 |
|
|
| 477 |
1 |
List<SequenceI> tmp = new ArrayList<>(); |
| 478 |
|
|
| 479 |
1 |
tmp = _sortByTree(tree.getTopNode(), tmp, align.getSequences()); |
| 480 |
|
|
| 481 |
1 |
if (tmp.size() != nSeq) |
| 482 |
|
{ |
| 483 |
|
|
| 484 |
|
|
| 485 |
|
|
| 486 |
0 |
if (tmp.size() != nSeq) |
| 487 |
|
{ |
| 488 |
0 |
addStrays(align, tmp); |
| 489 |
|
} |
| 490 |
|
|
| 491 |
0 |
if (tmp.size() != nSeq) |
| 492 |
|
{ |
| 493 |
0 |
jalview.bin.Console.errPrintln("WARNING: tmp.size()=" + tmp.size() |
| 494 |
|
+ " != nseq=" + nSeq |
| 495 |
|
+ " in getOrderByTree - tree contains sequences not in alignment"); |
| 496 |
|
} |
| 497 |
|
} |
| 498 |
|
|
| 499 |
1 |
return tmp; |
| 500 |
|
} |
| 501 |
|
|
| 502 |
|
|
| 503 |
|
|
| 504 |
|
|
| 505 |
|
@param |
| 506 |
|
|
| 507 |
|
@param |
| 508 |
|
|
| 509 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 4 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 510 |
1 |
public static void sortByTree(AlignmentI align, TreeModel tree)... |
| 511 |
|
{ |
| 512 |
1 |
List<SequenceI> tmp = getOrderByTree(align, tree); |
| 513 |
|
|
| 514 |
|
|
| 515 |
1 |
if (lastTree != tree) |
| 516 |
|
{ |
| 517 |
1 |
sortTreeAscending = true; |
| 518 |
1 |
lastTree = tree; |
| 519 |
|
} |
| 520 |
|
else |
| 521 |
|
{ |
| 522 |
0 |
sortTreeAscending = !sortTreeAscending; |
| 523 |
|
} |
| 524 |
|
|
| 525 |
1 |
if (sortTreeAscending) |
| 526 |
|
{ |
| 527 |
1 |
setOrder(align, tmp); |
| 528 |
|
} |
| 529 |
|
else |
| 530 |
|
{ |
| 531 |
0 |
setReverseOrder(align, |
| 532 |
|
vectorSubsetToArray(tmp, align.getSequences())); |
| 533 |
|
} |
| 534 |
|
} |
| 535 |
|
|
| 536 |
|
|
| 537 |
|
|
| 538 |
|
|
| 539 |
|
@param |
| 540 |
|
|
| 541 |
|
@param |
| 542 |
|
|
| 543 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 544 |
0 |
private static void addStrays(AlignmentI align, List<SequenceI> tmp)... |
| 545 |
|
{ |
| 546 |
0 |
int nSeq = align.getHeight(); |
| 547 |
|
|
| 548 |
0 |
for (int i = 0; i < nSeq; i++) |
| 549 |
|
{ |
| 550 |
0 |
if (!tmp.contains(align.getSequenceAt(i))) |
| 551 |
|
{ |
| 552 |
0 |
tmp.add(align.getSequenceAt(i)); |
| 553 |
|
} |
| 554 |
|
} |
| 555 |
|
|
| 556 |
0 |
if (nSeq != tmp.size()) |
| 557 |
|
{ |
| 558 |
0 |
System.err |
| 559 |
|
.println("ERROR: Size still not right even after addStrays"); |
| 560 |
|
} |
| 561 |
|
} |
| 562 |
|
|
| 563 |
|
|
| 564 |
|
|
| 565 |
|
|
| 566 |
|
@param |
| 567 |
|
|
| 568 |
|
@param |
| 569 |
|
|
| 570 |
|
@param |
| 571 |
|
|
| 572 |
|
|
| 573 |
|
@return |
| 574 |
|
|
| |
|
| 78.3% |
Uncovered Elements: 5 (23) |
Complexity: 9 |
Complexity Density: 0.69 |
|
| 575 |
29 |
private static List<SequenceI> _sortByTree(BinaryNode node,... |
| 576 |
|
List<SequenceI> tmp, List<SequenceI> seqset) |
| 577 |
|
{ |
| 578 |
29 |
if (node == null) |
| 579 |
|
{ |
| 580 |
0 |
return tmp; |
| 581 |
|
} |
| 582 |
|
|
| 583 |
29 |
BinaryNode left = node.left(); |
| 584 |
29 |
BinaryNode right = node.right(); |
| 585 |
|
|
| 586 |
29 |
if ((left == null) && (right == null)) |
| 587 |
|
{ |
| 588 |
15 |
if (!(node instanceof SequenceNode |
| 589 |
|
&& ((SequenceNode) node).isPlaceholder()) |
| 590 |
|
&& (node.element() != null)) |
| 591 |
|
{ |
| 592 |
15 |
if (node.element() instanceof SequenceI) |
| 593 |
|
{ |
| 594 |
15 |
if (!tmp.contains(node.element())) |
| 595 |
|
|
| 596 |
|
|
| 597 |
|
{ |
| 598 |
15 |
tmp.add((SequenceI) node.element()); |
| 599 |
|
} |
| 600 |
|
} |
| 601 |
|
} |
| 602 |
|
|
| 603 |
15 |
return tmp; |
| 604 |
|
} |
| 605 |
|
else |
| 606 |
|
{ |
| 607 |
14 |
_sortByTree(left, tmp, seqset); |
| 608 |
14 |
_sortByTree(right, tmp, seqset); |
| 609 |
|
} |
| 610 |
|
|
| 611 |
14 |
return tmp; |
| 612 |
|
} |
| 613 |
|
|
| 614 |
|
|
| 615 |
|
|
| 616 |
|
|
| 617 |
|
|
| 618 |
|
|
| 619 |
|
|
| 620 |
|
|
| 621 |
|
|
| 622 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 623 |
0 |
public static void recoverOrder(SequenceI[] alignment)... |
| 624 |
|
{ |
| 625 |
0 |
float[] ids = new float[alignment.length]; |
| 626 |
|
|
| 627 |
0 |
for (int i = 0; i < alignment.length; i++) |
| 628 |
|
{ |
| 629 |
0 |
ids[i] = (Float.valueOf(alignment[i].getName().substring(8))) |
| 630 |
|
.floatValue(); |
| 631 |
|
} |
| 632 |
|
|
| 633 |
0 |
jalview.util.QuickSort.sort(ids, alignment); |
| 634 |
|
} |
| 635 |
|
|
| 636 |
|
|
| 637 |
|
|
| 638 |
|
|
| 639 |
|
|
| 640 |
|
@param |
| 641 |
|
|
| 642 |
|
|
| 643 |
|
@param |
| 644 |
|
|
| 645 |
|
|
| |
|
| 0% |
Uncovered Elements: 49 (49) |
Complexity: 11 |
Complexity Density: 0.38 |
|
| 646 |
0 |
public static void sortByAnnotationScore(String scoreLabel,... |
| 647 |
|
AlignmentI alignment) |
| 648 |
|
{ |
| 649 |
0 |
SequenceI[] seqs = alignment.getSequencesArray(); |
| 650 |
0 |
boolean[] hasScore = new boolean[seqs.length]; |
| 651 |
|
|
| 652 |
0 |
int hasScores = 0; |
| 653 |
0 |
double[] scores = new double[seqs.length]; |
| 654 |
0 |
double min = 0, max = 0; |
| 655 |
0 |
for (int i = 0; i < seqs.length; i++) |
| 656 |
|
{ |
| 657 |
0 |
AlignmentAnnotation[] scoreAnn = seqs[i].getAnnotation(scoreLabel); |
| 658 |
0 |
if (scoreAnn != null) |
| 659 |
|
{ |
| 660 |
0 |
hasScores++; |
| 661 |
0 |
hasScore[i] = true; |
| 662 |
0 |
scores[i] = scoreAnn[0].getScore(); |
| 663 |
|
|
| 664 |
0 |
if (hasScores == 1) |
| 665 |
|
{ |
| 666 |
0 |
max = min = scores[i]; |
| 667 |
|
} |
| 668 |
|
else |
| 669 |
|
{ |
| 670 |
0 |
if (max < scores[i]) |
| 671 |
|
{ |
| 672 |
0 |
max = scores[i]; |
| 673 |
|
} |
| 674 |
0 |
if (min > scores[i]) |
| 675 |
|
{ |
| 676 |
0 |
min = scores[i]; |
| 677 |
|
} |
| 678 |
|
} |
| 679 |
|
} |
| 680 |
|
else |
| 681 |
|
{ |
| 682 |
0 |
hasScore[i] = false; |
| 683 |
|
} |
| 684 |
|
} |
| 685 |
0 |
if (hasScores == 0) |
| 686 |
|
{ |
| 687 |
0 |
return; |
| 688 |
|
} |
| 689 |
0 |
if (hasScores < seqs.length) |
| 690 |
|
{ |
| 691 |
0 |
for (int i = 0; i < seqs.length; i++) |
| 692 |
|
{ |
| 693 |
0 |
if (!hasScore[i]) |
| 694 |
|
{ |
| 695 |
0 |
scores[i] = (max + i + 1.0); |
| 696 |
|
} |
| 697 |
|
} |
| 698 |
|
} |
| 699 |
|
|
| 700 |
0 |
jalview.util.QuickSort.sort(scores, seqs); |
| 701 |
0 |
if (lastSortByAnnotation != scoreLabel) |
| 702 |
|
{ |
| 703 |
0 |
lastSortByAnnotation = scoreLabel; |
| 704 |
0 |
setOrder(alignment, seqs); |
| 705 |
|
} |
| 706 |
|
else |
| 707 |
|
{ |
| 708 |
0 |
setReverseOrder(alignment, seqs); |
| 709 |
|
} |
| 710 |
|
} |
| 711 |
|
|
| 712 |
|
|
| 713 |
|
|
| 714 |
|
|
| 715 |
|
|
| 716 |
|
|
| 717 |
|
|
| 718 |
|
public static String FEATURE_SCORE = "average_score"; |
| 719 |
|
|
| 720 |
|
public static String FEATURE_LABEL = "text"; |
| 721 |
|
|
| 722 |
|
public static String FEATURE_DENSITY = "density"; |
| 723 |
|
|
| 724 |
|
|
| 725 |
|
|
| 726 |
|
|
| 727 |
|
|
| 728 |
|
|
| 729 |
|
|
| 730 |
|
|
| 731 |
|
@param |
| 732 |
|
|
| 733 |
|
@param |
| 734 |
|
|
| 735 |
|
@param |
| 736 |
|
|
| 737 |
|
@param |
| 738 |
|
|
| 739 |
|
@param |
| 740 |
|
|
| 741 |
|
@param |
| 742 |
|
|
| 743 |
|
|
| |
|
| 72.8% |
Uncovered Elements: 28 (103) |
Complexity: 28 |
Complexity Density: 0.46 |
|
| 744 |
6 |
public static void sortByFeature(List<String> featureTypes,... |
| 745 |
|
List<String> groups, final int startCol, final int endCol, |
| 746 |
|
AlignmentI alignment, String method) |
| 747 |
|
{ |
| 748 |
6 |
if (method != FEATURE_SCORE && method != FEATURE_LABEL |
| 749 |
|
&& method != FEATURE_DENSITY) |
| 750 |
|
{ |
| 751 |
0 |
String msg = String.format( |
| 752 |
|
"Implementation Error - sortByFeature method must be either '%s' or '%s'", |
| 753 |
|
FEATURE_SCORE, FEATURE_DENSITY); |
| 754 |
0 |
jalview.bin.Console.errPrintln(msg); |
| 755 |
0 |
return; |
| 756 |
|
} |
| 757 |
|
|
| 758 |
6 |
flipFeatureSortIfUnchanged(method, featureTypes, groups, startCol, |
| 759 |
|
endCol); |
| 760 |
|
|
| 761 |
6 |
SequenceI[] seqs = alignment.getSequencesArray(); |
| 762 |
|
|
| 763 |
6 |
boolean[] hasScore = new boolean[seqs.length]; |
| 764 |
|
|
| 765 |
6 |
int hasScores = 0; |
| 766 |
6 |
double[] scores = new double[seqs.length]; |
| 767 |
6 |
int[] seqScores = new int[seqs.length]; |
| 768 |
6 |
Object[][] feats = new Object[seqs.length][]; |
| 769 |
6 |
double min = 0d; |
| 770 |
6 |
double max = 0d; |
| 771 |
|
|
| 772 |
30 |
for (int i = 0; i < seqs.length; i++) |
| 773 |
|
{ |
| 774 |
|
|
| 775 |
|
|
| 776 |
|
|
| 777 |
|
|
| 778 |
24 |
String[] types = featureTypes == null ? null |
| 779 |
|
: featureTypes.toArray(new String[featureTypes.size()]); |
| 780 |
24 |
List<SequenceFeature> sfs = seqs[i].findFeatures(startCol + 1, |
| 781 |
|
endCol + 1, types); |
| 782 |
|
|
| 783 |
24 |
seqScores[i] = 0; |
| 784 |
24 |
scores[i] = 0.0; |
| 785 |
|
|
| 786 |
24 |
Iterator<SequenceFeature> it = sfs.listIterator(); |
| 787 |
52 |
while (it.hasNext()) |
| 788 |
|
{ |
| 789 |
28 |
SequenceFeature sf = it.next(); |
| 790 |
|
|
| 791 |
|
|
| 792 |
|
|
| 793 |
|
|
| 794 |
|
|
| 795 |
28 |
String featureGroup = sf.getFeatureGroup(); |
| 796 |
28 |
if (groups != null && featureGroup != null |
| 797 |
|
&& !"".equals(featureGroup) |
| 798 |
|
&& !groups.contains(featureGroup)) |
| 799 |
|
{ |
| 800 |
1 |
it.remove(); |
| 801 |
|
} |
| 802 |
|
else |
| 803 |
|
{ |
| 804 |
27 |
float score = sf.getScore(); |
| 805 |
27 |
if (FEATURE_SCORE.equals(method) && !Float.isNaN(score)) |
| 806 |
|
{ |
| 807 |
21 |
if (seqScores[i] == 0) |
| 808 |
|
{ |
| 809 |
15 |
hasScores++; |
| 810 |
|
} |
| 811 |
21 |
seqScores[i]++; |
| 812 |
21 |
hasScore[i] = true; |
| 813 |
21 |
scores[i] += score; |
| 814 |
|
|
| 815 |
|
} |
| 816 |
|
} |
| 817 |
|
} |
| 818 |
|
|
| 819 |
24 |
feats[i] = sfs.toArray(new SequenceFeature[sfs.size()]); |
| 820 |
24 |
if (!sfs.isEmpty()) |
| 821 |
|
{ |
| 822 |
18 |
if (method == FEATURE_LABEL) |
| 823 |
|
{ |
| 824 |
|
|
| 825 |
0 |
String[] labs = new String[sfs.size()]; |
| 826 |
0 |
for (int l = 0; l < sfs.size(); l++) |
| 827 |
|
{ |
| 828 |
0 |
SequenceFeature sf = sfs.get(l); |
| 829 |
0 |
String description = sf.getDescription(); |
| 830 |
0 |
labs[l] = (description != null ? description : sf.getType()); |
| 831 |
|
} |
| 832 |
0 |
QuickSort.sort(labs, feats[i]); |
| 833 |
|
} |
| 834 |
|
} |
| 835 |
24 |
if (hasScore[i]) |
| 836 |
|
{ |
| 837 |
|
|
| 838 |
15 |
scores[i] /= seqScores[i]; |
| 839 |
|
|
| 840 |
15 |
if (hasScores == 1) |
| 841 |
|
{ |
| 842 |
5 |
min = scores[i]; |
| 843 |
5 |
max = min; |
| 844 |
|
} |
| 845 |
|
else |
| 846 |
|
{ |
| 847 |
10 |
max = Math.max(max, scores[i]); |
| 848 |
10 |
min = Math.min(min, scores[i]); |
| 849 |
|
} |
| 850 |
|
} |
| 851 |
|
} |
| 852 |
|
|
| 853 |
6 |
if (FEATURE_SCORE.equals(method)) |
| 854 |
|
{ |
| 855 |
6 |
if (hasScores == 0) |
| 856 |
|
{ |
| 857 |
1 |
return; |
| 858 |
|
} |
| 859 |
|
|
| 860 |
5 |
if (hasScores < seqs.length) |
| 861 |
|
{ |
| 862 |
25 |
for (int i = 0; i < seqs.length; i++) |
| 863 |
|
{ |
| 864 |
20 |
if (!hasScore[i]) |
| 865 |
|
{ |
| 866 |
5 |
scores[i] = (max + 1 + i); |
| 867 |
|
} |
| 868 |
|
else |
| 869 |
|
{ |
| 870 |
|
|
| 871 |
|
|
| 872 |
|
|
| 873 |
|
|
| 874 |
|
|
| 875 |
|
} |
| 876 |
|
} |
| 877 |
|
} |
| 878 |
5 |
QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending); |
| 879 |
|
} |
| 880 |
0 |
else if (FEATURE_DENSITY.equals(method)) |
| 881 |
|
{ |
| 882 |
0 |
for (int i = 0; i < seqs.length; i++) |
| 883 |
|
{ |
| 884 |
0 |
int featureCount = feats[i] == null ? 0 |
| 885 |
|
: ((SequenceFeature[]) feats[i]).length; |
| 886 |
0 |
scores[i] = featureCount; |
| 887 |
|
|
| 888 |
|
|
| 889 |
|
|
| 890 |
|
} |
| 891 |
0 |
QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending); |
| 892 |
|
} |
| 893 |
|
|
| 894 |
5 |
setOrder(alignment, seqs); |
| 895 |
|
} |
| 896 |
|
|
| 897 |
|
|
| 898 |
|
|
| 899 |
|
|
| 900 |
|
|
| 901 |
|
@param |
| 902 |
|
@param |
| 903 |
|
@param |
| 904 |
|
@param |
| 905 |
|
@param |
| 906 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 907 |
6 |
protected static void flipFeatureSortIfUnchanged(String method,... |
| 908 |
|
List<String> featureTypes, List<String> groups, |
| 909 |
|
final int startCol, final int endCol) |
| 910 |
|
{ |
| 911 |
6 |
StringBuilder sb = new StringBuilder(64); |
| 912 |
6 |
sb.append(startCol).append(method).append(endCol); |
| 913 |
6 |
if (featureTypes != null) |
| 914 |
|
{ |
| 915 |
2 |
Collections.sort(featureTypes); |
| 916 |
2 |
sb.append(featureTypes.toString()); |
| 917 |
|
} |
| 918 |
6 |
if (groups != null) |
| 919 |
|
{ |
| 920 |
1 |
Collections.sort(groups); |
| 921 |
1 |
sb.append(groups.toString()); |
| 922 |
|
} |
| 923 |
6 |
String scoreCriteria = sb.toString(); |
| 924 |
|
|
| 925 |
|
|
| 926 |
|
|
| 927 |
|
|
| 928 |
6 |
if (sortByFeatureCriteria == null |
| 929 |
|
|| !scoreCriteria.equals(sortByFeatureCriteria)) |
| 930 |
|
{ |
| 931 |
4 |
sortByFeatureAscending = true; |
| 932 |
|
} |
| 933 |
|
else |
| 934 |
|
{ |
| 935 |
2 |
sortByFeatureAscending = !sortByFeatureAscending; |
| 936 |
|
} |
| 937 |
6 |
sortByFeatureCriteria = scoreCriteria; |
| 938 |
|
} |
| 939 |
|
|
| 940 |
|
} |