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 the set of hiddenRegion start positions
278 * @return list of column number in visible view where hidden regions start
280 public List<Integer> findHiddenRegionPositions()
284 lock.readLock().lock();
285 List<Integer> positions = new ArrayList<>(
286 hiddenColumns.size());
288 positions.add(hiddenColumns.elementAt(0)[0]);
289 for (int i = 1; i < hiddenColumns.size(); ++i)
293 if (hiddenColumns != null)
299 int[] region = hiddenColumns.elementAt(index);
300 gaps += region[1] + 1 - region[0];
301 result = region[1] + 1;
303 } while (index <= i);
307 positions.add(result);
314 lock.readLock().unlock();
319 * This method returns the rightmost limit of a region of an alignment with
320 * hidden columns. In otherwords, the next hidden column.
325 public int getHiddenBoundaryRight(int alPos)
329 lock.readLock().lock();
330 if (hiddenColumns != null)
335 int[] region = hiddenColumns.elementAt(index);
336 if (alPos < region[0])
342 } while (index < hiddenColumns.size());
348 lock.readLock().unlock();
354 * This method returns the leftmost limit of a region of an alignment with
355 * hidden columns. In otherwords, the previous hidden column.
360 public int getHiddenBoundaryLeft(int alPos)
364 lock.readLock().lock();
366 if (hiddenColumns != null)
368 int index = hiddenColumns.size() - 1;
371 int[] region = hiddenColumns.elementAt(index);
372 if (alPos > region[1])
378 } while (index > -1);
384 lock.readLock().unlock();
389 * This method returns the index of the hidden region to the left of a column
390 * position. If the column is in a hidden region it returns the index of the
391 * region to the left. If there is no hidden region to the left it returns -1.
396 private int getHiddenIndexLeft(int pos)
401 lock.readLock().lock();
402 if (hiddenColumns != null)
404 int index = hiddenColumns.size() - 1;
407 int[] region = hiddenColumns.elementAt(index);
414 } while (index > -1);
420 lock.readLock().unlock();
426 * Adds the specified column range to the hidden columns
431 public void hideColumns(int start, int end)
433 hideColumns(start, end, false);
437 * Adds the specified column range to the hidden columns
442 private void hideColumns(int start, int end, boolean alreadyLocked)
449 lock.writeLock().lock();
452 if (hiddenColumns == null)
454 hiddenColumns = new Vector<>();
458 * traverse existing hidden ranges and insert / amend / append as
461 for (int i = 0; i < hiddenColumns.size(); i++)
463 int[] region = hiddenColumns.elementAt(i);
465 if (end < region[0] - 1)
468 * insert discontiguous preceding range
470 hiddenColumns.insertElementAt(new int[] { start, end }, i);
474 if (end <= region[1])
477 * new range overlaps existing, or is contiguous preceding it - adjust
480 region[0] = Math.min(region[0], start);
484 if (start <= region[1] + 1)
487 * new range overlaps existing, or is contiguous following it - adjust
488 * start and end columns
490 region[0] = Math.min(region[0], start);
491 region[1] = Math.max(region[1], end);
494 * also update or remove any subsequent ranges
495 * that are overlapped
497 while (i < hiddenColumns.size() - 1)
499 int[] nextRegion = hiddenColumns.get(i + 1);
500 if (nextRegion[0] > end + 1)
503 * gap to next hidden range - no more to update
507 region[1] = Math.max(nextRegion[1], end);
508 hiddenColumns.remove(i + 1);
515 * remaining case is that the new range follows everything else
517 hiddenColumns.addElement(new int[] { start, end });
522 lock.writeLock().unlock();
527 public boolean isVisible(int column)
531 lock.readLock().lock();
533 if (hiddenColumns != null)
535 for (int[] region : hiddenColumns)
537 if (column >= region[0] && column <= region[1])
547 lock.readLock().unlock();
554 public HiddenColumns()
563 public HiddenColumns(HiddenColumns copy)
568 lock.readLock().lock();
571 if (copy.hiddenColumns != null)
573 hiddenColumns = copy.copyHiddenRegions();
579 lock.readLock().unlock();
583 private Vector<int[]> copyHiddenRegions()
585 Vector<int[]> copy = new Vector<>(hiddenColumns.size());
586 for (int i = 0, j = hiddenColumns.size(); i < j; i++)
589 rh = hiddenColumns.elementAt(i);
592 cp = new int[rh.length];
593 System.arraycopy(rh, 0, cp, 0, rh.length);
600 private ArrayList<int[]> copyHiddenRegionsToArrayList()
602 ArrayList<int[]> copy = new ArrayList<>(hiddenColumns.size());
603 for (int i = 0, j = hiddenColumns.size(); i < j; i++)
606 rh = hiddenColumns.elementAt(i);
609 cp = new int[rh.length];
610 System.arraycopy(rh, 0, cp, 0, rh.length);
617 public void getHiddenColumnsCopy(Vector<int[]> copy)
621 lock.readLock().lock();
622 copy = copyHiddenRegions();
625 lock.readLock().unlock();
629 public void getHiddenColumnsCopy(ArrayList<int[]> copy)
633 lock.readLock().lock();
634 copy = copyHiddenRegionsToArrayList();
637 lock.readLock().unlock();
642 * propagate shift in alignment columns to column selection
647 * shift in edit (+ve for removal, or -ve for inserts)
649 public List<int[]> compensateForEdit(int start, int change,
654 lock.writeLock().lock();
655 List<int[]> deletedHiddenColumns = null;
657 if (hiddenColumns != null)
659 deletedHiddenColumns = new ArrayList<>();
660 int hSize = hiddenColumns.size();
661 for (int i = 0; i < hSize; i++)
663 int[] region = hiddenColumns.elementAt(i);
664 if (region[0] > start && start + change > region[1])
666 deletedHiddenColumns.add(region);
668 hiddenColumns.removeElementAt(i);
674 if (region[0] > start)
687 this.revealHiddenColumns(0, sel);
690 return deletedHiddenColumns;
693 lock.writeLock().unlock();
698 * propagate shift in alignment columns to column selection special version of
699 * compensateForEdit - allowing for edits within hidden regions
704 * shift in edit (+ve for removal, or -ve for inserts)
706 public void compensateForDelEdits(int start, int change)
710 lock.writeLock().lock();
711 if (hiddenColumns != null)
713 for (int i = 0; i < hiddenColumns.size(); i++)
715 int[] region = hiddenColumns.elementAt(i);
716 if (region[0] >= start)
720 if (region[1] >= start)
724 if (region[1] < region[0])
726 hiddenColumns.removeElementAt(i--);
742 lock.writeLock().unlock();
747 * return all visible segments between the given start and end boundaries
750 * (first column inclusive from 0)
752 * (last column - not inclusive)
753 * @return int[] {i_start, i_end, ..} where intervals lie in
754 * start<=i_start<=i_end<end
756 public int[] getVisibleContigs(int start, int end)
760 lock.readLock().lock();
761 if (hiddenColumns != null && hiddenColumns.size() > 0)
763 List<int[]> visiblecontigs = new ArrayList<>();
764 List<int[]> regions = getHiddenRegions();
768 int hideStart, hideEnd;
770 for (int j = 0; vstart < end && j < regions.size(); j++)
772 region = regions.get(j);
773 hideStart = region[0];
776 if (hideEnd < vstart)
780 if (hideStart > vstart)
782 visiblecontigs.add(new int[] { vstart, hideStart - 1 });
784 vstart = hideEnd + 1;
789 visiblecontigs.add(new int[] { vstart, end - 1 });
791 int[] vcontigs = new int[visiblecontigs.size() * 2];
792 for (int i = 0, j = visiblecontigs.size(); i < j; i++)
794 int[] vc = visiblecontigs.get(i);
795 visiblecontigs.set(i, null);
796 vcontigs[i * 2] = vc[0];
797 vcontigs[i * 2 + 1] = vc[1];
799 visiblecontigs.clear();
804 return new int[] { start, end - 1 };
809 lock.readLock().unlock();
813 public String[] getVisibleSequenceStrings(int start, int end,
818 lock.readLock().lock();
819 int i, iSize = seqs.length;
820 String selections[] = new String[iSize];
821 if (hiddenColumns != null && hiddenColumns.size() > 0)
823 for (i = 0; i < iSize; i++)
825 StringBuffer visibleSeq = new StringBuffer();
826 List<int[]> regions = getHiddenRegions();
828 int blockStart = start, blockEnd = end;
830 int hideStart, hideEnd;
832 for (int j = 0; j < regions.size(); j++)
834 region = regions.get(j);
835 hideStart = region[0];
838 if (hideStart < start)
843 blockStart = Math.min(blockStart, hideEnd + 1);
844 blockEnd = Math.min(blockEnd, hideStart);
846 if (blockStart > blockEnd)
851 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
853 blockStart = hideEnd + 1;
857 if (end > blockStart)
859 visibleSeq.append(seqs[i].getSequence(blockStart, end));
862 selections[i] = visibleSeq.toString();
867 for (i = 0; i < iSize; i++)
869 selections[i] = seqs[i].getSequenceAsString(start, end);
877 lock.readLock().unlock();
882 * Locate the first and last position visible for this sequence. if seq isn't
883 * visible then return the position of the left and right of the hidden
884 * boundary region, and the corresponding alignment column indices for the
885 * extent of the sequence
888 * @return int[] { visible start, visible end, first seqpos, last seqpos,
889 * alignment index for seq start, alignment index for seq end }
891 public int[] locateVisibleBoundsOfSequence(SequenceI seq)
895 lock.readLock().lock();
896 int fpos = seq.getStart(), lpos = seq.getEnd();
899 if (hiddenColumns == null || hiddenColumns.size() == 0)
901 int ifpos = seq.findIndex(fpos) - 1,
902 ilpos = seq.findIndex(lpos) - 1;
903 return new int[] { ifpos, ilpos, fpos, lpos, ifpos, ilpos };
906 // Simply walk along the sequence whilst watching for hidden column
908 List<int[]> regions = getHiddenRegions();
909 int spos = fpos, lastvispos = -1, rcount = 0,
910 hideStart = seq.getLength(), hideEnd = -1;
911 int visPrev = 0, visNext = 0, firstP = -1, lastP = -1;
912 boolean foundStart = false;
913 for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
916 if (!Comparison.isGap(seq.getCharAt(p)))
918 // keep track of first/last column
919 // containing sequence data regardless of visibility
925 // update hidden region start/end
926 while (hideEnd < p && rcount < regions.size())
928 int[] region = regions.get(rcount++);
930 visNext += region[0] - visPrev;
931 hideStart = region[0];
936 hideStart = seq.getLength();
938 // update visible boundary for sequence
950 // look for next sequence position
956 return new int[] { findColumnPosition(start),
957 findColumnPosition(lastvispos), fpos, lpos, firstP, lastP };
959 // otherwise, sequence was completely hidden
960 return new int[] { visPrev, visNext, 0, 0, firstP, lastP };
964 lock.readLock().unlock();
969 * delete any columns in alignmentAnnotation that are hidden (including
970 * sequence associated annotation).
972 * @param alignmentAnnotation
974 public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)
976 makeVisibleAnnotation(-1, -1, alignmentAnnotation);
980 * delete any columns in alignmentAnnotation that are hidden (including
981 * sequence associated annotation).
984 * remove any annotation to the right of this column
986 * remove any annotation to the left of this column
987 * @param alignmentAnnotation
988 * the annotation to operate on
990 public void makeVisibleAnnotation(int start, int end,
991 AlignmentAnnotation alignmentAnnotation)
995 lock.readLock().lock();
996 if (alignmentAnnotation.annotations == null)
1000 if (start == end && end == -1)
1003 end = alignmentAnnotation.annotations.length;
1005 if (hiddenColumns != null && hiddenColumns.size() > 0)
1007 // then mangle the alignmentAnnotation annotation array
1008 Vector<Annotation[]> annels = new Vector<>();
1009 Annotation[] els = null;
1010 List<int[]> regions = getHiddenRegions();
1011 int blockStart = start, blockEnd = end;
1013 int hideStart, hideEnd, w = 0;
1015 for (int j = 0; j < regions.size(); j++)
1017 region = regions.get(j);
1018 hideStart = region[0];
1019 hideEnd = region[1];
1021 if (hideStart < start)
1026 blockStart = Math.min(blockStart, hideEnd + 1);
1027 blockEnd = Math.min(blockEnd, hideStart);
1029 if (blockStart > blockEnd)
1034 annels.addElement(els = new Annotation[blockEnd - blockStart]);
1035 System.arraycopy(alignmentAnnotation.annotations, blockStart, els,
1038 blockStart = hideEnd + 1;
1042 if (end > blockStart)
1044 annels.addElement(els = new Annotation[end - blockStart + 1]);
1046 + blockStart) <= alignmentAnnotation.annotations.length)
1048 // copy just the visible segment of the annotation row
1049 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1050 els, 0, els.length);
1054 // copy to the end of the annotation row
1055 System.arraycopy(alignmentAnnotation.annotations, blockStart,
1057 (alignmentAnnotation.annotations.length - blockStart));
1066 alignmentAnnotation.annotations = new Annotation[w];
1069 for (Annotation[] chnk : annels)
1071 System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
1078 alignmentAnnotation.restrict(start, end);
1083 lock.readLock().unlock();
1089 * @return true if there are columns hidden
1091 public boolean hasHiddenColumns()
1095 lock.readLock().lock();
1096 return hiddenColumns != null && hiddenColumns.size() > 0;
1099 lock.readLock().unlock();
1105 * @return true if there are more than one set of columns hidden
1107 public boolean hasManyHiddenColumns()
1111 lock.readLock().lock();
1112 return hiddenColumns != null && hiddenColumns.size() > 1;
1115 lock.readLock().unlock();
1120 * mark the columns corresponding to gap characters as hidden in the column
1125 public void hideInsertionsFor(SequenceI sr)
1129 lock.writeLock().lock();
1130 List<int[]> inserts = sr.getInsertions();
1131 for (int[] r : inserts)
1133 hideColumns(r[0], r[1], true);
1137 lock.writeLock().unlock();
1142 * Unhides, and adds to the selection list, all hidden columns
1144 public void revealAllHiddenColumns(ColumnSelection sel)
1148 lock.writeLock().lock();
1149 if (hiddenColumns != null)
1151 for (int i = 0; i < hiddenColumns.size(); i++)
1153 int[] region = hiddenColumns.elementAt(i);
1154 for (int j = region[0]; j < region[1] + 1; j++)
1161 hiddenColumns = null;
1165 lock.writeLock().unlock();
1170 * Reveals, and marks as selected, the hidden column range with the given
1175 public void revealHiddenColumns(int start, ColumnSelection sel)
1179 lock.writeLock().lock();
1180 for (int i = 0; i < hiddenColumns.size(); i++)
1182 int[] region = hiddenColumns.elementAt(i);
1183 if (start == region[0])
1185 for (int j = region[0]; j < region[1] + 1; j++)
1190 hiddenColumns.removeElement(region);
1194 if (hiddenColumns.size() == 0)
1196 hiddenColumns = null;
1201 lock.writeLock().unlock();
1206 * removes intersection of position,length ranges in deletions from the
1207 * start,end regions marked in intervals.
1213 private boolean pruneIntervalVector(final List<int[]> shifts,
1214 Vector<int[]> intervals)
1216 boolean pruned = false;
1217 int i = 0, j = intervals.size() - 1, s = 0, t = shifts.size() - 1;
1218 int hr[] = intervals.elementAt(i);
1219 int sr[] = shifts.get(s);
1220 while (i <= j && s <= t)
1222 boolean trailinghn = hr[1] >= sr[0];
1227 hr = intervals.elementAt(++i);
1235 int endshift = sr[0] + sr[1]; // deletion ranges - -ve means an insert
1236 if (endshift < hr[0] || endshift < sr[0])
1237 { // leadinghc disjoint or not a deletion
1240 sr = shifts.get(++s);
1248 boolean leadinghn = hr[0] >= sr[0];
1249 boolean leadinghc = hr[0] < endshift;
1250 boolean trailinghc = hr[1] < endshift;
1254 { // deleted hidden region.
1255 intervals.removeElementAt(i);
1260 hr = intervals.elementAt(i);
1266 hr[0] = endshift; // clip c terminal region
1267 leadinghn = !leadinghn;
1283 // sr contained in hr
1286 sr = shifts.get(++s);
1296 return pruned; // true if any interval was removed or modified by
1301 * remove any hiddenColumns or selected columns and shift remaining based on a
1302 * series of position, range deletions.
1306 public void pruneDeletions(List<int[]> shifts)
1310 lock.writeLock().lock();
1311 // delete any intervals intersecting.
1312 if (hiddenColumns != null)
1314 pruneIntervalVector(shifts, hiddenColumns);
1315 if (hiddenColumns != null && hiddenColumns.size() == 0)
1317 hiddenColumns = null;
1323 lock.writeLock().unlock();
1328 * Add gaps into the sequences aligned to profileseq under the given
1333 * - alignment to have gaps inserted into it
1335 * - alignment view where sequence corresponding to profileseq is
1337 * @return new HiddenColumns for new alignment view, with insertions into
1338 * profileseq marked as hidden.
1340 public static HiddenColumns propagateInsertions(SequenceI profileseq,
1341 AlignmentI al, AlignmentView input)
1345 char gc = al.getGapCharacter();
1346 Object[] alandhidden = input.getAlignmentAndHiddenColumns(gc);
1347 HiddenColumns nview = (HiddenColumns) alandhidden[1];
1348 SequenceI origseq = ((SequenceI[]) alandhidden[0])[profsqpos];
1349 nview.propagateInsertions(profileseq, al, origseq);
1356 * - sequence in al which corresponds to origseq
1358 * - alignment which is to have gaps inserted into it
1360 * - sequence corresponding to profileseq which defines gap map for
1363 private void propagateInsertions(SequenceI profileseq, AlignmentI al,
1366 char gc = al.getGapCharacter();
1367 // recover mapping between sequence's non-gap positions and positions
1369 pruneDeletions(ShiftList.parseMap(origseq.gapMap()));
1370 int[] viscontigs = al.getHiddenColumns().getVisibleContigs(0,
1371 profileseq.getLength());
1375 // add profile to visible contigs
1376 for (int v = 0; v < viscontigs.length; v += 2)
1378 if (viscontigs[v] > spos)
1380 StringBuffer sb = new StringBuffer();
1381 for (int s = 0, ns = viscontigs[v] - spos; s < ns; s++)
1385 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1387 SequenceI sqobj = al.getSequenceAt(s);
1388 if (sqobj != profileseq)
1390 String sq = al.getSequenceAt(s).getSequenceAsString();
1391 if (sq.length() <= spos + offset)
1394 int diff = spos + offset - sq.length() - 1;
1399 while ((diff = spos + offset - sq.length() - 1) > 0)
1402 // + ((diff >= sb.length()) ? sb.toString() : sb
1403 // .substring(0, diff));
1404 if (diff >= sb.length())
1406 sq += sb.toString();
1410 char[] buf = new char[diff];
1411 sb.getChars(0, diff, buf, 0);
1412 sq += buf.toString();
1416 sq += sb.toString();
1420 al.getSequenceAt(s).setSequence(
1421 sq.substring(0, spos + offset) + sb.toString()
1422 + sq.substring(spos + offset));
1426 // offset+=sb.length();
1428 spos = viscontigs[v + 1] + 1;
1430 if ((offset + spos) < profileseq.getLength())
1432 // pad the final region with gaps.
1433 StringBuffer sb = new StringBuffer();
1434 for (int s = 0, ns = profileseq.getLength() - spos - offset; s < ns; s++)
1438 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1440 SequenceI sqobj = al.getSequenceAt(s);
1441 if (sqobj == profileseq)
1445 String sq = sqobj.getSequenceAsString();
1447 int diff = origseq.getLength() - sq.length();
1451 // + ((diff >= sb.length()) ? sb.toString() : sb
1452 // .substring(0, diff));
1453 if (diff >= sb.length())
1455 sq += sb.toString();
1459 char[] buf = new char[diff];
1460 sb.getChars(0, diff, buf, 0);
1461 sq += buf.toString();
1463 diff = origseq.getLength() - sq.length();
1470 * remove any hiddenColumns or selected columns and shift remaining based on a
1471 * series of position, range deletions.
1475 private void pruneDeletions(ShiftList deletions)
1477 if (deletions != null)
1479 final List<int[]> shifts = deletions.getShifts();
1480 if (shifts != null && shifts.size() > 0)
1482 pruneDeletions(shifts);
1484 // and shift the rest.
1485 this.compensateForEdits(deletions);
1491 * Adjust hidden column boundaries based on a series of column additions or
1492 * deletions in visible regions.
1494 * @param shiftrecord
1497 private ShiftList compensateForEdits(ShiftList shiftrecord)
1499 if (shiftrecord != null)
1501 final List<int[]> shifts = shiftrecord.getShifts();
1502 if (shifts != null && shifts.size() > 0)
1505 for (int i = 0, j = shifts.size(); i < j; i++)
1507 int[] sh = shifts.get(i);
1508 compensateForDelEdits(shifted + sh[0], sh[1]);
1512 return shiftrecord.getInverse();
1518 * Returns a hashCode built from hidden column ranges
1521 public int hashCode()
1525 lock.readLock().lock();
1527 if (hiddenColumns != null)
1529 for (int[] hidden : hiddenColumns)
1531 hashCode = 31 * hashCode + hidden[0];
1532 hashCode = 31 * hashCode + hidden[1];
1539 lock.readLock().unlock();
1544 * Hide columns corresponding to the marked bits
1547 * - columns map to bits starting from zero
1549 public void hideMarkedBits(BitSet inserts)
1553 lock.writeLock().lock();
1554 for (int firstSet = inserts
1555 .nextSetBit(0), lastSet = 0; firstSet >= 0; firstSet = inserts
1556 .nextSetBit(lastSet))
1558 lastSet = inserts.nextClearBit(firstSet);
1559 hideColumns(firstSet, lastSet - 1, true);
1563 lock.writeLock().unlock();
1570 * BitSet where hidden columns will be marked
1572 public void markHiddenRegions(BitSet inserts)
1576 lock.readLock().lock();
1577 if (hiddenColumns == null)
1581 for (int[] range : hiddenColumns)
1583 inserts.set(range[0], range[1] + 1);
1588 lock.readLock().unlock();
1593 public Iterator<int[]> iterator()
1595 if (hiddenColumns == null)
1597 return Collections.<int[]> emptyList().iterator();
1599 return hiddenColumns.iterator();