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