X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FAlignmentSorter.java;h=b0373366166692a6032455e38775f935e24489fd;hb=f0bba4cb65260c4e7f79c30cd442123aeb1b312f;hp=f22835088f97981669dbf06dc0a40efe2e501004;hpb=9769c798c95dff2006438438706a3e715755cd57;p=jalview.git diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index f228350..b037336 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -25,6 +25,7 @@ import jalview.analysis.scoremodels.SimilarityParams; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; +import jalview.datamodel.BinaryNode; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; @@ -108,8 +109,9 @@ public class AlignmentSorter true); for (int i = 0; i < nSeq; i++) { - scores[i] = (float) PIDModel.computePID(align.getSequenceAt(i) - .getSequenceAsString(), refSeq, pidParams); + scores[i] = (float) PIDModel.computePID( + align.getSequenceAt(i).getSequenceAsString(), refSeq, + pidParams); seqs[i] = align.getSequenceAt(i); } @@ -142,8 +144,8 @@ public class AlignmentSorter } // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work - List asq; - synchronized (asq = align.getSequences()) + List asq = align.getSequences(); + synchronized (asq) { for (int i = 0; i < len; i++) { @@ -178,10 +180,10 @@ public class AlignmentSorter public static void setOrder(AlignmentI align, SequenceI[] seqs) { // NOTE: DO NOT USE align.setSequenceAt() here - it will NOT work - List algn; - synchronized (algn = align.getSequences()) + List algn = align.getSequences(); + synchronized (algn) { - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); for (int i = 0; i < seqs.length; i++) { @@ -278,7 +280,7 @@ public class AlignmentSorter { // MAINTAINS ORIGNAL SEQUENCE ORDER, // ORDERS BY GROUP SIZE - List groups = new ArrayList(); + List groups = new ArrayList<>(); if (groups.hashCode() != lastGroupHash) { @@ -314,7 +316,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++) { @@ -356,7 +358,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()]; @@ -415,7 +417,8 @@ public class AlignmentSorter } else { - setReverseOrder(align, vectorSubsetToArray(tmp, align.getSequences())); + setReverseOrder(align, + vectorSubsetToArray(tmp, align.getSequences())); } } @@ -434,7 +437,7 @@ public class AlignmentSorter { int nSeq = align.getHeight(); - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); tmp = _sortByTree(tree.getTopNode(), tmp, align.getSequences()); @@ -450,12 +453,9 @@ public class AlignmentSorter if (tmp.size() != nSeq) { - System.err - .println("WARNING: tmp.size()=" - + tmp.size() - + " != nseq=" - + nSeq - + " in getOrderByTree - tree contains sequences not in alignment"); + jalview.bin.Console.errPrintln("WARNING: tmp.size()=" + tmp.size() + " != nseq=" + + nSeq + + " in getOrderByTree - tree contains sequences not in alignment"); } } @@ -491,7 +491,8 @@ public class AlignmentSorter } else { - setReverseOrder(align, vectorSubsetToArray(tmp, align.getSequences())); + setReverseOrder(align, + vectorSubsetToArray(tmp, align.getSequences())); } } @@ -534,7 +535,7 @@ public class AlignmentSorter * * @return DOCUMENT ME! */ - private static List _sortByTree(SequenceNode node, + private static List _sortByTree(BinaryNode node, List tmp, List seqset) { if (node == null) @@ -542,12 +543,14 @@ public class AlignmentSorter return tmp; } - SequenceNode left = (SequenceNode) node.left(); - SequenceNode right = (SequenceNode) node.right(); + BinaryNode left = (BinaryNode) node.left(); + BinaryNode right = (BinaryNode) node.right(); if ((left == null) && (right == null)) { - if (!node.isPlaceholder() && (node.element() != null)) + if (!(node instanceof SequenceNode + && ((SequenceNode) node).isPlaceholder()) + && (node.element() != null)) { if (node.element() instanceof SequenceI) { @@ -586,7 +589,7 @@ public class AlignmentSorter for (int i = 0; i < alignment.length; i++) { - ids[i] = (new Float(alignment[i].getName().substring(8))) + ids[i] = (Float.valueOf(alignment[i].getName().substring(8))) .floatValue(); } @@ -681,27 +684,6 @@ public class AlignmentSorter public static String FEATURE_DENSITY = "density"; - private static boolean containsIgnoreCase(final String lab, - final List labs) - { - if (labs == null) - { - return true; - } - if (lab == null) - { - return false; - } - for (String label : labs) - { - if (lab.equalsIgnoreCase(label)) - { - return true; - } - } - return false; - } - /** * Sort sequences by feature score or density, optionally restricted by * feature types, feature groups, or alignment start/end positions. @@ -729,14 +711,15 @@ public class AlignmentSorter if (method != FEATURE_SCORE && method != FEATURE_LABEL && method != FEATURE_DENSITY) { - String msg = String - .format("Implementation Error - sortByFeature method must be either '%s' or '%s'", - FEATURE_SCORE, FEATURE_DENSITY); - System.err.println(msg); + String msg = String.format( + "Implementation Error - sortByFeature method must be either '%s' or '%s'", + FEATURE_SCORE, FEATURE_DENSITY); + jalview.bin.Console.errPrintln(msg); return; } - flipFeatureSortIfUnchanged(method, featureTypes, groups, startCol, endCol); + flipFeatureSortIfUnchanged(method, featureTypes, groups, startCol, + endCol); SequenceI[] seqs = alignment.getSequencesArray(); @@ -755,13 +738,10 @@ public class AlignmentSorter * get sequence residues overlapping column region * and features for residue positions and specified types */ - // TODO new method findPositions(startCol, endCol)? JAL-2544 - int startResidue = seqs[i].findPosition(startCol); - int endResidue = seqs[i].findPosition(endCol); - String[] types = featureTypes == null ? null : featureTypes - .toArray(new String[featureTypes.size()]); - List sfs = seqs[i].getFeatures().findFeatures( - startResidue, endResidue, types); + String[] types = featureTypes == null ? null + : featureTypes.toArray(new String[featureTypes.size()]); + List sfs = seqs[i].findFeatures(startCol + 1, + endCol + 1, types); seqScores[i] = 0; scores[i] = 0.0; @@ -772,19 +752,12 @@ public class AlignmentSorter SequenceFeature sf = it.next(); /* - * double-check feature overlaps columns (JAL-2544) - * (could avoid this with a findPositions(fromCol, toCol) method) - * findIndex returns base 1 column values, startCol/endCol are base 0 + * accept all features with null or empty group, otherwise + * check group is one of the currently visible groups */ - if (seqs[i].findIndex(sf.getBegin()) > endCol + 1 - || seqs[i].findIndex(sf.getEnd()) < startCol + 1) - { - it.remove(); - continue; - } - String featureGroup = sf.getFeatureGroup(); if (groups != null && featureGroup != null + && !"".equals(featureGroup) && !groups.contains(featureGroup)) { it.remove(); @@ -859,7 +832,7 @@ public class AlignmentSorter { // int nf = (feats[i] == null) ? 0 // : ((SequenceFeature[]) feats[i]).length; - // // System.err.println("Sorting on Score: seq " + + // // jalview.bin.Console.errPrintln("Sorting on Score: seq " + // seqs[i].getName() // + " Feats: " + nf + " Score : " + scores[i]); } @@ -874,7 +847,7 @@ public class AlignmentSorter int featureCount = feats[i] == null ? 0 : ((SequenceFeature[]) feats[i]).length; scores[i] = featureCount; - // System.err.println("Sorting on Density: seq "+seqs[i].getName()+ + // jalview.bin.Console.errPrintln("Sorting on Density: seq "+seqs[i].getName()+ // " Feats: "+featureCount+" Score : "+scores[i]); } QuickSort.sortByDouble(scores, seqs, sortByFeatureAscending);