2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import jalview.util.Comparison;
24 import jalview.util.ShiftList;
25 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
26 import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField;
28 import java.util.ArrayList;
29 import java.util.BitSet;
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.Vector;
35 * Data class holding the selected columns and hidden column ranges for a view.
38 public class ColumnSelection
41 * A class to hold an efficient representation of selected columns
46 * list of selected columns (ordered by selection order, not column order)
48 private List<Integer> order = new ArrayList<Integer>();
51 * bitfield for column selection - allows quick lookup
53 private BitSet selected = new BitSet();
56 * adds a new column i to the selection - only if i is not already selected
60 public void add(int i)
64 order.add(Integer.valueOf(i));
75 public void remove(int col)
78 Integer colInt = new Integer(col);
80 if (selected.get(col))
82 // if this ever changes to List.remove(), ensure Integer not int
84 // as List.remove(int i) removes the i'th item which is wrong
90 public boolean contains(Integer colInt)
92 return selected.get(colInt);
95 public boolean isEmpty()
97 return order.isEmpty();
100 public List<Integer> getList()
111 * gets the column that was selected first, second or i'th
116 public int elementAt(int i)
121 protected boolean pruneColumnList(final List<int[]> shifts)
123 int s = 0, t = shifts.size();
124 int[] sr = shifts.get(s++);
125 boolean pruned = false;
126 int i = 0, j = order.size();
127 while (i < j && s <= t)
129 int c = order.get(i++).intValue();
132 if (sr[1] + sr[0] >= c)
133 { // sr[1] -ve means inseriton.
152 * shift every selected column at or above start by change
155 * - leftmost column to be shifted
159 public void compensateForEdits(int start, int change)
161 BitSet mask = new BitSet();
162 for (int i = 0; i < order.size(); i++)
164 int temp = order.get(i);
168 // clear shifted bits and update List of selected columns
169 selected.clear(temp);
170 mask.set(temp - change);
171 order.set(i, new Integer(temp - change));
174 // lastly update the bitfield all at once
178 public boolean isSelected(int column)
180 return selected.get(column);
183 public int getMaxColumn()
185 return selected.length() - 1;
188 public int getMinColumn()
190 return selected.get(0) ? 0 : selected.nextSetBit(0);
194 * @return a series of selection intervals along the range
196 public List<int[]> getRanges()
198 List<int[]> rlist = new ArrayList<int[]>();
199 if (selected.isEmpty())
203 int next = selected.nextSetBit(0), clear = -1;
206 clear = selected.nextClearBit(next);
207 rlist.add(new int[] { next, clear - 1 });
208 next = selected.nextSetBit(clear);
214 public int hashCode()
216 // TODO Auto-generated method stub
217 return selected.hashCode();
221 public boolean equals(Object obj)
223 if (obj instanceof IntList)
225 return ((IntList) obj).selected.equals(selected);
231 IntList selection = new IntList();
234 * list of hidden column [start, end] ranges; the list is maintained in
235 * ascending start column order
237 Vector<int[]> hiddenColumns;
240 * Add a column to the selection
245 public void addElement(int col)
251 * clears column selection
259 * Removes value 'col' from the selection (not the col'th item)
262 * index of column to be removed
264 public void removeElement(int col)
266 selection.remove(col);
270 * removes a range of columns from the selection
273 * int - first column in range to be removed
277 public void removeElements(int start, int end)
280 for (int i = start; i < end; i++)
282 colInt = new Integer(i);
283 if (selection.contains(colInt))
285 selection.remove(colInt);
291 * Returns a list of selected columns. The list contains no duplicates but is
292 * not necessarily ordered. It also may include columns hidden from the
295 public List<Integer> getSelected()
297 return selection.getList();
301 * @return list of int arrays containing start and end column position for
302 * runs of selected columns ordered from right to left.
304 public List<int[]> getSelectedRanges()
306 return selection.getRanges();
312 * index to search for in column selection
314 * @return true if col is selected
316 public boolean contains(int col)
318 return (col > -1) ? selection.isSelected(col) : false;
322 * Answers true if no columns are selected, else false
324 public boolean isEmpty()
326 return selection == null || selection.isEmpty();
330 * rightmost selected column
332 * @return rightmost column in alignment that is selected
336 if (selection.isEmpty())
340 return selection.getMaxColumn();
344 * Leftmost column in selection
346 * @return column index of leftmost column in selection
350 if (selection.isEmpty())
354 return selection.getMinColumn();
358 * propagate shift in alignment columns to column selection
363 * shift in edit (+ve for removal, or -ve for inserts)
365 public List<int[]> compensateForEdit(int start, int change)
367 List<int[]> deletedHiddenColumns = null;
368 selection.compensateForEdits(start, change);
370 if (hiddenColumns != null)
372 deletedHiddenColumns = new ArrayList<int[]>();
373 int hSize = hiddenColumns.size();
374 for (int i = 0; i < hSize; i++)
376 int[] region = hiddenColumns.elementAt(i);
377 if (region[0] > start && start + change > region[1])
379 deletedHiddenColumns.add(region);
381 hiddenColumns.removeElementAt(i);
387 if (region[0] > start)
400 this.revealHiddenColumns(0);
403 return deletedHiddenColumns;
407 * propagate shift in alignment columns to column selection special version of
408 * compensateForEdit - allowing for edits within hidden regions
413 * shift in edit (+ve for removal, or -ve for inserts)
415 private void compensateForDelEdits(int start, int change)
418 selection.compensateForEdits(start, change);
420 if (hiddenColumns != null)
422 for (int i = 0; i < hiddenColumns.size(); i++)
424 int[] region = hiddenColumns.elementAt(i);
425 if (region[0] >= start)
429 if (region[1] >= start)
433 if (region[1] < region[0])
435 hiddenColumns.removeElementAt(i--);
451 * Adjust hidden column boundaries based on a series of column additions or
452 * deletions in visible regions.
457 public ShiftList compensateForEdits(ShiftList shiftrecord)
459 if (shiftrecord != null)
461 final List<int[]> shifts = shiftrecord.getShifts();
462 if (shifts != null && shifts.size() > 0)
465 for (int i = 0, j = shifts.size(); i < j; i++)
467 int[] sh = shifts.get(i);
468 // compensateForEdit(shifted+sh[0], sh[1]);
469 compensateForDelEdits(shifted + sh[0], sh[1]);
473 return shiftrecord.getInverse();
479 * removes intersection of position,length ranges in deletions from the
480 * start,end regions marked in intervals.
486 private boolean pruneIntervalVector(final List<int[]> shifts,
487 Vector<int[]> intervals)
489 boolean pruned = false;
490 int i = 0, j = intervals.size() - 1, s = 0, t = shifts.size() - 1;
491 int hr[] = intervals.elementAt(i);
492 int sr[] = shifts.get(s);
493 while (i <= j && s <= t)
495 boolean trailinghn = hr[1] >= sr[0];
500 hr = intervals.elementAt(++i);
508 int endshift = sr[0] + sr[1]; // deletion ranges - -ve means an insert
509 if (endshift < hr[0] || endshift < sr[0])
510 { // leadinghc disjoint or not a deletion
513 sr = shifts.get(++s);
521 boolean leadinghn = hr[0] >= sr[0];
522 boolean leadinghc = hr[0] < endshift;
523 boolean trailinghc = hr[1] < endshift;
527 { // deleted hidden region.
528 intervals.removeElementAt(i);
533 hr = intervals.elementAt(i);
539 hr[0] = endshift; // clip c terminal region
540 leadinghn = !leadinghn;
556 // sr contained in hr
559 sr = shifts.get(++s);
569 return pruned; // true if any interval was removed or modified by
574 * remove any hiddenColumns or selected columns and shift remaining based on a
575 * series of position, range deletions.
579 public void pruneDeletions(ShiftList deletions)
581 if (deletions != null)
583 final List<int[]> shifts = deletions.getShifts();
584 if (shifts != null && shifts.size() > 0)
586 // delete any intervals intersecting.
587 if (hiddenColumns != null)
589 pruneIntervalVector(shifts, hiddenColumns);
590 if (hiddenColumns != null && hiddenColumns.size() == 0)
592 hiddenColumns = null;
595 if (selection != null && selection.size() > 0)
597 selection.pruneColumnList(shifts);
598 if (selection != null && selection.size() == 0)
603 // and shift the rest.
604 this.compensateForEdits(deletions);
610 * This Method is used to return all the HiddenColumn regions
612 * @return empty list or List of hidden column intervals
614 public List<int[]> getHiddenColumns()
616 return hiddenColumns == null ? Collections.<int[]> emptyList()
621 * Return absolute column index for a visible column index
624 * int column index in alignment view (count from zero)
625 * @return alignment column index for column
627 public int adjustForHiddenColumns(int column)
630 if (hiddenColumns != null)
632 for (int i = 0; i < hiddenColumns.size(); i++)
634 int[] region = hiddenColumns.elementAt(i);
635 if (result >= region[0])
637 result += region[1] - region[0] + 1;
645 * Use this method to find out where a column will appear in the visible
646 * alignment when hidden columns exist. If the column is not visible, then the
647 * left-most visible column will always be returned.
649 * @param hiddenColumn
653 public int findColumnPosition(int hiddenColumn)
655 int result = hiddenColumn;
656 if (hiddenColumns != null)
662 region = hiddenColumns.elementAt(index++);
663 if (hiddenColumn > region[1])
665 result -= region[1] + 1 - region[0];
667 } while ((hiddenColumn > region[1]) && (index < hiddenColumns.size()));
668 if (hiddenColumn > region[0] && hiddenColumn < region[1])
670 return region[0] + hiddenColumn - result;
673 return result; // return the shifted position after removing hidden columns.
677 * Use this method to determine where the next hiddenRegion starts
679 * @param hiddenRegion
680 * index of hidden region (counts from 0)
681 * @return column number in visible view
683 public int findHiddenRegionPosition(int hiddenRegion)
686 if (hiddenColumns != null)
692 int[] region = hiddenColumns.elementAt(index);
693 if (hiddenRegion == 0)
698 gaps += region[1] + 1 - region[0];
699 result = region[1] + 1;
701 } while (index <= hiddenRegion);
710 * THis method returns the rightmost limit of a region of an alignment with
711 * hidden columns. In otherwords, the next hidden column.
716 public int getHiddenBoundaryRight(int alPos)
718 if (hiddenColumns != null)
723 int[] region = hiddenColumns.elementAt(index);
724 if (alPos < region[0])
730 } while (index < hiddenColumns.size());
738 * This method returns the leftmost limit of a region of an alignment with
739 * hidden columns. In otherwords, the previous hidden column.
744 public int getHiddenBoundaryLeft(int alPos)
746 if (hiddenColumns != null)
748 int index = hiddenColumns.size() - 1;
751 int[] region = hiddenColumns.elementAt(index);
752 if (alPos > region[1])
758 } while (index > -1);
765 public void hideSelectedColumns()
767 synchronized (selection)
769 for (int[] selregions : selection.getRanges())
771 hideColumns(selregions[0], selregions[1]);
779 * Adds the specified column range to the hidden columns
784 public void hideColumns(int start, int end)
786 if (hiddenColumns == null)
788 hiddenColumns = new Vector<int[]>();
792 * traverse existing hidden ranges and insert / amend / append as
795 for (int i = 0; i < hiddenColumns.size(); i++)
797 int[] region = hiddenColumns.elementAt(i);
799 if (end < region[0] - 1)
802 * insert discontiguous preceding range
804 hiddenColumns.insertElementAt(new int[] { start, end }, i);
808 if (end <= region[1])
811 * new range overlaps existing, or is contiguous preceding it - adjust
814 region[0] = Math.min(region[0], start);
818 if (start <= region[1] + 1)
821 * new range overlaps existing, or is contiguous following it - adjust
822 * start and end columns
824 region[0] = Math.min(region[0], start);
825 region[1] = Math.max(region[1], end);
831 * remaining case is that the new range follows everything else
833 hiddenColumns.addElement(new int[] { start, end });
837 * Hides the specified column and any adjacent selected columns
842 public void hideColumns(int col)
845 * deselect column (whether selected or not!)
850 * find adjacent selected columns
852 int min = col - 1, max = col + 1;
853 while (contains(min))
859 while (contains(max))
866 * min, max are now the closest unselected columns
875 hideColumns(min, max);
879 * Unhides, and adds to the selection list, all hidden columns
881 public void revealAllHiddenColumns()
883 if (hiddenColumns != null)
885 for (int i = 0; i < hiddenColumns.size(); i++)
887 int[] region = hiddenColumns.elementAt(i);
888 for (int j = region[0]; j < region[1] + 1; j++)
895 hiddenColumns = null;
899 * Reveals, and marks as selected, the hidden column range with the given
904 public void revealHiddenColumns(int start)
906 for (int i = 0; i < hiddenColumns.size(); i++)
908 int[] region = hiddenColumns.elementAt(i);
909 if (start == region[0])
911 for (int j = region[0]; j < region[1] + 1; j++)
916 hiddenColumns.removeElement(region);
920 if (hiddenColumns.size() == 0)
922 hiddenColumns = null;
926 public boolean isVisible(int column)
928 if (hiddenColumns != null)
930 for (int[] region : hiddenColumns)
932 if (column >= region[0] && column <= region[1])
947 public ColumnSelection(ColumnSelection copy)
951 if (copy.selection != null)
953 selection = new IntList();
954 for (int i = 0, j = copy.selection.size(); i < j; i++)
956 selection.add(copy.selection.elementAt(i));
959 if (copy.hiddenColumns != null)
961 hiddenColumns = new Vector<int[]>(copy.hiddenColumns.size());
962 for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++)
965 rh = copy.hiddenColumns.elementAt(i);
968 cp = new int[rh.length];
969 System.arraycopy(rh, 0, cp, 0, rh.length);
970 hiddenColumns.addElement(cp);
980 public ColumnSelection()
984 public String[] getVisibleSequenceStrings(int start, int end,
987 int i, iSize = seqs.length;
988 String selection[] = new String[iSize];
989 if (hiddenColumns != null && hiddenColumns.size() > 0)
991 for (i = 0; i < iSize; i++)
993 StringBuffer visibleSeq = new StringBuffer();
994 List<int[]> regions = getHiddenColumns();
996 int blockStart = start, blockEnd = end;
998 int hideStart, hideEnd;
1000 for (int j = 0; j < regions.size(); j++)
1002 region = regions.get(j);
1003 hideStart = region[0];
1004 hideEnd = region[1];
1006 if (hideStart < start)
1011 blockStart = Math.min(blockStart, hideEnd + 1);
1012 blockEnd = Math.min(blockEnd, hideStart);
1014 if (blockStart > blockEnd)
1019 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
1021 blockStart = hideEnd + 1;
1025 if (end > blockStart)
1027 visibleSeq.append(seqs[i].getSequence(blockStart, end));
1030 selection[i] = visibleSeq.toString();
1035 for (i = 0; i < iSize; i++)
1037 selection[i] = seqs[i].getSequenceAsString(start, end);
1045 * return all visible segments between the given start and end boundaries
1048 * (first column inclusive from 0)
1050 * (last column - not inclusive)
1051 * @return int[] {i_start, i_end, ..} where intervals lie in
1052 * start<=i_start<=i_end<end
1054 public int[] getVisibleContigs(int start, int end)
1056 if (hiddenColumns != null && hiddenColumns.size() > 0)
1058 List<int[]> visiblecontigs = new ArrayList<int[]>();
1059 List<int[]> regions = getHiddenColumns();
1063 int hideStart, hideEnd;
1065 for (int j = 0; vstart < end && j < regions.size(); j++)
1067 region = regions.get(j);
1068 hideStart = region[0];
1069 hideEnd = region[1];
1071 if (hideEnd < vstart)
1075 if (hideStart > vstart)
1077 visiblecontigs.add(new int[] { vstart, hideStart - 1 });
1079 vstart = hideEnd + 1;
1084 visiblecontigs.add(new int[] { vstart, end - 1 });
1086 int[] vcontigs = new int[visiblecontigs.size() * 2];
1087 for (int i = 0, j = visiblecontigs.size(); i < j; i++)
1089 int[] vc = visiblecontigs.get(i);
1090 visiblecontigs.set(i, null);
1091 vcontigs[i * 2] = vc[0];
1092 vcontigs[i * 2 + 1] = vc[1];
1094 visiblecontigs.clear();
1099 return new int[] { start, end - 1 };
1104 * Locate the first and last position visible for this sequence. if seq isn't
1105 * visible then return the position of the left and right of the hidden
1106 * boundary region, and the corresponding alignment column indices for the
1107 * extent of the sequence
1110 * @return int[] { visible start, visible end, first seqpos, last seqpos,
1111 * alignment index for seq start, alignment index for seq end }
1113 public int[] locateVisibleBoundsOfSequence(SequenceI seq)
1115 int fpos=seq.getStart(),lpos= seq.getEnd();
1118 if (hiddenColumns == null || hiddenColumns.size() == 0)
1120 int ifpos = seq.findIndex(fpos) - 1, ilpos = seq.findIndex(lpos) - 1;
1121 return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos };
1124 // Simply walk along the sequence whilst watching for hidden column
1126 List<int[]> regions = getHiddenColumns();
1127 int spos = fpos, lastvispos = -1, rcount = 0, hideStart = seq
1128 .getLength(), hideEnd = -1;
1129 int visPrev = 0, visNext = 0, firstP = -1, lastP = -1;
1130 boolean foundStart = false;
1131 for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
1134 if (!Comparison.isGap(seq.getCharAt(p)))
1136 // keep track of first/last column
1137 // containing sequence data regardless of visibility
1143 // update hidden region start/end
1144 while (hideEnd < p && rcount < regions.size())
1146 int[] region = regions.get(rcount++);
1148 visNext += region[0] - visPrev;
1149 hideStart = region[0];
1150 hideEnd = region[1];
1154 hideStart = seq.getLength();
1156 // update visible boundary for sequence
1168 // look for next sequence position
1174 return new int[] { findColumnPosition(start),
1175 findColumnPosition(lastvispos), fpos, lpos, firstP, lastP };
1177 // otherwise, sequence was completely hidden
1178 return new int[] { visPrev, visNext, 0, 0, firstP, lastP };
1182 * delete any columns in alignmentAnnotation that are hidden (including
1183 * sequence associated annotation).
1185 * @param alignmentAnnotation
1187 public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)
1189 makeVisibleAnnotation(-1, -1, alignmentAnnotation);
1193 * delete any columns in alignmentAnnotation that are hidden (including
1194 * sequence associated annotation).
1197 * remove any annotation to the right of this column
1199 * remove any annotation to the left of this column
1200 * @param alignmentAnnotation
1201 * the annotation to operate on
1203 public void makeVisibleAnnotation(int start, int end,
1204 AlignmentAnnotation alignmentAnnotation)
1206 if (alignmentAnnotation.annotations == null)
1210 if (start == end && end == -1)
1213 end = alignmentAnnotation.annotations.length;
1215 if (hiddenColumns != null && hiddenColumns.size() > 0)
1217 // then mangle the alignmentAnnotation annotation array
1218 Vector<Annotation[]> annels = new Vector<Annotation[]>();
1219 Annotation[] els = null;
1220 List<int[]> regions = getHiddenColumns();
1221 int blockStart = start, blockEnd = end;
1223 int hideStart, hideEnd, w = 0;
1225 for (int j = 0; j < regions.size(); j++)
1227 region = regions.get(j);
1228 hideStart = region[0];
1229 hideEnd = region[1];
1231 if (hideStart < start)
1236 blockStart = Math.min(blockStart, hideEnd + 1);
1237 blockEnd = Math.min(blockEnd, hideStart);
1239 if (blockStart > blockEnd)
1244 annels.addElement(els = new Annotation[blockEnd - blockStart]);
1245 System.arraycopy(alignmentAnnotation.annotations, blockStart, els,
1248 blockStart = hideEnd + 1;
1252 if (end > blockStart)
1254 annels.addElement(els = new Annotation[end - blockStart + 1]);
1255 if ((els.length + blockStart) <= alignmentAnnotation.annotations.length)
1257 // copy just the visible segment of the annotation row
1258 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1259 els, 0, els.length);
1263 // copy to the end of the annotation row
1264 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1266 (alignmentAnnotation.annotations.length - blockStart));
1275 alignmentAnnotation.annotations = new Annotation[w];
1278 for (Annotation[] chnk : annels)
1280 System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
1287 alignmentAnnotation.restrict(start, end);
1292 * Invert the column selection from first to end-1. leaves hiddenColumns
1293 * untouched (and unselected)
1298 public void invertColumnSelection(int first, int width)
1300 boolean hasHidden = hiddenColumns != null && hiddenColumns.size() > 0;
1301 for (int i = first; i < width; i++)
1309 if (!hasHidden || isVisible(i))
1318 * add in any unselected columns from the given column selection, excluding
1319 * any that are hidden.
1323 public void addElementsFrom(ColumnSelection colsel)
1325 if (colsel != null && !colsel.isEmpty())
1327 for (Integer col : colsel.getSelected())
1329 if (hiddenColumns != null && isVisible(col.intValue()))
1338 * set the selected columns the given column selection, excluding any columns
1343 public void setElementsFrom(ColumnSelection colsel)
1345 selection = new IntList();
1346 if (colsel.selection != null && colsel.selection.size() > 0)
1348 if (hiddenColumns != null && hiddenColumns.size() > 0)
1350 // only select visible columns in this columns selection
1351 addElementsFrom(colsel);
1355 // add everything regardless
1356 for (Integer col : colsel.getSelected())
1365 * Add gaps into the sequences aligned to profileseq under the given
1370 * - alignment to have gaps inserted into it
1372 * - alignment view where sequence corresponding to profileseq is
1374 * @return new Column selection for new alignment view, with insertions into
1375 * profileseq marked as hidden.
1377 public static ColumnSelection propagateInsertions(SequenceI profileseq,
1378 AlignmentI al, AlignmentView input)
1382 // return propagateInsertions(profileseq, al, )
1383 char gc = al.getGapCharacter();
1384 Object[] alandcolsel = input.getAlignmentAndColumnSelection(gc);
1385 ColumnSelection nview = (ColumnSelection) alandcolsel[1];
1386 SequenceI origseq = ((SequenceI[]) alandcolsel[0])[profsqpos];
1387 nview.propagateInsertions(profileseq, al, origseq);
1394 * - sequence in al which corresponds to origseq
1396 * - alignment which is to have gaps inserted into it
1398 * - sequence corresponding to profileseq which defines gap map for
1401 public void propagateInsertions(SequenceI profileseq, AlignmentI al,
1404 char gc = al.getGapCharacter();
1405 // recover mapping between sequence's non-gap positions and positions
1407 pruneDeletions(ShiftList.parseMap(origseq.gapMap()));
1408 int[] viscontigs = getVisibleContigs(0, profileseq.getLength());
1411 // input.pruneDeletions(ShiftList.parseMap(((SequenceI[])
1412 // alandcolsel[0])[0].gapMap()))
1413 // add profile to visible contigs
1414 for (int v = 0; v < viscontigs.length; v += 2)
1416 if (viscontigs[v] > spos)
1418 StringBuffer sb = new StringBuffer();
1419 for (int s = 0, ns = viscontigs[v] - spos; s < ns; s++)
1423 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1425 SequenceI sqobj = al.getSequenceAt(s);
1426 if (sqobj != profileseq)
1428 String sq = al.getSequenceAt(s).getSequenceAsString();
1429 if (sq.length() <= spos + offset)
1432 int diff = spos + offset - sq.length() - 1;
1437 while ((diff = spos + offset - sq.length() - 1) > 0)
1440 // + ((diff >= sb.length()) ? sb.toString() : sb
1441 // .substring(0, diff));
1442 if (diff >= sb.length())
1444 sq += sb.toString();
1448 char[] buf = new char[diff];
1449 sb.getChars(0, diff, buf, 0);
1450 sq += buf.toString();
1454 sq += sb.toString();
1458 al.getSequenceAt(s).setSequence(
1459 sq.substring(0, spos + offset) + sb.toString()
1460 + sq.substring(spos + offset));
1464 // offset+=sb.length();
1466 spos = viscontigs[v + 1] + 1;
1468 if ((offset + spos) < profileseq.getLength())
1470 // pad the final region with gaps.
1471 StringBuffer sb = new StringBuffer();
1472 for (int s = 0, ns = profileseq.getLength() - spos - offset; s < ns; s++)
1476 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1478 SequenceI sqobj = al.getSequenceAt(s);
1479 if (sqobj == profileseq)
1483 String sq = sqobj.getSequenceAsString();
1485 int diff = origseq.getLength() - sq.length();
1489 // + ((diff >= sb.length()) ? sb.toString() : sb
1490 // .substring(0, diff));
1491 if (diff >= sb.length())
1493 sq += sb.toString();
1497 char[] buf = new char[diff];
1498 sb.getChars(0, diff, buf, 0);
1499 sq += buf.toString();
1501 diff = origseq.getLength() - sq.length();
1509 * @return true if there are columns marked
1511 public boolean hasSelectedColumns()
1513 return (selection != null && selection.size() > 0);
1518 * @return true if there are columns hidden
1520 public boolean hasHiddenColumns()
1522 return hiddenColumns != null && hiddenColumns.size() > 0;
1527 * @return true if there are more than one set of columns hidden
1529 public boolean hasManyHiddenColumns()
1531 return hiddenColumns != null && hiddenColumns.size() > 1;
1535 * mark the columns corresponding to gap characters as hidden in the column
1540 public void hideInsertionsFor(SequenceI sr)
1542 List<int[]> inserts = sr.getInsertions();
1543 for (int[] r : inserts)
1545 hideColumns(r[0], r[1]);
1549 public boolean filterAnnotations(Annotation[] annotations,
1550 AnnotationFilterParameter filterParams)
1552 // JBPNote - this method needs to be refactored to become independent of
1553 // viewmodel package
1554 this.revealAllHiddenColumns();
1559 if (annotations[count] != null)
1562 boolean itemMatched = false;
1564 if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
1565 && annotations[count].value >= filterParams
1566 .getThresholdValue())
1570 if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
1571 && annotations[count].value <= filterParams
1572 .getThresholdValue())
1577 if (filterParams.isFilterAlphaHelix()
1578 && annotations[count].secondaryStructure == 'H')
1583 if (filterParams.isFilterBetaSheet()
1584 && annotations[count].secondaryStructure == 'E')
1589 if (filterParams.isFilterTurn()
1590 && annotations[count].secondaryStructure == 'S')
1595 String regexSearchString = filterParams.getRegexString();
1596 if (regexSearchString != null
1597 && !filterParams.getRegexSearchFields().isEmpty())
1599 List<SearchableAnnotationField> fields = filterParams
1600 .getRegexSearchFields();
1603 if (fields.contains(SearchableAnnotationField.DISPLAY_STRING)
1604 && annotations[count].displayCharacter
1605 .matches(regexSearchString))
1609 } catch (java.util.regex.PatternSyntaxException pse)
1611 if (annotations[count].displayCharacter
1612 .equals(regexSearchString))
1617 if (fields.contains(SearchableAnnotationField.DESCRIPTION)
1618 && annotations[count].description != null
1619 && annotations[count].description
1620 .matches(regexSearchString))
1628 this.addElement(count);
1632 } while (count < annotations.length);
1637 * Returns a hashCode built from selected columns and hidden column ranges
1640 public int hashCode()
1642 int hashCode = selection.hashCode();
1643 if (hiddenColumns != null)
1645 for (int[] hidden : hiddenColumns)
1647 hashCode = 31 * hashCode + hidden[0];
1648 hashCode = 31 * hashCode + hidden[1];
1655 * Answers true if comparing to a ColumnSelection with the same selected
1656 * columns and hidden columns, else false
1659 public boolean equals(Object obj)
1661 if (!(obj instanceof ColumnSelection))
1665 ColumnSelection that = (ColumnSelection) obj;
1668 * check columns selected are either both null, or match
1670 if (this.selection == null)
1672 if (that.selection != null)
1677 if (!this.selection.equals(that.selection))
1683 * check hidden columns are either both null, or match
1685 if (this.hiddenColumns == null)
1687 return (that.hiddenColumns == null);
1689 if (that.hiddenColumns == null
1690 || that.hiddenColumns.size() != this.hiddenColumns.size())
1695 for (int[] thisRange : hiddenColumns)
1697 int[] thatRange = that.hiddenColumns.get(i++);
1698 if (thisRange[0] != thatRange[0] || thisRange[1] != thatRange[1])