1 package jalview.datamodel;
3 import jalview.util.Comparison;
4 import jalview.util.ShiftList;
6 import java.util.ArrayList;
7 import java.util.BitSet;
8 import java.util.Collections;
9 import java.util.Iterator;
10 import java.util.List;
11 import java.util.Vector;
12 import java.util.concurrent.locks.ReentrantReadWriteLock;
14 public class HiddenColumns implements Iterable<int[]>
16 private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
19 * list of hidden column [start, end] ranges; the list is maintained in
20 * ascending start column order
22 private Vector<int[]> hiddenColumns;
25 * This Method is used to return all the HiddenColumn regions
27 * @return empty list or List of hidden column intervals
29 public List<int[]> getHiddenRegions()
31 return hiddenColumns == null ? Collections.<int[]> emptyList()
36 * Find the number of hidden columns
38 * @return number of hidden columns
44 lock.readLock().lock();
48 for (int[] range : hiddenColumns)
50 size += range[1] - range[0] + 1;
57 lock.readLock().unlock();
62 * Answers if there are any hidden columns
64 * @return true if there are hidden columns
66 public boolean hasHidden()
70 lock.readLock().lock();
71 return (hiddenColumns != null) && (!hiddenColumns.isEmpty());
74 lock.readLock().unlock();
80 public boolean equals(Object obj)
84 lock.readLock().lock();
86 if (!(obj instanceof HiddenColumns))
90 HiddenColumns that = (HiddenColumns) obj;
93 * check hidden columns are either both null, or match
95 if (this.hiddenColumns == null)
97 return (that.hiddenColumns == null);
99 if (that.hiddenColumns == null
100 || that.hiddenColumns.size() != this.hiddenColumns.size())
105 for (int[] thisRange : hiddenColumns)
107 int[] thatRange = that.hiddenColumns.get(i++);
108 if (thisRange[0] != thatRange[0] || thisRange[1] != thatRange[1])
116 lock.readLock().unlock();
121 * Return absolute column index for a visible column index
124 * int column index in alignment view (count from zero)
125 * @return alignment column index for column
127 public int adjustForHiddenColumns(int column)
131 lock.readLock().lock();
133 if (hiddenColumns != null)
135 for (int i = 0; i < hiddenColumns.size(); i++)
137 int[] region = hiddenColumns.elementAt(i);
138 if (result >= region[0])
140 result += region[1] - region[0] + 1;
147 lock.readLock().unlock();
152 * Use this method to find out where a column will appear in the visible
153 * alignment when hidden columns exist. If the column is not visible, then the
154 * left-most visible column will always be returned.
156 * @param hiddenColumn
157 * the column index in the full alignment including hidden columns
158 * @return the position of the column in the visible alignment
160 public int findColumnPosition(int hiddenColumn)
164 lock.readLock().lock();
165 int result = hiddenColumn;
166 if (hiddenColumns != null)
172 region = hiddenColumns.elementAt(index++);
173 if (hiddenColumn > region[1])
175 result -= region[1] + 1 - region[0];
177 } while ((hiddenColumn > region[1])
178 && (index < hiddenColumns.size()));
180 if (hiddenColumn >= region[0] && hiddenColumn <= region[1])
182 // Here the hidden column is within a region, so
183 // we want to return the position of region[0]-1, adjusted for any
184 // earlier hidden columns.
185 // Calculate the difference between the actual hidden col position
186 // and region[0]-1, and then subtract from result to convert result
188 // the adjusted hiddenColumn value to the adjusted region[0]-1 value
190 // However, if the region begins at 0 we cannot return region[0]-1
198 return result - (hiddenColumn - region[0] + 1);
202 return result; // return the shifted position after removing hidden
206 lock.readLock().unlock();
211 * Find the visible column which is a given visible number of columns to the
212 * left of another visible column. i.e. for a startColumn x, the column which
213 * is distance 1 away will be column x-1.
215 * @param visibleDistance
216 * the number of visible columns to offset by
218 * the column to start from
219 * @return the position of the column in the visible alignment
221 public int subtractVisibleColumns(int visibleDistance, int startColumn)
226 lock.readLock().lock();
227 int distance = visibleDistance;
229 // in case startColumn is in a hidden region, move it to the left
230 int start = adjustForHiddenColumns(findColumnPosition(startColumn));
232 // get index of hidden region to left of start
233 int index = getHiddenIndexLeft(start);
236 // no hidden regions to left of startColumn
237 return start - distance;
240 // walk backwards through the alignment subtracting the counts of visible
241 // columns from distance
244 int nextstart = start;
246 while ((index > -1) && (distance - gap > 0))
248 // subtract the gap to right of region from distance
252 // calculate the next gap
253 region = hiddenColumns.get(index);
254 gap = start - region[1];
256 // set start to just to left of current region
257 nextstart = region[0] - 1;
261 if (distance - gap > 0)
263 // fell out of loop because there are no more hidden regions
265 return nextstart - distance;
267 return start - distance;
270 lock.readLock().unlock();
276 * Use this method to determine where the next hiddenRegion starts
278 * @param hiddenRegion
279 * index of hidden region (counts from 0)
280 * @return column number in visible view
282 public int findHiddenRegionPosition(int hiddenRegion)
286 lock.readLock().lock();
288 if (hiddenColumns != null)
294 int[] region = hiddenColumns.elementAt(index);
295 if (hiddenRegion == 0)
300 gaps += region[1] + 1 - region[0];
301 result = region[1] + 1;
303 } while (index <= hiddenRegion);
312 lock.readLock().unlock();
317 * This method returns the rightmost limit of a region of an alignment with
318 * hidden columns. In otherwords, the next hidden column.
323 public int getHiddenBoundaryRight(int alPos)
327 lock.readLock().lock();
328 if (hiddenColumns != null)
333 int[] region = hiddenColumns.elementAt(index);
334 if (alPos < region[0])
340 } while (index < hiddenColumns.size());
346 lock.readLock().unlock();
352 * This method returns the leftmost limit of a region of an alignment with
353 * hidden columns. In otherwords, the previous hidden column.
358 public int getHiddenBoundaryLeft(int alPos)
362 lock.readLock().lock();
364 if (hiddenColumns != null)
366 int index = hiddenColumns.size() - 1;
369 int[] region = hiddenColumns.elementAt(index);
370 if (alPos > region[1])
376 } while (index > -1);
382 lock.readLock().unlock();
387 * This method returns the index of the hidden region to the left of a column
388 * position. If the column is in a hidden region it returns the index of the
389 * region to the left. If there is no hidden region to the left it returns -1.
394 private int getHiddenIndexLeft(int pos)
399 lock.readLock().lock();
400 if (hiddenColumns != null)
402 int index = hiddenColumns.size() - 1;
405 int[] region = hiddenColumns.elementAt(index);
412 } while (index > -1);
418 lock.readLock().unlock();
424 * Adds the specified column range to the hidden columns
429 public void hideColumns(int start, int end)
431 hideColumns(start, end, false);
435 * Adds the specified column range to the hidden columns
440 private void hideColumns(int start, int end, boolean alreadyLocked)
447 lock.writeLock().lock();
450 if (hiddenColumns == null)
452 hiddenColumns = new Vector<>();
456 * traverse existing hidden ranges and insert / amend / append as
459 for (int i = 0; i < hiddenColumns.size(); i++)
461 int[] region = hiddenColumns.elementAt(i);
463 if (end < region[0] - 1)
466 * insert discontiguous preceding range
468 hiddenColumns.insertElementAt(new int[] { start, end }, i);
472 if (end <= region[1])
475 * new range overlaps existing, or is contiguous preceding it - adjust
478 region[0] = Math.min(region[0], start);
482 if (start <= region[1] + 1)
485 * new range overlaps existing, or is contiguous following it - adjust
486 * start and end columns
488 region[0] = Math.min(region[0], start);
489 region[1] = Math.max(region[1], end);
492 * also update or remove any subsequent ranges
493 * that are overlapped
495 while (i < hiddenColumns.size() - 1)
497 int[] nextRegion = hiddenColumns.get(i + 1);
498 if (nextRegion[0] > end + 1)
501 * gap to next hidden range - no more to update
505 region[1] = Math.max(nextRegion[1], end);
506 hiddenColumns.remove(i + 1);
513 * remaining case is that the new range follows everything else
515 hiddenColumns.addElement(new int[] { start, end });
520 lock.writeLock().unlock();
525 public boolean isVisible(int column)
529 lock.readLock().lock();
531 if (hiddenColumns != null)
533 for (int[] region : hiddenColumns)
535 if (column >= region[0] && column <= region[1])
545 lock.readLock().unlock();
552 public HiddenColumns()
561 public HiddenColumns(HiddenColumns copy)
566 lock.readLock().lock();
569 if (copy.hiddenColumns != null)
571 hiddenColumns = copy.copyHiddenRegions();
577 lock.readLock().unlock();
581 private Vector<int[]> copyHiddenRegions()
583 Vector<int[]> copy = new Vector<>(hiddenColumns.size());
584 for (int i = 0, j = hiddenColumns.size(); i < j; i++)
587 rh = hiddenColumns.elementAt(i);
590 cp = new int[rh.length];
591 System.arraycopy(rh, 0, cp, 0, rh.length);
598 private ArrayList<int[]> copyHiddenRegionsToArrayList()
600 ArrayList<int[]> copy = new ArrayList<>(hiddenColumns.size());
601 for (int i = 0, j = hiddenColumns.size(); i < j; i++)
604 rh = hiddenColumns.elementAt(i);
607 cp = new int[rh.length];
608 System.arraycopy(rh, 0, cp, 0, rh.length);
615 public void getHiddenColumnsCopy(Vector<int[]> copy)
619 lock.readLock().lock();
620 copy = copyHiddenRegions();
623 lock.readLock().unlock();
627 public void getHiddenColumnsCopy(ArrayList<int[]> copy)
631 lock.readLock().lock();
632 copy = copyHiddenRegionsToArrayList();
635 lock.readLock().unlock();
640 * propagate shift in alignment columns to column selection
645 * shift in edit (+ve for removal, or -ve for inserts)
647 public List<int[]> compensateForEdit(int start, int change,
652 lock.writeLock().lock();
653 List<int[]> deletedHiddenColumns = null;
655 if (hiddenColumns != null)
657 deletedHiddenColumns = new ArrayList<>();
658 int hSize = hiddenColumns.size();
659 for (int i = 0; i < hSize; i++)
661 int[] region = hiddenColumns.elementAt(i);
662 if (region[0] > start && start + change > region[1])
664 deletedHiddenColumns.add(region);
666 hiddenColumns.removeElementAt(i);
672 if (region[0] > start)
685 this.revealHiddenColumns(0, sel);
688 return deletedHiddenColumns;
691 lock.writeLock().unlock();
696 * propagate shift in alignment columns to column selection special version of
697 * compensateForEdit - allowing for edits within hidden regions
702 * shift in edit (+ve for removal, or -ve for inserts)
704 public void compensateForDelEdits(int start, int change)
708 lock.writeLock().lock();
709 if (hiddenColumns != null)
711 for (int i = 0; i < hiddenColumns.size(); i++)
713 int[] region = hiddenColumns.elementAt(i);
714 if (region[0] >= start)
718 if (region[1] >= start)
722 if (region[1] < region[0])
724 hiddenColumns.removeElementAt(i--);
740 lock.writeLock().unlock();
745 * return all visible segments between the given start and end boundaries
748 * (first column inclusive from 0)
750 * (last column - not inclusive)
751 * @return int[] {i_start, i_end, ..} where intervals lie in
752 * start<=i_start<=i_end<end
754 public int[] getVisibleContigs(int start, int end)
758 lock.readLock().lock();
759 if (hiddenColumns != null && hiddenColumns.size() > 0)
761 List<int[]> visiblecontigs = new ArrayList<>();
762 List<int[]> regions = getHiddenRegions();
766 int hideStart, hideEnd;
768 for (int j = 0; vstart < end && j < regions.size(); j++)
770 region = regions.get(j);
771 hideStart = region[0];
774 if (hideEnd < vstart)
778 if (hideStart > vstart)
780 visiblecontigs.add(new int[] { vstart, hideStart - 1 });
782 vstart = hideEnd + 1;
787 visiblecontigs.add(new int[] { vstart, end - 1 });
789 int[] vcontigs = new int[visiblecontigs.size() * 2];
790 for (int i = 0, j = visiblecontigs.size(); i < j; i++)
792 int[] vc = visiblecontigs.get(i);
793 visiblecontigs.set(i, null);
794 vcontigs[i * 2] = vc[0];
795 vcontigs[i * 2 + 1] = vc[1];
797 visiblecontigs.clear();
802 return new int[] { start, end - 1 };
807 lock.readLock().unlock();
811 public String[] getVisibleSequenceStrings(int start, int end,
816 lock.readLock().lock();
817 int i, iSize = seqs.length;
818 String selections[] = new String[iSize];
819 if (hiddenColumns != null && hiddenColumns.size() > 0)
821 for (i = 0; i < iSize; i++)
823 StringBuffer visibleSeq = new StringBuffer();
824 List<int[]> regions = getHiddenRegions();
826 int blockStart = start, blockEnd = end;
828 int hideStart, hideEnd;
830 for (int j = 0; j < regions.size(); j++)
832 region = regions.get(j);
833 hideStart = region[0];
836 if (hideStart < start)
841 blockStart = Math.min(blockStart, hideEnd + 1);
842 blockEnd = Math.min(blockEnd, hideStart);
844 if (blockStart > blockEnd)
849 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
851 blockStart = hideEnd + 1;
855 if (end > blockStart)
857 visibleSeq.append(seqs[i].getSequence(blockStart, end));
860 selections[i] = visibleSeq.toString();
865 for (i = 0; i < iSize; i++)
867 selections[i] = seqs[i].getSequenceAsString(start, end);
875 lock.readLock().unlock();
880 * Locate the first and last position visible for this sequence. if seq isn't
881 * visible then return the position of the left and right of the hidden
882 * boundary region, and the corresponding alignment column indices for the
883 * extent of the sequence
886 * @return int[] { visible start, visible end, first seqpos, last seqpos,
887 * alignment index for seq start, alignment index for seq end }
889 public int[] locateVisibleBoundsOfSequence(SequenceI seq)
893 lock.readLock().lock();
894 int fpos = seq.getStart(), lpos = seq.getEnd();
897 if (hiddenColumns == null || hiddenColumns.size() == 0)
899 int ifpos = seq.findIndex(fpos) - 1,
900 ilpos = seq.findIndex(lpos) - 1;
901 return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos };
904 // Simply walk along the sequence whilst watching for hidden column
906 List<int[]> regions = getHiddenRegions();
907 int spos = fpos, lastvispos = -1, rcount = 0,
908 hideStart = seq.getLength(), hideEnd = -1;
909 int visPrev = 0, visNext = 0, firstP = -1, lastP = -1;
910 boolean foundStart = false;
911 for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
914 if (!Comparison.isGap(seq.getCharAt(p)))
916 // keep track of first/last column
917 // containing sequence data regardless of visibility
923 // update hidden region start/end
924 while (hideEnd < p && rcount < regions.size())
926 int[] region = regions.get(rcount++);
928 visNext += region[0] - visPrev;
929 hideStart = region[0];
934 hideStart = seq.getLength();
936 // update visible boundary for sequence
948 // look for next sequence position
954 return new int[] { findColumnPosition(start),
955 findColumnPosition(lastvispos), fpos, lpos, firstP, lastP };
957 // otherwise, sequence was completely hidden
958 return new int[] { visPrev, visNext, 0, 0, firstP, lastP };
962 lock.readLock().unlock();
967 * delete any columns in alignmentAnnotation that are hidden (including
968 * sequence associated annotation).
970 * @param alignmentAnnotation
972 public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)
974 makeVisibleAnnotation(-1, -1, alignmentAnnotation);
978 * delete any columns in alignmentAnnotation that are hidden (including
979 * sequence associated annotation).
982 * remove any annotation to the right of this column
984 * remove any annotation to the left of this column
985 * @param alignmentAnnotation
986 * the annotation to operate on
988 public void makeVisibleAnnotation(int start, int end,
989 AlignmentAnnotation alignmentAnnotation)
993 lock.readLock().lock();
994 if (alignmentAnnotation.annotations == null)
998 if (start == end && end == -1)
1001 end = alignmentAnnotation.annotations.length;
1003 if (hiddenColumns != null && hiddenColumns.size() > 0)
1005 // then mangle the alignmentAnnotation annotation array
1006 Vector<Annotation[]> annels = new Vector<>();
1007 Annotation[] els = null;
1008 List<int[]> regions = getHiddenRegions();
1009 int blockStart = start, blockEnd = end;
1011 int hideStart, hideEnd, w = 0;
1013 for (int j = 0; j < regions.size(); j++)
1015 region = regions.get(j);
1016 hideStart = region[0];
1017 hideEnd = region[1];
1019 if (hideStart < start)
1024 blockStart = Math.min(blockStart, hideEnd + 1);
1025 blockEnd = Math.min(blockEnd, hideStart);
1027 if (blockStart > blockEnd)
1032 annels.addElement(els = new Annotation[blockEnd - blockStart]);
1033 System.arraycopy(alignmentAnnotation.annotations, blockStart, els,
1036 blockStart = hideEnd + 1;
1040 if (end > blockStart)
1042 annels.addElement(els = new Annotation[end - blockStart + 1]);
1044 + blockStart) <= alignmentAnnotation.annotations.length)
1046 // copy just the visible segment of the annotation row
1047 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1048 els, 0, els.length);
1052 // copy to the end of the annotation row
1053 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1055 (alignmentAnnotation.annotations.length - blockStart));
1064 alignmentAnnotation.annotations = new Annotation[w];
1067 for (Annotation[] chnk : annels)
1069 System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
1076 alignmentAnnotation.restrict(start, end);
1081 lock.readLock().unlock();
1087 * @return true if there are columns hidden
1089 public boolean hasHiddenColumns()
1093 lock.readLock().lock();
1094 return hiddenColumns != null && hiddenColumns.size() > 0;
1097 lock.readLock().unlock();
1103 * @return true if there are more than one set of columns hidden
1105 public boolean hasManyHiddenColumns()
1109 lock.readLock().lock();
1110 return hiddenColumns != null && hiddenColumns.size() > 1;
1113 lock.readLock().unlock();
1118 * mark the columns corresponding to gap characters as hidden in the column
1123 public void hideInsertionsFor(SequenceI sr)
1127 lock.writeLock().lock();
1128 List<int[]> inserts = sr.getInsertions();
1129 for (int[] r : inserts)
1131 hideColumns(r[0], r[1], true);
1135 lock.writeLock().unlock();
1140 * Unhides, and adds to the selection list, all hidden columns
1142 public void revealAllHiddenColumns(ColumnSelection sel)
1146 lock.writeLock().lock();
1147 if (hiddenColumns != null)
1149 for (int i = 0; i < hiddenColumns.size(); i++)
1151 int[] region = hiddenColumns.elementAt(i);
1152 for (int j = region[0]; j < region[1] + 1; j++)
1159 hiddenColumns = null;
1163 lock.writeLock().unlock();
1168 * Reveals, and marks as selected, the hidden column range with the given
1173 public void revealHiddenColumns(int start, ColumnSelection sel)
1177 lock.writeLock().lock();
1178 for (int i = 0; i < hiddenColumns.size(); i++)
1180 int[] region = hiddenColumns.elementAt(i);
1181 if (start == region[0])
1183 for (int j = region[0]; j < region[1] + 1; j++)
1188 hiddenColumns.removeElement(region);
1192 if (hiddenColumns.size() == 0)
1194 hiddenColumns = null;
1199 lock.writeLock().unlock();
1204 * removes intersection of position,length ranges in deletions from the
1205 * start,end regions marked in intervals.
1211 private boolean pruneIntervalVector(final List<int[]> shifts,
1212 Vector<int[]> intervals)
1214 boolean pruned = false;
1215 int i = 0, j = intervals.size() - 1, s = 0, t = shifts.size() - 1;
1216 int hr[] = intervals.elementAt(i);
1217 int sr[] = shifts.get(s);
1218 while (i <= j && s <= t)
1220 boolean trailinghn = hr[1] >= sr[0];
1225 hr = intervals.elementAt(++i);
1233 int endshift = sr[0] + sr[1]; // deletion ranges - -ve means an insert
1234 if (endshift < hr[0] || endshift < sr[0])
1235 { // leadinghc disjoint or not a deletion
1238 sr = shifts.get(++s);
1246 boolean leadinghn = hr[0] >= sr[0];
1247 boolean leadinghc = hr[0] < endshift;
1248 boolean trailinghc = hr[1] < endshift;
1252 { // deleted hidden region.
1253 intervals.removeElementAt(i);
1258 hr = intervals.elementAt(i);
1264 hr[0] = endshift; // clip c terminal region
1265 leadinghn = !leadinghn;
1281 // sr contained in hr
1284 sr = shifts.get(++s);
1294 return pruned; // true if any interval was removed or modified by
1299 * remove any hiddenColumns or selected columns and shift remaining based on a
1300 * series of position, range deletions.
1304 public void pruneDeletions(List<int[]> shifts)
1308 lock.writeLock().lock();
1309 // delete any intervals intersecting.
1310 if (hiddenColumns != null)
1312 pruneIntervalVector(shifts, hiddenColumns);
1313 if (hiddenColumns != null && hiddenColumns.size() == 0)
1315 hiddenColumns = null;
1321 lock.writeLock().unlock();
1326 * Add gaps into the sequences aligned to profileseq under the given
1331 * - alignment to have gaps inserted into it
1333 * - alignment view where sequence corresponding to profileseq is
1335 * @return new HiddenColumns for new alignment view, with insertions into
1336 * profileseq marked as hidden.
1338 public static HiddenColumns propagateInsertions(SequenceI profileseq,
1339 AlignmentI al, AlignmentView input)
1343 char gc = al.getGapCharacter();
1344 Object[] alandhidden = input.getAlignmentAndHiddenColumns(gc);
1345 HiddenColumns nview = (HiddenColumns) alandhidden[1];
1346 SequenceI origseq = ((SequenceI[]) alandhidden[0])[profsqpos];
1347 nview.propagateInsertions(profileseq, al, origseq);
1354 * - sequence in al which corresponds to origseq
1356 * - alignment which is to have gaps inserted into it
1358 * - sequence corresponding to profileseq which defines gap map for
1361 private void propagateInsertions(SequenceI profileseq, AlignmentI al,
1364 char gc = al.getGapCharacter();
1365 // recover mapping between sequence's non-gap positions and positions
1367 pruneDeletions(ShiftList.parseMap(origseq.gapMap()));
1368 int[] viscontigs = al.getHiddenColumns().getVisibleContigs(0,
1369 profileseq.getLength());
1373 // add profile to visible contigs
1374 for (int v = 0; v < viscontigs.length; v += 2)
1376 if (viscontigs[v] > spos)
1378 StringBuffer sb = new StringBuffer();
1379 for (int s = 0, ns = viscontigs[v] - spos; s < ns; s++)
1383 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1385 SequenceI sqobj = al.getSequenceAt(s);
1386 if (sqobj != profileseq)
1388 String sq = al.getSequenceAt(s).getSequenceAsString();
1389 if (sq.length() <= spos + offset)
1392 int diff = spos + offset - sq.length() - 1;
1397 while ((diff = spos + offset - sq.length() - 1) > 0)
1400 // + ((diff >= sb.length()) ? sb.toString() : sb
1401 // .substring(0, diff));
1402 if (diff >= sb.length())
1404 sq += sb.toString();
1408 char[] buf = new char[diff];
1409 sb.getChars(0, diff, buf, 0);
1410 sq += buf.toString();
1414 sq += sb.toString();
1418 al.getSequenceAt(s).setSequence(
1419 sq.substring(0, spos + offset) + sb.toString()
1420 + sq.substring(spos + offset));
1424 // offset+=sb.length();
1426 spos = viscontigs[v + 1] + 1;
1428 if ((offset + spos) < profileseq.getLength())
1430 // pad the final region with gaps.
1431 StringBuffer sb = new StringBuffer();
1432 for (int s = 0, ns = profileseq.getLength() - spos - offset; s < ns; s++)
1436 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1438 SequenceI sqobj = al.getSequenceAt(s);
1439 if (sqobj == profileseq)
1443 String sq = sqobj.getSequenceAsString();
1445 int diff = origseq.getLength() - sq.length();
1449 // + ((diff >= sb.length()) ? sb.toString() : sb
1450 // .substring(0, diff));
1451 if (diff >= sb.length())
1453 sq += sb.toString();
1457 char[] buf = new char[diff];
1458 sb.getChars(0, diff, buf, 0);
1459 sq += buf.toString();
1461 diff = origseq.getLength() - sq.length();
1468 * remove any hiddenColumns or selected columns and shift remaining based on a
1469 * series of position, range deletions.
1473 private void pruneDeletions(ShiftList deletions)
1475 if (deletions != null)
1477 final List<int[]> shifts = deletions.getShifts();
1478 if (shifts != null && shifts.size() > 0)
1480 pruneDeletions(shifts);
1482 // and shift the rest.
1483 this.compensateForEdits(deletions);
1489 * Adjust hidden column boundaries based on a series of column additions or
1490 * deletions in visible regions.
1492 * @param shiftrecord
1495 private ShiftList compensateForEdits(ShiftList shiftrecord)
1497 if (shiftrecord != null)
1499 final List<int[]> shifts = shiftrecord.getShifts();
1500 if (shifts != null && shifts.size() > 0)
1503 for (int i = 0, j = shifts.size(); i < j; i++)
1505 int[] sh = shifts.get(i);
1506 compensateForDelEdits(shifted + sh[0], sh[1]);
1510 return shiftrecord.getInverse();
1516 * Returns a hashCode built from hidden column ranges
1519 public int hashCode()
1523 lock.readLock().lock();
1525 if (hiddenColumns != null)
1527 for (int[] hidden : hiddenColumns)
1529 hashCode = 31 * hashCode + hidden[0];
1530 hashCode = 31 * hashCode + hidden[1];
1537 lock.readLock().unlock();
1542 * Hide columns corresponding to the marked bits
1545 * - columns map to bits starting from zero
1547 public void hideMarkedBits(BitSet inserts)
1551 lock.writeLock().lock();
1552 for (int firstSet = inserts
1553 .nextSetBit(0), lastSet = 0; firstSet >= 0; firstSet = inserts
1554 .nextSetBit(lastSet))
1556 lastSet = inserts.nextClearBit(firstSet);
1557 hideColumns(firstSet, lastSet - 1, true);
1561 lock.writeLock().unlock();
1568 * BitSet where hidden columns will be marked
1570 public void markHiddenRegions(BitSet inserts)
1574 lock.readLock().lock();
1575 if (hiddenColumns == null)
1579 for (int[] range : hiddenColumns)
1581 inserts.set(range[0], range[1] + 1);
1586 lock.readLock().unlock();
1591 public Iterator<int[]> iterator()
1593 if (hiddenColumns == null)
1595 return Collections.<int[]> emptyList().iterator();
1597 return hiddenColumns.iterator();