X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FAlignmentSorter.java;fp=src%2Fjalview%2Fanalysis%2FAlignmentSorter.java;h=2d05865da2584a1f705f2377104895464c02bd99;hb=933e28e48b4f3bf98851cedd99ef345d45bf25a3;hp=8473904e2a6356a4cc90b11858d5130fd41cbcb1;hpb=72404f561ccd190eab1990874f017bbe94bf9e10;p=jalview.git diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index 8473904..2d05865 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -86,6 +86,10 @@ public class AlignmentSorter private static boolean sortLengthAscending; + private static boolean sortEValueAscending; + + private static boolean sortBitScoreAscending; + /** * Sorts sequences in the alignment by Percentage Identity with the given * reference sequence, sorting the highest identity to the top @@ -182,7 +186,7 @@ public class AlignmentSorter List algn; synchronized (algn = align.getSequences()) { - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); for (int i = 0; i < seqs.length; i++) { @@ -268,6 +272,90 @@ public class AlignmentSorter } /** + * Sorts by sequence evalue. Currently moves all sequences without an evalue to + * the top of the alignment. + * + * @param align + * The alignment object to sort + */ + public static void sortByEValue(AlignmentI align) + { + int nSeq = align.getHeight(); + + double[] evalue = new double[nSeq]; + SequenceI[] seqs = new SequenceI[nSeq]; + + for (int i = 0; i < nSeq; i++) + { + seqs[i] = align.getSequenceAt(i); + AlignmentAnnotation[] ann = seqs[i].getAnnotation("Search Scores"); + if (ann != null) + { + evalue[i] = ann[0].getEValue(); + } + else + { + evalue[i] = -1; + } + } + + QuickSort.sort(evalue, seqs); + + if (sortEValueAscending) + { + setReverseOrder(align, seqs); + } + else + { + setOrder(align, seqs); + } + + sortEValueAscending = !sortEValueAscending; + } + + /** + * Sorts by sequence bit score. Currently moves all sequences without a bit + * score to the top of the alignment + * + * @param align + * The alignment object to sort + */ + public static void sortByBitScore(AlignmentI align) + { + int nSeq = align.getHeight(); + + double[] score = new double[nSeq]; + SequenceI[] seqs = new SequenceI[nSeq]; + + for (int i = 0; i < nSeq; i++) + { + seqs[i] = align.getSequenceAt(i); + AlignmentAnnotation[] ann = seqs[i].getAnnotation("Search Scores"); + if (ann != null) + { + score[i] = ann[0].getEValue(); + } + else + { + score[i] = -1; + } + } + + QuickSort.sort(score, seqs); + + if (sortBitScoreAscending) + { + setReverseOrder(align, seqs); + } + else + { + setOrder(align, seqs); + } + + sortBitScoreAscending = !sortBitScoreAscending; + } + + /** * Sorts the alignment by size of group.
* Maintains the order of sequences in each group by order in given alignment * object. @@ -279,7 +367,7 @@ public class AlignmentSorter { // MAINTAINS ORIGNAL SEQUENCE ORDER, // ORDERS BY GROUP SIZE - List groups = new ArrayList(); + List groups = new ArrayList<>(); if (groups.hashCode() != lastGroupHash) { @@ -315,7 +403,7 @@ public class AlignmentSorter // NOW ADD SEQUENCES MAINTAINING ALIGNMENT ORDER // ///////////////////////////////////////////// - List seqs = new ArrayList(); + List seqs = new ArrayList<>(); for (int i = 0; i < groups.size(); i++) { @@ -357,7 +445,7 @@ public class AlignmentSorter // tmp2 = tmp.retainAll(mask); // return tmp2.addAll(mask.removeAll(tmp2)) - ArrayList seqs = new ArrayList(); + ArrayList seqs = new ArrayList<>(); int i, idx; boolean[] tmask = new boolean[mask.size()]; @@ -436,7 +524,7 @@ public class AlignmentSorter { int nSeq = align.getHeight(); - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); tmp = _sortByTree(tree.getTopNode(), tmp, align.getSequences());