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
1088 * @return int[] { visible start, visible end, first seqpos, last seqpos }
1090 public int[] locateVisibleBoundsOfSequence(SequenceI seq)
1092 int fpos=seq.getStart(),lpos= seq.getEnd();
1095 if (hiddenColumns == null || hiddenColumns.size() == 0)
1097 return new int[] { seq.findIndex(fpos) - 1, seq.findIndex(lpos) - 1,
1102 // Simply walk along the sequence whilst watching for hidden column
1104 List<int[]> regions = getHiddenColumns();
1105 int spos = fpos, lastvispos = -1, rcount = 0, hideStart = seq
1106 .getLength(), hideEnd = -1;
1107 int visPrev = 0, visNext = 0;
1108 boolean foundStart = false;
1109 for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
1112 if (!Comparison.isGap(seq.getCharAt(p)))
1114 // update hidden region start/end
1115 while (hideEnd < p && rcount < regions.size())
1117 int[] region = regions.get(rcount++);
1119 visNext += region[0] - visPrev;
1120 hideStart = region[0];
1121 hideEnd = region[1];
1125 hideStart = seq.getLength();
1127 // update visible boundary for sequence
1139 // look for next sequence position
1145 return new int[] { findColumnPosition(start),
1146 findColumnPosition(lastvispos), fpos, lpos };
1148 // otherwise, sequence was completely hidden
1149 return new int[] { visPrev, visNext, 0, 0 };
1153 * delete any columns in alignmentAnnotation that are hidden (including
1154 * sequence associated annotation).
1156 * @param alignmentAnnotation
1158 public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)
1160 makeVisibleAnnotation(-1, -1, alignmentAnnotation);
1164 * delete any columns in alignmentAnnotation that are hidden (including
1165 * sequence associated annotation).
1168 * remove any annotation to the right of this column
1170 * remove any annotation to the left of this column
1171 * @param alignmentAnnotation
1172 * the annotation to operate on
1174 public void makeVisibleAnnotation(int start, int end,
1175 AlignmentAnnotation alignmentAnnotation)
1177 if (alignmentAnnotation.annotations == null)
1181 if (start == end && end == -1)
1184 end = alignmentAnnotation.annotations.length;
1186 if (hiddenColumns != null && hiddenColumns.size() > 0)
1188 // then mangle the alignmentAnnotation annotation array
1189 Vector<Annotation[]> annels = new Vector<Annotation[]>();
1190 Annotation[] els = null;
1191 List<int[]> regions = getHiddenColumns();
1192 int blockStart = start, blockEnd = end;
1194 int hideStart, hideEnd, w = 0;
1196 for (int j = 0; j < regions.size(); j++)
1198 region = regions.get(j);
1199 hideStart = region[0];
1200 hideEnd = region[1];
1202 if (hideStart < start)
1207 blockStart = Math.min(blockStart, hideEnd + 1);
1208 blockEnd = Math.min(blockEnd, hideStart);
1210 if (blockStart > blockEnd)
1215 annels.addElement(els = new Annotation[blockEnd - blockStart]);
1216 System.arraycopy(alignmentAnnotation.annotations, blockStart, els,
1219 blockStart = hideEnd + 1;
1223 if (end > blockStart)
1225 annels.addElement(els = new Annotation[end - blockStart + 1]);
1226 if ((els.length + blockStart) <= alignmentAnnotation.annotations.length)
1228 // copy just the visible segment of the annotation row
1229 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1230 els, 0, els.length);
1234 // copy to the end of the annotation row
1235 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1237 (alignmentAnnotation.annotations.length - blockStart));
1246 alignmentAnnotation.annotations = new Annotation[w];
1249 for (Annotation[] chnk : annels)
1251 System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
1258 alignmentAnnotation.restrict(start, end);
1263 * Invert the column selection from first to end-1. leaves hiddenColumns
1264 * untouched (and unselected)
1269 public void invertColumnSelection(int first, int width)
1271 boolean hasHidden = hiddenColumns != null && hiddenColumns.size() > 0;
1272 for (int i = first; i < width; i++)
1280 if (!hasHidden || isVisible(i))
1289 * add in any unselected columns from the given column selection, excluding
1290 * any that are hidden.
1294 public void addElementsFrom(ColumnSelection colsel)
1296 if (colsel != null && !colsel.isEmpty())
1298 for (Integer col : colsel.getSelected())
1300 if (hiddenColumns != null && isVisible(col.intValue()))
1309 * set the selected columns the given column selection, excluding any columns
1314 public void setElementsFrom(ColumnSelection colsel)
1316 selected = new IntList();
1317 if (colsel.selected != null && colsel.selected.size() > 0)
1319 if (hiddenColumns != null && hiddenColumns.size() > 0)
1321 // only select visible columns in this columns selection
1322 addElementsFrom(colsel);
1326 // add everything regardless
1327 for (Integer col : colsel.getSelected())
1336 * Add gaps into the sequences aligned to profileseq under the given
1341 * - alignment to have gaps inserted into it
1343 * - alignment view where sequence corresponding to profileseq is
1345 * @return new Column selection for new alignment view, with insertions into
1346 * profileseq marked as hidden.
1348 public static ColumnSelection propagateInsertions(SequenceI profileseq,
1349 AlignmentI al, AlignmentView input)
1353 // return propagateInsertions(profileseq, al, )
1354 char gc = al.getGapCharacter();
1355 Object[] alandcolsel = input.getAlignmentAndColumnSelection(gc);
1356 ColumnSelection nview = (ColumnSelection) alandcolsel[1];
1357 SequenceI origseq = ((SequenceI[]) alandcolsel[0])[profsqpos];
1358 nview.propagateInsertions(profileseq, al, origseq);
1365 * - sequence in al which corresponds to origseq
1367 * - alignment which is to have gaps inserted into it
1369 * - sequence corresponding to profileseq which defines gap map for
1372 public void propagateInsertions(SequenceI profileseq, AlignmentI al,
1375 char gc = al.getGapCharacter();
1376 // recover mapping between sequence's non-gap positions and positions
1378 pruneDeletions(ShiftList.parseMap(origseq.gapMap()));
1379 int[] viscontigs = getVisibleContigs(0, profileseq.getLength());
1382 // input.pruneDeletions(ShiftList.parseMap(((SequenceI[])
1383 // alandcolsel[0])[0].gapMap()))
1384 // add profile to visible contigs
1385 for (int v = 0; v < viscontigs.length; v += 2)
1387 if (viscontigs[v] > spos)
1389 StringBuffer sb = new StringBuffer();
1390 for (int s = 0, ns = viscontigs[v] - spos; s < ns; s++)
1394 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1396 SequenceI sqobj = al.getSequenceAt(s);
1397 if (sqobj != profileseq)
1399 String sq = al.getSequenceAt(s).getSequenceAsString();
1400 if (sq.length() <= spos + offset)
1403 int diff = spos + offset - sq.length() - 1;
1408 while ((diff = spos + offset - sq.length() - 1) > 0)
1411 // + ((diff >= sb.length()) ? sb.toString() : sb
1412 // .substring(0, diff));
1413 if (diff >= sb.length())
1415 sq += sb.toString();
1419 char[] buf = new char[diff];
1420 sb.getChars(0, diff, buf, 0);
1421 sq += buf.toString();
1425 sq += sb.toString();
1429 al.getSequenceAt(s).setSequence(
1430 sq.substring(0, spos + offset) + sb.toString()
1431 + sq.substring(spos + offset));
1435 // offset+=sb.length();
1437 spos = viscontigs[v + 1] + 1;
1439 if ((offset + spos) < profileseq.getLength())
1441 // pad the final region with gaps.
1442 StringBuffer sb = new StringBuffer();
1443 for (int s = 0, ns = profileseq.getLength() - spos - offset; s < ns; s++)
1447 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1449 SequenceI sqobj = al.getSequenceAt(s);
1450 if (sqobj == profileseq)
1454 String sq = sqobj.getSequenceAsString();
1456 int diff = origseq.getLength() - sq.length();
1460 // + ((diff >= sb.length()) ? sb.toString() : sb
1461 // .substring(0, diff));
1462 if (diff >= sb.length())
1464 sq += sb.toString();
1468 char[] buf = new char[diff];
1469 sb.getChars(0, diff, buf, 0);
1470 sq += buf.toString();
1472 diff = origseq.getLength() - sq.length();
1480 * @return true if there are columns marked
1482 public boolean hasSelectedColumns()
1484 return (selected != null && selected.size() > 0);
1489 * @return true if there are columns hidden
1491 public boolean hasHiddenColumns()
1493 return hiddenColumns != null && hiddenColumns.size() > 0;
1498 * @return true if there are more than one set of columns hidden
1500 public boolean hasManyHiddenColumns()
1502 return hiddenColumns != null && hiddenColumns.size() > 1;
1506 * mark the columns corresponding to gap characters as hidden in the column
1511 public void hideInsertionsFor(SequenceI sr)
1513 List<int[]> inserts = sr.getInsertions();
1514 for (int[] r : inserts)
1516 hideColumns(r[0], r[1]);
1520 public boolean filterAnnotations(Annotation[] annotations,
1521 AnnotationFilterParameter filterParams)
1523 // JBPNote - this method needs to be refactored to become independent of
1524 // viewmodel package
1525 this.revealAllHiddenColumns();
1530 if (annotations[count] != null)
1533 boolean itemMatched = false;
1535 if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
1536 && annotations[count].value >= filterParams
1537 .getThresholdValue())
1541 if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
1542 && annotations[count].value <= filterParams
1543 .getThresholdValue())
1548 if (filterParams.isFilterAlphaHelix()
1549 && annotations[count].secondaryStructure == 'H')
1554 if (filterParams.isFilterBetaSheet()
1555 && annotations[count].secondaryStructure == 'E')
1560 if (filterParams.isFilterTurn()
1561 && annotations[count].secondaryStructure == 'S')
1566 String regexSearchString = filterParams.getRegexString();
1567 if (regexSearchString != null
1568 && !filterParams.getRegexSearchFields().isEmpty())
1570 List<SearchableAnnotationField> fields = filterParams
1571 .getRegexSearchFields();
1574 if (fields.contains(SearchableAnnotationField.DISPLAY_STRING)
1575 && annotations[count].displayCharacter
1576 .matches(regexSearchString))
1580 } catch (java.util.regex.PatternSyntaxException pse)
1582 if (annotations[count].displayCharacter
1583 .equals(regexSearchString))
1588 if (fields.contains(SearchableAnnotationField.DESCRIPTION)
1589 && annotations[count].description != null
1590 && annotations[count].description
1591 .matches(regexSearchString))
1599 this.addElement(count);
1603 } while (count < annotations.length);