X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fdatamodel%2FColumnSelection.java;h=b7bc40e357df4c798a545cf7c7a01b3d2a4f2976;hb=ad15cff29620f960119f80176f1fd443da9f6763;hp=775327ad428b7ea943a60ae2f6bd5aff58bc539d;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git
diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java
index 775327ad..b7bc40e 100644
--- a/src/jalview/datamodel/ColumnSelection.java
+++ b/src/jalview/datamodel/ColumnSelection.java
@@ -1,25 +1,34 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.datamodel;
-import java.util.*;
+import jalview.util.ShiftList;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField;
-import jalview.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Vector;
/**
* NOTE: Columns are zero based.
@@ -29,7 +38,7 @@ public class ColumnSelection
Vector selected = new Vector();
// Vector of int [] {startCol, endCol}
- Vector hiddenColumns;
+ Vector hiddenColumns;
/**
* Add a column to the selection
@@ -95,7 +104,7 @@ public class ColumnSelection
*
* @return Vector containing selected columns as Integers
*/
- public Vector getSelected()
+ public Vector getSelected()
{
return selected;
}
@@ -183,9 +192,9 @@ public class ColumnSelection
* @param left
* shift in edit (+ve for removal, or -ve for inserts)
*/
- public Vector compensateForEdit(int start, int change)
+ public List compensateForEdit(int start, int change)
{
- Vector deletedHiddenColumns = null;
+ List deletedHiddenColumns = null;
for (int i = 0; i < size(); i++)
{
int temp = columnAt(i);
@@ -198,14 +207,14 @@ public class ColumnSelection
if (hiddenColumns != null)
{
- deletedHiddenColumns = new Vector();
+ deletedHiddenColumns = new ArrayList();
int hSize = hiddenColumns.size();
for (int i = 0; i < hSize; i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.elementAt(i);
if (region[0] > start && start + change > region[1])
{
- deletedHiddenColumns.addElement(hiddenColumns.elementAt(i));
+ deletedHiddenColumns.add(region);
hiddenColumns.removeElementAt(i);
i--;
@@ -257,7 +266,7 @@ public class ColumnSelection
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.elementAt(i);
if (region[0] >= start)
{
region[0] -= change;
@@ -471,16 +480,13 @@ public class ColumnSelection
}
/**
- * This Method is used to return all the HiddenColumn regions less than the
- * given index.
- *
- * @param end
- * int
- * @return Vector
+ * This Method is used to return all the HiddenColumn regions
+ * @return empty list or List of hidden column intervals
*/
- public Vector getHiddenColumns()
+ public List getHiddenColumns()
{
- return hiddenColumns;
+ return hiddenColumns == null ? Arrays.asList(new int[]
+ {}) : hiddenColumns;
}
/**
@@ -497,7 +503,7 @@ public class ColumnSelection
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.elementAt(i);
if (result >= region[0])
{
result += region[1] - region[0] + 1;
@@ -525,7 +531,7 @@ public class ColumnSelection
int[] region;
do
{
- region = (int[]) hiddenColumns.elementAt(index++);
+ region = hiddenColumns.elementAt(index++);
if (hiddenColumn > region[1])
{
result -= region[1] + 1 - region[0];
@@ -551,7 +557,7 @@ public class ColumnSelection
int gaps = 0;
do
{
- int[] region = (int[]) hiddenColumns.elementAt(index);
+ int[] region = hiddenColumns.elementAt(index);
if (hiddenRegion == 0)
{
return region[0];
@@ -582,7 +588,7 @@ public class ColumnSelection
int index = 0;
do
{
- int[] region = (int[]) hiddenColumns.elementAt(index);
+ int[] region = hiddenColumns.elementAt(index);
if (alPos < region[0])
{
return region[0];
@@ -610,7 +616,7 @@ public class ColumnSelection
int index = hiddenColumns.size() - 1;
do
{
- int[] region = (int[]) hiddenColumns.elementAt(index);
+ int[] region = hiddenColumns.elementAt(index);
if (alPos > region[1])
{
return region[1];
@@ -628,7 +634,7 @@ public class ColumnSelection
{
while (size() > 0)
{
- int column = ((Integer) getSelected().firstElement()).intValue();
+ int column = getSelected().firstElement().intValue();
hideColumns(column);
}
@@ -646,7 +652,7 @@ public class ColumnSelection
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.elementAt(i);
if (start <= region[1] && end >= region[0])
{
hiddenColumns.removeElementAt(i);
@@ -713,7 +719,7 @@ public class ColumnSelection
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.elementAt(i);
for (int j = region[0]; j < region[1] + 1; j++)
{
addElement(j);
@@ -728,7 +734,7 @@ public class ColumnSelection
{
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.elementAt(i);
if (res == region[0])
{
for (int j = region[0]; j < region[1] + 1; j++)
@@ -749,14 +755,16 @@ public class ColumnSelection
public boolean isVisible(int column)
{
if (hiddenColumns != null)
+ {
for (int i = 0; i < hiddenColumns.size(); i++)
{
- int[] region = (int[]) hiddenColumns.elementAt(i);
+ int[] region = hiddenColumns.elementAt(i);
if (column >= region[0] && column <= region[1])
{
return false;
}
}
+ }
return true;
}
@@ -784,7 +792,7 @@ public class ColumnSelection
for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++)
{
int[] rh, cp;
- rh = (int[]) copy.hiddenColumns.elementAt(i);
+ rh = copy.hiddenColumns.elementAt(i);
if (rh != null)
{
cp = new int[rh.length];
@@ -813,7 +821,7 @@ public class ColumnSelection
for (i = 0; i < iSize; i++)
{
StringBuffer visibleSeq = new StringBuffer();
- Vector regions = getHiddenColumns();
+ List regions = getHiddenColumns();
int blockStart = start, blockEnd = end;
int[] region;
@@ -821,7 +829,7 @@ public class ColumnSelection
for (int j = 0; j < regions.size(); j++)
{
- region = (int[]) regions.elementAt(j);
+ region = regions.get(j);
hideStart = region[0];
hideEnd = region[1];
@@ -878,7 +886,7 @@ public class ColumnSelection
if (hiddenColumns != null && hiddenColumns.size() > 0)
{
Vector visiblecontigs = new Vector();
- Vector regions = getHiddenColumns();
+ List regions = getHiddenColumns();
int vstart = start;
int[] region;
@@ -886,7 +894,7 @@ public class ColumnSelection
for (int j = 0; vstart < end && j < regions.size(); j++)
{
- region = (int[]) regions.elementAt(j);
+ region = regions.get(j);
hideStart = region[0];
hideEnd = region[1];
@@ -964,14 +972,14 @@ public class ColumnSelection
// then mangle the alignmentAnnotation annotation array
Vector annels = new Vector();
Annotation[] els = null;
- Vector regions = getHiddenColumns();
+ List regions = getHiddenColumns();
int blockStart = start, blockEnd = end;
int[] region;
int hideStart, hideEnd, w = 0;
for (int j = 0; j < regions.size(); j++)
{
- region = (int[]) regions.elementAt(j);
+ region = regions.get(j);
hideStart = region[0];
hideEnd = region[1];
@@ -1015,7 +1023,9 @@ public class ColumnSelection
w += els.length;
}
if (w == 0)
+ {
return;
+ }
Enumeration e = annels.elements();
alignmentAnnotation.annotations = new Annotation[w];
w = 0;
@@ -1255,4 +1265,131 @@ public class ColumnSelection
}
}
}
+
+ /**
+ *
+ * @return true if there are columns marked
+ */
+ public boolean hasSelectedColumns()
+ {
+ return (selected != null && selected.size() > 0);
+ }
+
+ /**
+ *
+ * @return true if there are columns hidden
+ */
+ public boolean hasHiddenColumns()
+ {
+ return hiddenColumns != null && hiddenColumns.size() > 0;
+ }
+
+ /**
+ *
+ * @return true if there are more than one set of columns hidden
+ */
+ public boolean hasManyHiddenColumns()
+ {
+ return hiddenColumns != null && hiddenColumns.size() > 1;
+ }
+
+ /**
+ * mark the columns corresponding to gap characters as hidden in the column
+ * selection
+ *
+ * @param sr
+ */
+ public void hideInsertionsFor(SequenceI sr)
+ {
+ List inserts = sr.getInsertions();
+ for (int[] r : inserts)
+ {
+ hideColumns(r[0], r[1]);
+ }
+ }
+
+ public boolean filterAnnotations(Annotation[] annotations,
+ AnnotationFilterParameter filterParams)
+ {
+ this.revealAllHiddenColumns();
+ this.clear();
+ int count = 0;
+ do
+ {
+ if (annotations[count] != null)
+ {
+
+ boolean itemMatched = false;
+
+ if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
+ && annotations[count].value >= filterParams
+ .getThresholdValue())
+ {
+ itemMatched = true;
+ }
+ if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
+ && annotations[count].value <= filterParams
+ .getThresholdValue())
+ {
+ itemMatched = true;
+ }
+
+ if (filterParams.isFilterAlphaHelix()
+ && annotations[count].secondaryStructure == 'H')
+ {
+ itemMatched = true;
+ }
+
+ if (filterParams.isFilterBetaSheet()
+ && annotations[count].secondaryStructure == 'E')
+ {
+ itemMatched = true;
+ }
+
+ if (filterParams.isFilterTurn()
+ && annotations[count].secondaryStructure == 'S')
+ {
+ itemMatched = true;
+ }
+
+ String regexSearchString = filterParams.getRegexString();
+ if (regexSearchString != null
+ && !filterParams.getRegexSearchFields().isEmpty())
+ {
+ List fields = filterParams
+ .getRegexSearchFields();
+ try
+ {
+ if (fields.contains(SearchableAnnotationField.DISPLAY_STRING)
+ && annotations[count].displayCharacter
+ .matches(regexSearchString))
+ {
+ itemMatched = true;
+ }
+ } catch (java.util.regex.PatternSyntaxException pse)
+ {
+ if (annotations[count].displayCharacter
+ .equals(regexSearchString))
+ {
+ itemMatched = true;
+ }
+ }
+ if (fields.contains(SearchableAnnotationField.DESCRIPTION)
+ && annotations[count].description != null
+ && annotations[count].description
+ .matches(regexSearchString))
+ {
+ itemMatched = true;
+ }
+ }
+
+ if (itemMatched)
+ {
+ this.addElement(count);
+ }
+ }
+ count++;
+ } while (count < annotations.length);
+ return false;
+ }
}