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 * NOTE: Columns are zero based.
37 public class ColumnSelection
42 * list of selected columns (ordered by selection order, not column order)
44 private List<Integer> order = new ArrayList<Integer>();
47 * bitfield for column selection - allows quick lookup
49 private BitSet selected = new BitSet();
52 * adds a new column i to the selection - only if i is not already selected
56 public void add(int i)
60 order.add(Integer.valueOf(i));
71 public void remove(int col)
74 Integer colInt = new Integer(col);
76 if (selected.get(col))
78 // if this ever changes to List.remove(), ensure Integer not int
80 // as List.remove(int i) removes the i'th item which is wrong
86 public boolean contains(Integer colInt)
88 return selected.get(colInt);
91 public boolean isEmpty()
93 return order.isEmpty();
96 public List<Integer> getList()
107 * gets the column that was selected first, second or i'th
112 public int elementAt(int i)
117 protected boolean pruneColumnList(final List<int[]> shifts)
119 int s = 0, t = shifts.size();
120 int[] sr = shifts.get(s++);
121 boolean pruned = false;
122 int i = 0, j = order.size();
123 while (i < j && s <= t)
125 int c = order.get(i++).intValue();
128 if (sr[1] + sr[0] >= c)
129 { // sr[1] -ve means inseriton.
148 * shift every selected column at or above start by change
151 * - leftmost column to be shifted
155 public void compensateForEdits(int start, int change)
157 BitSet mask = new BitSet();
158 for (int i = 0; i < order.size(); i++)
160 int temp = order.get(i);
164 // clear shifted bits and update List of selected columns
165 selected.clear(temp);
166 mask.set(temp - change);
167 order.set(i, new Integer(temp - change));
170 // lastly update the bitfield all at once
174 public boolean isSelected(int column)
176 return selected.get(column);
179 public int getMaxColumn()
181 return selected.length() - 1;
184 public int getMinColumn()
186 return selected.get(0) ? 0 : selected.nextSetBit(0);
190 * @return a series of selection intervals along the range
192 public List<int[]> getRanges()
194 List<int[]> rlist = new ArrayList<int[]>();
195 if (selected.isEmpty())
199 int next = selected.nextSetBit(0), clear = -1;
202 clear = selected.nextClearBit(next);
203 rlist.add(new int[] { next, clear - 1 });
204 next = selected.nextSetBit(clear);
210 IntList selected = new IntList();
213 * list of hidden column [start, end] ranges; the list is maintained in
214 * ascending start column order
216 Vector<int[]> hiddenColumns;
219 * Add a column to the selection
224 public void addElement(int col)
230 * clears column selection
238 * Removes value 'col' from the selection (not the col'th item)
241 * index of column to be removed
243 public void removeElement(int col)
245 selected.remove(col);
249 * removes a range of columns from the selection
252 * int - first column in range to be removed
256 public void removeElements(int start, int end)
259 for (int i = start; i < end; i++)
261 colInt = new Integer(i);
262 if (selected.contains(colInt))
264 selected.remove(colInt);
270 * Returns a list of selected columns. The list contains no duplicates but is
271 * not necessarily ordered. It also may include columns hidden from the
274 public List<Integer> getSelected()
276 return selected.getList();
280 * @return list of int arrays containing start and end column position for
281 * runs of selected columns ordered from right to left.
283 public List<int[]> getSelectedRanges()
285 return selected.getRanges();
291 * index to search for in column selection
293 * @return true if col is selected
295 public boolean contains(int col)
297 return (col > -1) ? selected.isSelected(col) : false;
301 * Answers true if no columns are selected, else false
303 public boolean isEmpty()
305 return selected == null || selected.isEmpty();
309 * rightmost selected column
311 * @return rightmost column in alignment that is selected
315 if (selected.isEmpty())
319 return selected.getMaxColumn();
323 * Leftmost column in selection
325 * @return column index of leftmost column in selection
329 if (selected.isEmpty())
333 return selected.getMinColumn();
337 * propagate shift in alignment columns to column selection
342 * shift in edit (+ve for removal, or -ve for inserts)
344 public List<int[]> compensateForEdit(int start, int change)
346 List<int[]> deletedHiddenColumns = null;
347 selected.compensateForEdits(start, change);
349 if (hiddenColumns != null)
351 deletedHiddenColumns = new ArrayList<int[]>();
352 int hSize = hiddenColumns.size();
353 for (int i = 0; i < hSize; i++)
355 int[] region = hiddenColumns.elementAt(i);
356 if (region[0] > start && start + change > region[1])
358 deletedHiddenColumns.add(region);
360 hiddenColumns.removeElementAt(i);
366 if (region[0] > start)
379 this.revealHiddenColumns(0);
382 return deletedHiddenColumns;
386 * propagate shift in alignment columns to column selection special version of
387 * compensateForEdit - allowing for edits within hidden regions
392 * shift in edit (+ve for removal, or -ve for inserts)
394 private void compensateForDelEdits(int start, int change)
397 selected.compensateForEdits(start, change);
399 if (hiddenColumns != null)
401 for (int i = 0; i < hiddenColumns.size(); i++)
403 int[] region = hiddenColumns.elementAt(i);
404 if (region[0] >= start)
408 if (region[1] >= start)
412 if (region[1] < region[0])
414 hiddenColumns.removeElementAt(i--);
430 * Adjust hidden column boundaries based on a series of column additions or
431 * deletions in visible regions.
436 public ShiftList compensateForEdits(ShiftList shiftrecord)
438 if (shiftrecord != null)
440 final List<int[]> shifts = shiftrecord.getShifts();
441 if (shifts != null && shifts.size() > 0)
444 for (int i = 0, j = shifts.size(); i < j; i++)
446 int[] sh = shifts.get(i);
447 // compensateForEdit(shifted+sh[0], sh[1]);
448 compensateForDelEdits(shifted + sh[0], sh[1]);
452 return shiftrecord.getInverse();
458 * removes intersection of position,length ranges in deletions from the
459 * start,end regions marked in intervals.
465 private boolean pruneIntervalVector(final List<int[]> shifts,
466 Vector<int[]> intervals)
468 boolean pruned = false;
469 int i = 0, j = intervals.size() - 1, s = 0, t = shifts.size() - 1;
470 int hr[] = intervals.elementAt(i);
471 int sr[] = shifts.get(s);
472 while (i <= j && s <= t)
474 boolean trailinghn = hr[1] >= sr[0];
479 hr = intervals.elementAt(++i);
487 int endshift = sr[0] + sr[1]; // deletion ranges - -ve means an insert
488 if (endshift < hr[0] || endshift < sr[0])
489 { // leadinghc disjoint or not a deletion
492 sr = shifts.get(++s);
500 boolean leadinghn = hr[0] >= sr[0];
501 boolean leadinghc = hr[0] < endshift;
502 boolean trailinghc = hr[1] < endshift;
506 { // deleted hidden region.
507 intervals.removeElementAt(i);
512 hr = intervals.elementAt(i);
518 hr[0] = endshift; // clip c terminal region
519 leadinghn = !leadinghn;
535 // sr contained in hr
538 sr = shifts.get(++s);
548 return pruned; // true if any interval was removed or modified by
553 * remove any hiddenColumns or selected columns and shift remaining based on a
554 * series of position, range deletions.
558 public void pruneDeletions(ShiftList deletions)
560 if (deletions != null)
562 final List<int[]> shifts = deletions.getShifts();
563 if (shifts != null && shifts.size() > 0)
565 // delete any intervals intersecting.
566 if (hiddenColumns != null)
568 pruneIntervalVector(shifts, hiddenColumns);
569 if (hiddenColumns != null && hiddenColumns.size() == 0)
571 hiddenColumns = null;
574 if (selected != null && selected.size() > 0)
576 selected.pruneColumnList(shifts);
577 if (selected != null && selected.size() == 0)
582 // and shift the rest.
583 this.compensateForEdits(deletions);
589 * This Method is used to return all the HiddenColumn regions
591 * @return empty list or List of hidden column intervals
593 public List<int[]> getHiddenColumns()
595 return hiddenColumns == null ? Collections.<int[]> emptyList()
600 * Return absolute column index for a visible column index
603 * int column index in alignment view
604 * @return alignment column index for column
606 public int adjustForHiddenColumns(int column)
609 if (hiddenColumns != null)
611 for (int i = 0; i < hiddenColumns.size(); i++)
613 int[] region = hiddenColumns.elementAt(i);
614 if (result >= region[0])
616 result += region[1] - region[0] + 1;
624 * Use this method to find out where a column will appear in the visible
625 * alignment when hidden columns exist. If the column is not visible, then the
626 * left-most visible column will always be returned.
628 * @param hiddenColumn
632 public int findColumnPosition(int hiddenColumn)
634 int result = hiddenColumn;
635 if (hiddenColumns != null)
641 region = hiddenColumns.elementAt(index++);
642 if (hiddenColumn > region[1])
644 result -= region[1] + 1 - region[0];
646 } while ((hiddenColumn > region[1]) && (index < hiddenColumns.size()));
647 if (hiddenColumn > region[0] && hiddenColumn < region[1])
649 return region[0] + hiddenColumn - result;
652 return result; // return the shifted position after removing hidden columns.
656 * Use this method to determine where the next hiddenRegion starts
658 * @param hiddenRegion
659 * index of hidden region (counts from 0)
660 * @return column number in visible view
662 public int findHiddenRegionPosition(int hiddenRegion)
665 if (hiddenColumns != null)
671 int[] region = hiddenColumns.elementAt(index);
672 if (hiddenRegion == 0)
677 gaps += region[1] + 1 - region[0];
678 result = region[1] + 1;
680 } while (index <= hiddenRegion);
689 * THis method returns the rightmost limit of a region of an alignment with
690 * hidden columns. In otherwords, the next hidden column.
695 public int getHiddenBoundaryRight(int alPos)
697 if (hiddenColumns != null)
702 int[] region = hiddenColumns.elementAt(index);
703 if (alPos < region[0])
709 } while (index < hiddenColumns.size());
717 * This method returns the leftmost limit of a region of an alignment with
718 * hidden columns. In otherwords, the previous hidden column.
723 public int getHiddenBoundaryLeft(int alPos)
725 if (hiddenColumns != null)
727 int index = hiddenColumns.size() - 1;
730 int[] region = hiddenColumns.elementAt(index);
731 if (alPos > region[1])
737 } while (index > -1);
744 public void hideSelectedColumns()
746 synchronized (selected)
748 for (int[] selregions : selected.getRanges())
750 hideColumns(selregions[0], selregions[1]);
758 * Adds the specified column range to the hidden columns
763 public void hideColumns(int start, int end)
765 if (hiddenColumns == null)
767 hiddenColumns = new Vector<int[]>();
771 * traverse existing hidden ranges and insert / amend / append as
774 for (int i = 0; i < hiddenColumns.size(); i++)
776 int[] region = hiddenColumns.elementAt(i);
778 if (end < region[0] - 1)
781 * insert discontiguous preceding range
783 hiddenColumns.insertElementAt(new int[] { start, end }, i);
787 if (end <= region[1])
790 * new range overlaps existing, or is contiguous preceding it - adjust
793 region[0] = Math.min(region[0], start);
797 if (start <= region[1] + 1)
800 * new range overlaps existing, or is contiguous following it - adjust
801 * start and end columns
803 region[0] = Math.min(region[0], start);
804 region[1] = Math.max(region[1], end);
810 * remaining case is that the new range follows everything else
812 hiddenColumns.addElement(new int[] { start, end });
816 * Hides the specified column and any adjacent selected columns
821 public void hideColumns(int col)
824 * deselect column (whether selected or not!)
829 * find adjacent selected columns
831 int min = col - 1, max = col + 1;
832 while (contains(min))
838 while (contains(max))
845 * min, max are now the closest unselected columns
854 hideColumns(min, max);
858 * Unhides, and adds to the selection list, all hidden columns
860 public void revealAllHiddenColumns()
862 if (hiddenColumns != null)
864 for (int i = 0; i < hiddenColumns.size(); i++)
866 int[] region = hiddenColumns.elementAt(i);
867 for (int j = region[0]; j < region[1] + 1; j++)
874 hiddenColumns = null;
878 * Reveals, and marks as selected, the hidden column range with the given
883 public void revealHiddenColumns(int start)
885 for (int i = 0; i < hiddenColumns.size(); i++)
887 int[] region = hiddenColumns.elementAt(i);
888 if (start == region[0])
890 for (int j = region[0]; j < region[1] + 1; j++)
895 hiddenColumns.removeElement(region);
899 if (hiddenColumns.size() == 0)
901 hiddenColumns = null;
905 public boolean isVisible(int column)
907 if (hiddenColumns != null)
909 for (int[] region : hiddenColumns)
911 if (column >= region[0] && column <= region[1])
926 public ColumnSelection(ColumnSelection copy)
930 if (copy.selected != null)
932 selected = new IntList();
933 for (int i = 0, j = copy.selected.size(); i < j; i++)
935 selected.add(copy.selected.elementAt(i));
938 if (copy.hiddenColumns != null)
940 hiddenColumns = new Vector<int[]>(copy.hiddenColumns.size());
941 for (int i = 0, j = copy.hiddenColumns.size(); i < j; i++)
944 rh = copy.hiddenColumns.elementAt(i);
947 cp = new int[rh.length];
948 System.arraycopy(rh, 0, cp, 0, rh.length);
949 hiddenColumns.addElement(cp);
959 public ColumnSelection()
963 public String[] getVisibleSequenceStrings(int start, int end,
966 int i, iSize = seqs.length;
967 String selection[] = new String[iSize];
968 if (hiddenColumns != null && hiddenColumns.size() > 0)
970 for (i = 0; i < iSize; i++)
972 StringBuffer visibleSeq = new StringBuffer();
973 List<int[]> regions = getHiddenColumns();
975 int blockStart = start, blockEnd = end;
977 int hideStart, hideEnd;
979 for (int j = 0; j < regions.size(); j++)
981 region = regions.get(j);
982 hideStart = region[0];
985 if (hideStart < start)
990 blockStart = Math.min(blockStart, hideEnd + 1);
991 blockEnd = Math.min(blockEnd, hideStart);
993 if (blockStart > blockEnd)
998 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
1000 blockStart = hideEnd + 1;
1004 if (end > blockStart)
1006 visibleSeq.append(seqs[i].getSequence(blockStart, end));
1009 selection[i] = visibleSeq.toString();
1014 for (i = 0; i < iSize; i++)
1016 selection[i] = seqs[i].getSequenceAsString(start, end);
1024 * return all visible segments between the given start and end boundaries
1027 * (first column inclusive from 0)
1029 * (last column - not inclusive)
1030 * @return int[] {i_start, i_end, ..} where intervals lie in
1031 * start<=i_start<=i_end<end
1033 public int[] getVisibleContigs(int start, int end)
1035 if (hiddenColumns != null && hiddenColumns.size() > 0)
1037 List<int[]> visiblecontigs = new ArrayList<int[]>();
1038 List<int[]> regions = getHiddenColumns();
1042 int hideStart, hideEnd;
1044 for (int j = 0; vstart < end && j < regions.size(); j++)
1046 region = regions.get(j);
1047 hideStart = region[0];
1048 hideEnd = region[1];
1050 if (hideEnd < vstart)
1054 if (hideStart > vstart)
1056 visiblecontigs.add(new int[] { vstart, hideStart - 1 });
1058 vstart = hideEnd + 1;
1063 visiblecontigs.add(new int[] { vstart, end - 1 });
1065 int[] vcontigs = new int[visiblecontigs.size() * 2];
1066 for (int i = 0, j = visiblecontigs.size(); i < j; i++)
1068 int[] vc = visiblecontigs.get(i);
1069 visiblecontigs.set(i, null);
1070 vcontigs[i * 2] = vc[0];
1071 vcontigs[i * 2 + 1] = vc[1];
1073 visiblecontigs.clear();
1078 return new int[] { start, end - 1 };
1083 * Locate the first and last position visible for this sequence. if seq isn't
1084 * visible then return the position of the left and right of the hidden
1085 * boundary region, and the corresponding alignment column indices for the
1086 * extent of the sequence
1089 * @return int[] { visible start, visible end, first seqpos, last seqpos,
1090 * alignment index for seq start, alignment index for seq end }
1092 public int[] locateVisibleBoundsOfSequence(SequenceI seq)
1094 int fpos=seq.getStart(),lpos= seq.getEnd();
1097 if (hiddenColumns == null || hiddenColumns.size() == 0)
1099 int ifpos = seq.findIndex(fpos) - 1, ilpos = seq.findIndex(lpos) - 1;
1100 return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos };
1103 // Simply walk along the sequence whilst watching for hidden column
1105 List<int[]> regions = getHiddenColumns();
1106 int spos = fpos, lastvispos = -1, rcount = 0, hideStart = seq
1107 .getLength(), hideEnd = -1;
1108 int visPrev = 0, visNext = 0, firstP = -1, lastP = -1;
1109 boolean foundStart = false;
1110 for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
1113 if (!Comparison.isGap(seq.getCharAt(p)))
1115 // keep track of first/last column
1116 // containing sequence data regardless of visibility
1122 // update hidden region start/end
1123 while (hideEnd < p && rcount < regions.size())
1125 int[] region = regions.get(rcount++);
1127 visNext += region[0] - visPrev;
1128 hideStart = region[0];
1129 hideEnd = region[1];
1133 hideStart = seq.getLength();
1135 // update visible boundary for sequence
1147 // look for next sequence position
1153 return new int[] { findColumnPosition(start),
1154 findColumnPosition(lastvispos), fpos, lpos, firstP, lastP };
1156 // otherwise, sequence was completely hidden
1157 return new int[] { visPrev, visNext, 0, 0, firstP, lastP };
1161 * delete any columns in alignmentAnnotation that are hidden (including
1162 * sequence associated annotation).
1164 * @param alignmentAnnotation
1166 public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)
1168 makeVisibleAnnotation(-1, -1, alignmentAnnotation);
1172 * delete any columns in alignmentAnnotation that are hidden (including
1173 * sequence associated annotation).
1176 * remove any annotation to the right of this column
1178 * remove any annotation to the left of this column
1179 * @param alignmentAnnotation
1180 * the annotation to operate on
1182 public void makeVisibleAnnotation(int start, int end,
1183 AlignmentAnnotation alignmentAnnotation)
1185 if (alignmentAnnotation.annotations == null)
1189 if (start == end && end == -1)
1192 end = alignmentAnnotation.annotations.length;
1194 if (hiddenColumns != null && hiddenColumns.size() > 0)
1196 // then mangle the alignmentAnnotation annotation array
1197 Vector<Annotation[]> annels = new Vector<Annotation[]>();
1198 Annotation[] els = null;
1199 List<int[]> regions = getHiddenColumns();
1200 int blockStart = start, blockEnd = end;
1202 int hideStart, hideEnd, w = 0;
1204 for (int j = 0; j < regions.size(); j++)
1206 region = regions.get(j);
1207 hideStart = region[0];
1208 hideEnd = region[1];
1210 if (hideStart < start)
1215 blockStart = Math.min(blockStart, hideEnd + 1);
1216 blockEnd = Math.min(blockEnd, hideStart);
1218 if (blockStart > blockEnd)
1223 annels.addElement(els = new Annotation[blockEnd - blockStart]);
1224 System.arraycopy(alignmentAnnotation.annotations, blockStart, els,
1227 blockStart = hideEnd + 1;
1231 if (end > blockStart)
1233 annels.addElement(els = new Annotation[end - blockStart + 1]);
1234 if ((els.length + blockStart) <= alignmentAnnotation.annotations.length)
1236 // copy just the visible segment of the annotation row
1237 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1238 els, 0, els.length);
1242 // copy to the end of the annotation row
1243 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1245 (alignmentAnnotation.annotations.length - blockStart));
1254 alignmentAnnotation.annotations = new Annotation[w];
1257 for (Annotation[] chnk : annels)
1259 System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
1266 alignmentAnnotation.restrict(start, end);
1271 * Invert the column selection from first to end-1. leaves hiddenColumns
1272 * untouched (and unselected)
1277 public void invertColumnSelection(int first, int width)
1279 boolean hasHidden = hiddenColumns != null && hiddenColumns.size() > 0;
1280 for (int i = first; i < width; i++)
1288 if (!hasHidden || isVisible(i))
1297 * add in any unselected columns from the given column selection, excluding
1298 * any that are hidden.
1302 public void addElementsFrom(ColumnSelection colsel)
1304 if (colsel != null && !colsel.isEmpty())
1306 for (Integer col : colsel.getSelected())
1308 if (hiddenColumns != null && isVisible(col.intValue()))
1317 * set the selected columns the given column selection, excluding any columns
1322 public void setElementsFrom(ColumnSelection colsel)
1324 selected = new IntList();
1325 if (colsel.selected != null && colsel.selected.size() > 0)
1327 if (hiddenColumns != null && hiddenColumns.size() > 0)
1329 // only select visible columns in this columns selection
1330 addElementsFrom(colsel);
1334 // add everything regardless
1335 for (Integer col : colsel.getSelected())
1344 * Add gaps into the sequences aligned to profileseq under the given
1349 * - alignment to have gaps inserted into it
1351 * - alignment view where sequence corresponding to profileseq is
1353 * @return new Column selection for new alignment view, with insertions into
1354 * profileseq marked as hidden.
1356 public static ColumnSelection propagateInsertions(SequenceI profileseq,
1357 AlignmentI al, AlignmentView input)
1361 // return propagateInsertions(profileseq, al, )
1362 char gc = al.getGapCharacter();
1363 Object[] alandcolsel = input.getAlignmentAndColumnSelection(gc);
1364 ColumnSelection nview = (ColumnSelection) alandcolsel[1];
1365 SequenceI origseq = ((SequenceI[]) alandcolsel[0])[profsqpos];
1366 nview.propagateInsertions(profileseq, al, origseq);
1373 * - sequence in al which corresponds to origseq
1375 * - alignment which is to have gaps inserted into it
1377 * - sequence corresponding to profileseq which defines gap map for
1380 public void propagateInsertions(SequenceI profileseq, AlignmentI al,
1383 char gc = al.getGapCharacter();
1384 // recover mapping between sequence's non-gap positions and positions
1386 pruneDeletions(ShiftList.parseMap(origseq.gapMap()));
1387 int[] viscontigs = getVisibleContigs(0, profileseq.getLength());
1390 // input.pruneDeletions(ShiftList.parseMap(((SequenceI[])
1391 // alandcolsel[0])[0].gapMap()))
1392 // add profile to visible contigs
1393 for (int v = 0; v < viscontigs.length; v += 2)
1395 if (viscontigs[v] > spos)
1397 StringBuffer sb = new StringBuffer();
1398 for (int s = 0, ns = viscontigs[v] - spos; s < ns; s++)
1402 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1404 SequenceI sqobj = al.getSequenceAt(s);
1405 if (sqobj != profileseq)
1407 String sq = al.getSequenceAt(s).getSequenceAsString();
1408 if (sq.length() <= spos + offset)
1411 int diff = spos + offset - sq.length() - 1;
1416 while ((diff = spos + offset - sq.length() - 1) > 0)
1419 // + ((diff >= sb.length()) ? sb.toString() : sb
1420 // .substring(0, diff));
1421 if (diff >= sb.length())
1423 sq += sb.toString();
1427 char[] buf = new char[diff];
1428 sb.getChars(0, diff, buf, 0);
1429 sq += buf.toString();
1433 sq += sb.toString();
1437 al.getSequenceAt(s).setSequence(
1438 sq.substring(0, spos + offset) + sb.toString()
1439 + sq.substring(spos + offset));
1443 // offset+=sb.length();
1445 spos = viscontigs[v + 1] + 1;
1447 if ((offset + spos) < profileseq.getLength())
1449 // pad the final region with gaps.
1450 StringBuffer sb = new StringBuffer();
1451 for (int s = 0, ns = profileseq.getLength() - spos - offset; s < ns; s++)
1455 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1457 SequenceI sqobj = al.getSequenceAt(s);
1458 if (sqobj == profileseq)
1462 String sq = sqobj.getSequenceAsString();
1464 int diff = origseq.getLength() - sq.length();
1468 // + ((diff >= sb.length()) ? sb.toString() : sb
1469 // .substring(0, diff));
1470 if (diff >= sb.length())
1472 sq += sb.toString();
1476 char[] buf = new char[diff];
1477 sb.getChars(0, diff, buf, 0);
1478 sq += buf.toString();
1480 diff = origseq.getLength() - sq.length();
1488 * @return true if there are columns marked
1490 public boolean hasSelectedColumns()
1492 return (selected != null && selected.size() > 0);
1497 * @return true if there are columns hidden
1499 public boolean hasHiddenColumns()
1501 return hiddenColumns != null && hiddenColumns.size() > 0;
1506 * @return true if there are more than one set of columns hidden
1508 public boolean hasManyHiddenColumns()
1510 return hiddenColumns != null && hiddenColumns.size() > 1;
1514 * mark the columns corresponding to gap characters as hidden in the column
1519 public void hideInsertionsFor(SequenceI sr)
1521 List<int[]> inserts = sr.getInsertions();
1522 for (int[] r : inserts)
1524 hideColumns(r[0], r[1]);
1528 public boolean filterAnnotations(Annotation[] annotations,
1529 AnnotationFilterParameter filterParams)
1531 // JBPNote - this method needs to be refactored to become independent of
1532 // viewmodel package
1533 this.revealAllHiddenColumns();
1538 if (annotations[count] != null)
1541 boolean itemMatched = false;
1543 if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
1544 && annotations[count].value >= filterParams
1545 .getThresholdValue())
1549 if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
1550 && annotations[count].value <= filterParams
1551 .getThresholdValue())
1556 if (filterParams.isFilterAlphaHelix()
1557 && annotations[count].secondaryStructure == 'H')
1562 if (filterParams.isFilterBetaSheet()
1563 && annotations[count].secondaryStructure == 'E')
1568 if (filterParams.isFilterTurn()
1569 && annotations[count].secondaryStructure == 'S')
1574 String regexSearchString = filterParams.getRegexString();
1575 if (regexSearchString != null
1576 && !filterParams.getRegexSearchFields().isEmpty())
1578 List<SearchableAnnotationField> fields = filterParams
1579 .getRegexSearchFields();
1582 if (fields.contains(SearchableAnnotationField.DISPLAY_STRING)
1583 && annotations[count].displayCharacter
1584 .matches(regexSearchString))
1588 } catch (java.util.regex.PatternSyntaxException pse)
1590 if (annotations[count].displayCharacter
1591 .equals(regexSearchString))
1596 if (fields.contains(SearchableAnnotationField.DESCRIPTION)
1597 && annotations[count].description != null
1598 && annotations[count].description
1599 .matches(regexSearchString))
1607 this.addElement(count);
1611 } while (count < annotations.length);