X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=b427739ca3fc776c60e42ea6bfcf4549261092a1;hb=HEAD;hp=3ccaab869730a770f4463eee8cb7242f136b43c1;hpb=6f04e0a80f3c3ba8087a1ad316debd395d0a4db0;p=jalview.git diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 3ccaab8..b427739 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -20,15 +20,15 @@ */ package jalview.datamodel; -import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; -import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField; - import java.util.ArrayList; import java.util.BitSet; import java.util.Collections; import java.util.List; import java.util.regex.PatternSyntaxException; +import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; +import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField; + /** * Data class holding the selected columns and hidden column ranges for a view. * Ranges are base 1. @@ -106,7 +106,7 @@ public class ColumnSelection void remove(int col) { - Integer colInt = new Integer(col); + Integer colInt = Integer.valueOf(col); if (selected.get(col)) { @@ -204,7 +204,7 @@ public class ColumnSelection // clear shifted bits and update List of selected columns selected.clear(temp); mask.set(temp - change); - order.set(i, new Integer(temp - change)); + order.set(i, Integer.valueOf(temp - change)); } } // lastly update the bitfield all at once @@ -278,6 +278,27 @@ public class ColumnSelection } /** + * add a series of start,end (inclusive) ranges to the column selection + * + * @param rng + * [start_0, end_0, start_1, end_1, ... ] + * @param baseOne + * - when true, ranges are base 1 and will be mapped to base 0 + */ + public void addRangeOfElements(int[] rng, boolean baseOne) + { + int base = baseOne ? -1 : 0; + for (int c = 0; c < rng.length; c += 2) + { + for (int p = rng[c]; p <= rng[c + 1]; p++) + { + selection.add(base + p); + } + } + + } + + /** * clears column selection */ public void clear() @@ -309,7 +330,7 @@ public class ColumnSelection Integer colInt; for (int i = start; i < end; i++) { - colInt = new Integer(i); + colInt = Integer.valueOf(i); if (selection.contains(colInt)) { selection.remove(colInt); @@ -319,10 +340,12 @@ public class ColumnSelection /** * Returns a read-only view of the (possibly empty) list of selected columns + * (base 1) *

- * The list contains no duplicates but is not necessarily ordered. It also may - * include columns hidden from the current view. To modify (for example sort) - * the list, you should first make a copy. + * The list contains no duplicates but is not necessarily ordered. Columns are + * reported in alignment coordinates (base 1), so may also include columns + * hidden from the current view. To modify (for example sort) the list, you + * should first make a copy. *

* The list is not thread-safe: iterating over it could result in * ConcurrentModificationException if it is modified by another thread. @@ -354,6 +377,22 @@ public class ColumnSelection } /** + * + */ + public boolean intersects(int from, int to) + { + // TODO: do this in a more efficient bitwise way + for (int f = from; f <= to; f++) + { + if (selection.isSelected(f)) + { + return true; + } + } + return false; + } + + /** * Answers true if no columns are selected, else false */ public boolean isEmpty() @@ -543,12 +582,52 @@ public class ColumnSelection * @param filterParams * @return */ - public int filterAnnotations(Annotation[] annotations, + public int filterAnnotations(AlignmentAnnotation ann_row, AnnotationFilterParameter filterParams) { + Annotation[] annotations = ann_row.annotations; // JBPNote - this method needs to be refactored to become independent of // viewmodel package this.clear(); + + if (ann_row.graph == AlignmentAnnotation.CONTACT_MAP && (filterParams + .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD + || filterParams + .getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD)) + { + float tVal = filterParams.getThresholdValue(); + if (ann_row.sequenceRef != null) + { + // TODO - get ContactList from AlignmentView for non-seq-ref associatd + for (int column = 0; column < annotations.length; column++) + { + if (ann_row.annotations[column] == null) + { + continue; + } + + int cpos = ann_row.sequenceRef.findPosition(column) - 1; + ContactListI clist = ann_row.sequenceRef + .getContactListFor(ann_row, cpos); + for (int row = column + 8, rowEnd = clist + .getContactHeight(); row < rowEnd; row++) + { + if (filterParams + .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD + ? (clist.getContactAt(row) > tVal) + : (clist.getContactAt(row) < tVal)) + { + addElement(column); + break; + // int column_forrowpos = ann_row.sequenceRef.findIndex(row + 1); + // addElement(column_forrowpos); + } + } + } + } + return selection.size(); + } + int addedCount = 0; int column = 0; do @@ -556,6 +635,7 @@ public class ColumnSelection Annotation ann = annotations[column]; if (ann != null) { + float value = ann.value; boolean matched = false; /* @@ -564,14 +644,14 @@ public class ColumnSelection */ if (filterParams .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD - && ann.value > filterParams.getThresholdValue()) + && value > filterParams.getThresholdValue()) { matched = true; } if (!matched && filterParams .getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD - && ann.value < filterParams.getThresholdValue()) + && value < filterParams.getThresholdValue()) { matched = true; }