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;
25 import java.util.ArrayList;
26 import java.util.BitSet;
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.Vector;
30 import java.util.concurrent.locks.ReentrantReadWriteLock;
32 public class HiddenColumns
34 private static final int HASH_MULTIPLIER = 31;
36 private static final ReentrantReadWriteLock LOCK = new ReentrantReadWriteLock();
39 * list of hidden column [start, end] ranges; the list is maintained in
40 * ascending start column order
42 private ArrayList<int[]> hiddenColumns;
47 public HiddenColumns()
56 public HiddenColumns(HiddenColumns copy)
60 LOCK.writeLock().lock();
63 if (copy.hiddenColumns != null)
65 hiddenColumns = copy.copyHiddenRegionsToArrayList();
70 LOCK.writeLock().unlock();
75 * This method is used to return all the HiddenColumn regions and is intended
76 * to remain private. External callers which need a copy of the regions can
77 * call getHiddenColumnsCopyAsList.
79 * @return empty list or List of hidden column intervals
81 private List<int[]> getHiddenRegions()
83 return hiddenColumns == null ? Collections.<int[]> emptyList()
88 * Output regions data as a string. String is in the format:
89 * reg0[0]<between>reg0[1]<delimiter>reg1[0]<between>reg1[1] ... regn[1]
92 * string to delimit regions
93 * @param betweenstring
94 * to put between start and end region values
95 * @return regions formatted according to delimiter and between strings
97 public String regionsToString(String delimiter, String between)
101 LOCK.readLock().lock();
102 StringBuilder regionBuilder = new StringBuilder();
103 if (hiddenColumns != null)
105 for (int[] range : hiddenColumns)
107 regionBuilder.append(delimiter).append(range[0]).append(between)
111 regionBuilder.deleteCharAt(0);
113 return regionBuilder.toString();
116 LOCK.readLock().unlock();
121 * Find the number of hidden columns
123 * @return number of hidden columns
129 LOCK.readLock().lock();
131 if (hasHiddenColumns())
133 for (int[] range : hiddenColumns)
135 size += range[1] - range[0] + 1;
141 LOCK.readLock().unlock();
146 public boolean equals(Object obj)
150 LOCK.readLock().lock();
152 if (!(obj instanceof HiddenColumns))
156 HiddenColumns that = (HiddenColumns) obj;
159 * check hidden columns are either both null, or match
161 if (this.hiddenColumns == null)
163 return (that.hiddenColumns == null);
165 if (that.hiddenColumns == null
166 || that.hiddenColumns.size() != this.hiddenColumns.size())
171 for (int[] thisRange : hiddenColumns)
173 int[] thatRange = that.hiddenColumns.get(i++);
174 if (thisRange[0] != thatRange[0] || thisRange[1] != thatRange[1])
182 LOCK.readLock().unlock();
187 * Return absolute column index for a visible column index
190 * int column index in alignment view (count from zero)
191 * @return alignment column index for column
193 public int adjustForHiddenColumns(int column)
197 LOCK.readLock().lock();
199 if (hiddenColumns != null)
201 for (int i = 0; i < hiddenColumns.size(); i++)
203 int[] region = hiddenColumns.get(i);
204 if (result >= region[0])
206 result += region[1] - region[0] + 1;
213 LOCK.readLock().unlock();
218 * Use this method to find out where a column will appear in the visible
219 * alignment when hidden columns exist. If the column is not visible, then the
220 * left-most visible column will always be returned.
222 * @param hiddenColumn
223 * the column index in the full alignment including hidden columns
224 * @return the position of the column in the visible alignment
226 public int findColumnPosition(int hiddenColumn)
230 LOCK.readLock().lock();
231 int result = hiddenColumn;
232 if (hiddenColumns != null)
238 region = hiddenColumns.get(index++);
239 if (hiddenColumn > region[1])
241 result -= region[1] + 1 - region[0];
243 } while ((hiddenColumn > region[1])
244 && (index < hiddenColumns.size()));
246 if (hiddenColumn >= region[0] && hiddenColumn <= region[1])
248 // Here the hidden column is within a region, so
249 // we want to return the position of region[0]-1, adjusted for any
250 // earlier hidden columns.
251 // Calculate the difference between the actual hidden col position
252 // and region[0]-1, and then subtract from result to convert result
254 // the adjusted hiddenColumn value to the adjusted region[0]-1 value
256 // However, if the region begins at 0 we cannot return region[0]-1
264 return result - (hiddenColumn - region[0] + 1);
268 return result; // return the shifted position after removing hidden
272 LOCK.readLock().unlock();
277 * Find the visible column which is a given visible number of columns to the
278 * left of another visible column. i.e. for a startColumn x, the column which
279 * is distance 1 away will be column x-1.
281 * @param visibleDistance
282 * the number of visible columns to offset by
284 * the column to start from
285 * @return the position of the column in the visible alignment
287 public int subtractVisibleColumns(int visibleDistance, int startColumn)
292 LOCK.readLock().lock();
293 int distance = visibleDistance;
295 // in case startColumn is in a hidden region, move it to the left
296 int start = adjustForHiddenColumns(findColumnPosition(startColumn));
298 // get index of hidden region to left of start
299 int index = getHiddenIndexLeft(start);
302 // no hidden regions to left of startColumn
303 return start - distance;
306 // walk backwards through the alignment subtracting the counts of visible
307 // columns from distance
310 int nextstart = start;
312 while ((index > -1) && (distance - gap > 0))
314 // subtract the gap to right of region from distance
318 // calculate the next gap
319 region = hiddenColumns.get(index);
320 gap = start - region[1];
322 // set start to just to left of current region
323 nextstart = region[0] - 1;
327 if (distance - gap > 0)
329 // fell out of loop because there are no more hidden regions
331 return nextstart - distance;
333 return start - distance;
336 LOCK.readLock().unlock();
342 * Use this method to determine the set of hiddenRegion start positions
343 * between absolute position <start> and absolute position <end>
346 * absolute residue to start from
348 * absolute residue to end at
350 * @return list of column numbers in *visible* view where hidden regions start
352 public List<Integer> findHiddenRegionPositions(int start, int end)
356 LOCK.readLock().lock();
357 List<Integer> positions = null;
359 if (hiddenColumns != null)
361 positions = new ArrayList<>(hiddenColumns.size());
363 // navigate to start, keeping count of hidden columns
366 while ((i < hiddenColumns.size())
367 && (hiddenColumns.get(i)[0] < start))
369 int[] region = hiddenColumns.get(i);
370 hiddenSoFar += region[1] - region[0] + 1;
374 // iterate from start to end, adding start positions of each
375 // hidden region. Positions are visible columns count, not absolute
376 while (i < hiddenColumns.size()
377 && (hiddenColumns.get(i)[0] < end + hiddenSoFar))
379 int[] region = hiddenColumns.get(i);
380 positions.add(region[0] - hiddenSoFar);
381 hiddenSoFar += region[1] - region[0] + 1;
387 positions = new ArrayList<>();
393 LOCK.readLock().unlock();
398 * This method returns the rightmost limit of a region of an alignment with
399 * hidden columns. In otherwords, the next hidden column.
404 public int getHiddenBoundaryRight(int alPos)
408 LOCK.readLock().lock();
409 if (hiddenColumns != null)
414 int[] region = hiddenColumns.get(index);
415 if (alPos < region[0])
421 } while (index < hiddenColumns.size());
427 LOCK.readLock().unlock();
433 * This method returns the leftmost limit of a region of an alignment with
434 * hidden columns. In otherwords, the previous hidden column.
439 public int getHiddenBoundaryLeft(int alPos)
443 LOCK.readLock().lock();
445 if (hiddenColumns != null)
447 int index = hiddenColumns.size() - 1;
450 int[] region = hiddenColumns.get(index);
451 if (alPos > region[1])
457 } while (index > -1);
463 LOCK.readLock().unlock();
468 * This method returns the index of the hidden region to the left of a column
469 * position. If the column is in a hidden region it returns the index of the
470 * region to the left. If there is no hidden region to the left it returns -1.
475 private int getHiddenIndexLeft(int pos)
480 LOCK.readLock().lock();
481 if (hiddenColumns != null)
483 int index = hiddenColumns.size() - 1;
486 int[] region = hiddenColumns.get(index);
493 } while (index > -1);
499 LOCK.readLock().unlock();
505 * Adds the specified column range to the hidden columns
510 public void hideColumns(int start, int end)
512 boolean wasAlreadyLocked = false;
515 // check if the write lock was already locked by this thread,
516 // as this method can be called internally in loops within HiddenColumns
517 if (!LOCK.isWriteLockedByCurrentThread())
519 LOCK.writeLock().lock();
523 wasAlreadyLocked = true;
526 if (hiddenColumns == null)
528 hiddenColumns = new ArrayList<>();
532 * traverse existing hidden ranges and insert / amend / append as
535 for (int i = 0; i < hiddenColumns.size(); i++)
537 int[] region = hiddenColumns.get(i);
539 if (end < region[0] - 1)
542 * insert discontiguous preceding range
544 hiddenColumns.add(i, new int[] { start, end });
548 if (end <= region[1])
551 * new range overlaps existing, or is contiguous preceding it - adjust
554 region[0] = Math.min(region[0], start);
558 if (start <= region[1] + 1)
561 * new range overlaps existing, or is contiguous following it - adjust
562 * start and end columns
564 region[0] = Math.min(region[0], start);
565 region[1] = Math.max(region[1], end);
568 * also update or remove any subsequent ranges
569 * that are overlapped
571 while (i < hiddenColumns.size() - 1)
573 int[] nextRegion = hiddenColumns.get(i + 1);
574 if (nextRegion[0] > end + 1)
577 * gap to next hidden range - no more to update
581 region[1] = Math.max(nextRegion[1], end);
582 hiddenColumns.remove(i + 1);
589 * remaining case is that the new range follows everything else
591 hiddenColumns.add(new int[] { start, end });
594 if (!wasAlreadyLocked)
596 LOCK.writeLock().unlock();
601 public boolean isVisible(int column)
605 LOCK.readLock().lock();
607 if (hiddenColumns != null)
609 for (int[] region : hiddenColumns)
611 if (column >= region[0] && column <= region[1])
621 LOCK.readLock().unlock();
625 private ArrayList<int[]> copyHiddenRegionsToArrayList()
628 if (hiddenColumns != null)
630 size = hiddenColumns.size();
632 ArrayList<int[]> copy = new ArrayList<>(size);
634 for (int i = 0, j = size; i < j; i++)
638 rh = hiddenColumns.get(i);
641 cp = new int[rh.length];
642 System.arraycopy(rh, 0, cp, 0, rh.length);
651 * Returns a copy of the vector of hidden regions, as an ArrayList. Before
652 * using this method please consider if you really need access to the hidden
653 * regions - a new (or existing!) method on HiddenColumns might be more
656 * @return hidden regions as an ArrayList of [start,end] pairs
658 public ArrayList<int[]> getHiddenColumnsCopy()
662 LOCK.readLock().lock();
663 return copyHiddenRegionsToArrayList();
666 LOCK.readLock().unlock();
671 * return all visible segments between the given start and end boundaries
674 * (first column inclusive from 0)
676 * (last column - not inclusive)
677 * @return int[] {i_start, i_end, ..} where intervals lie in
678 * start<=i_start<=i_end<end
680 public int[] getVisibleContigs(int start, int end)
684 LOCK.readLock().lock();
685 if (hiddenColumns != null && hiddenColumns.size() > 0)
687 // max limit on number of visible contigs
688 // so we can dimension array
689 int maxcontigs = end - start + 1;
690 if (maxcontigs > (hiddenColumns.size() + 1) * 2)
692 maxcontigs = (hiddenColumns.size() + 1) * 2;
694 int[] vcontigs = new int[maxcontigs];
700 for (int[] region : hiddenColumns)
702 hideStart = region[0];
706 if (hideEnd < vstart)
710 if (hideStart > vstart)
712 vcontigs[i * 2] = vstart;
713 vcontigs[i * 2 + 1] = hideStart - 1;
716 vstart = hideEnd + 1;
718 // exit if we're past the end
727 vcontigs[i * 2] = vstart;
728 vcontigs[i * 2 + 1] = end - 1;
732 // copy final array into array of correct size
733 int[] trimmmedContigs = new int[i * 2];
734 System.arraycopy(vcontigs, 0, trimmmedContigs, 0, i * 2);
736 return trimmmedContigs;
740 return new int[] { start, end - 1 };
744 LOCK.readLock().unlock();
748 public String[] getVisibleSequenceStrings(int start, int end,
753 LOCK.readLock().lock();
754 int iSize = seqs.length;
755 String[] selections = new String[iSize];
756 if (hiddenColumns != null && hiddenColumns.size() > 0)
758 for (int i = 0; i < iSize; i++)
760 StringBuffer visibleSeq = new StringBuffer();
762 int blockStart = start;
767 for (int[] region : hiddenColumns)
769 hideStart = region[0];
772 if (hideStart < start)
777 blockStart = Math.min(blockStart, hideEnd + 1);
778 blockEnd = Math.min(blockEnd, hideStart);
780 if (blockStart > blockEnd)
785 visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
787 blockStart = hideEnd + 1;
791 if (end > blockStart)
793 visibleSeq.append(seqs[i].getSequence(blockStart, end));
796 selections[i] = visibleSeq.toString();
801 for (int i = 0; i < iSize; i++)
803 selections[i] = seqs[i].getSequenceAsString(start, end);
810 LOCK.readLock().unlock();
815 * Locate the first and last position visible for this sequence. if seq isn't
816 * visible then return the position of the left and right of the hidden
817 * boundary region, and the corresponding alignment column indices for the
818 * extent of the sequence
821 * @return int[] { visible start, visible end, first seqpos, last seqpos,
822 * alignment index for seq start, alignment index for seq end }
824 public int[] locateVisibleBoundsOfSequence(SequenceI seq)
828 LOCK.readLock().lock();
829 int fpos = seq.getStart();
830 int lpos = seq.getEnd();
833 if (hiddenColumns == null || hiddenColumns.size() == 0)
835 int ifpos = seq.findIndex(fpos) - 1;
836 int ilpos = seq.findIndex(lpos) - 1;
837 return new int[] { ifpos, ifpos, ilpos };
840 // Simply walk along the sequence whilst watching for hidden column
842 List<int[]> regions = getHiddenRegions();
845 int hideStart = seq.getLength();
851 boolean foundStart = false;
852 for (int p = 0, pLen = seq.getLength(); spos <= seq.getEnd()
855 if (!Comparison.isGap(seq.getCharAt(p)))
857 // keep track of first/last column
858 // containing sequence data regardless of visibility
864 // update hidden region start/end
865 while (hideEnd < p && rcount < regions.size())
867 int[] region = regions.get(rcount++);
869 visNext += region[0] - visPrev;
870 hideStart = region[0];
875 hideStart = seq.getLength();
877 // update visible boundary for sequence
888 // look for next sequence position
894 return new int[] { findColumnPosition(start), firstP, lastP };
896 // otherwise, sequence was completely hidden
897 return new int[] { visPrev, firstP, lastP };
900 LOCK.readLock().unlock();
905 * delete any columns in alignmentAnnotation that are hidden (including
906 * sequence associated annotation).
908 * @param alignmentAnnotation
910 public void makeVisibleAnnotation(AlignmentAnnotation alignmentAnnotation)
912 makeVisibleAnnotation(-1, -1, alignmentAnnotation);
916 * delete any columns in alignmentAnnotation that are hidden (including
917 * sequence associated annotation).
920 * remove any annotation to the right of this column
922 * remove any annotation to the left of this column
923 * @param alignmentAnnotation
924 * the annotation to operate on
926 public void makeVisibleAnnotation(int start, int end,
927 AlignmentAnnotation alignmentAnnotation)
931 LOCK.readLock().lock();
932 if (alignmentAnnotation.annotations == null)
936 if (start == end && end == -1)
939 end = alignmentAnnotation.annotations.length;
941 if (hiddenColumns != null && hiddenColumns.size() > 0)
943 // then mangle the alignmentAnnotation annotation array
944 Vector<Annotation[]> annels = new Vector<>();
945 Annotation[] els = null;
946 int blockStart = start;
952 for (int[] region : hiddenColumns)
954 hideStart = region[0];
957 if (hideStart < start)
962 blockStart = Math.min(blockStart, hideEnd + 1);
963 blockEnd = Math.min(blockEnd, hideStart);
965 if (blockStart > blockEnd)
970 els = new Annotation[blockEnd - blockStart];
971 annels.addElement(els);
972 System.arraycopy(alignmentAnnotation.annotations, blockStart, els,
975 blockStart = hideEnd + 1;
979 if (end > blockStart)
981 els = new Annotation[end - blockStart + 1];
982 annels.addElement(els);
984 + blockStart) <= alignmentAnnotation.annotations.length)
986 // copy just the visible segment of the annotation row
987 System.arraycopy(alignmentAnnotation.annotations, blockStart,
992 // copy to the end of the annotation row
993 System.arraycopy(alignmentAnnotation.annotations, blockStart,
995 (alignmentAnnotation.annotations.length - blockStart));
1004 alignmentAnnotation.annotations = new Annotation[w];
1007 for (Annotation[] chnk : annels)
1009 System.arraycopy(chnk, 0, alignmentAnnotation.annotations, w,
1016 alignmentAnnotation.restrict(start, end);
1020 LOCK.readLock().unlock();
1026 * @return true if there are columns hidden
1028 public boolean hasHiddenColumns()
1032 LOCK.readLock().lock();
1033 return hiddenColumns != null && hiddenColumns.size() > 0;
1036 LOCK.readLock().unlock();
1042 * @return true if there are more than one set of columns hidden
1044 public boolean hasManyHiddenColumns()
1048 LOCK.readLock().lock();
1049 return hiddenColumns != null && hiddenColumns.size() > 1;
1052 LOCK.readLock().unlock();
1057 * mark the columns corresponding to gap characters as hidden in the column
1062 public void hideInsertionsFor(SequenceI sr)
1066 LOCK.writeLock().lock();
1067 List<int[]> inserts = sr.getInsertions();
1068 for (int[] r : inserts)
1070 hideColumns(r[0], r[1]);
1074 LOCK.writeLock().unlock();
1079 * Unhides, and adds to the selection list, all hidden columns
1081 public void revealAllHiddenColumns(ColumnSelection sel)
1085 LOCK.writeLock().lock();
1086 if (hiddenColumns != null)
1088 for (int i = 0; i < hiddenColumns.size(); i++)
1090 int[] region = hiddenColumns.get(i);
1091 for (int j = region[0]; j < region[1] + 1; j++)
1098 hiddenColumns = null;
1101 LOCK.writeLock().unlock();
1106 * Reveals, and marks as selected, the hidden column range with the given
1111 public void revealHiddenColumns(int start, ColumnSelection sel)
1115 LOCK.writeLock().lock();
1116 for (int i = 0; i < hiddenColumns.size(); i++)
1118 int[] region = hiddenColumns.get(i);
1119 if (start == region[0])
1121 for (int j = region[0]; j < region[1] + 1; j++)
1126 hiddenColumns.remove(region);
1130 if (hiddenColumns.size() == 0)
1132 hiddenColumns = null;
1136 LOCK.writeLock().unlock();
1141 * Add gaps into the sequences aligned to profileseq under the given
1146 * - alignment to have gaps inserted into it
1148 * - alignment view where sequence corresponding to profileseq is
1150 * @return new HiddenColumns for new alignment view, with insertions into
1151 * profileseq marked as hidden.
1153 public static HiddenColumns propagateInsertions(SequenceI profileseq,
1154 AlignmentI al, AlignmentView input)
1158 char gc = al.getGapCharacter();
1159 Object[] alandhidden = input.getAlignmentAndHiddenColumns(gc);
1160 HiddenColumns nview = (HiddenColumns) alandhidden[1];
1161 SequenceI origseq = ((SequenceI[]) alandhidden[0])[profsqpos];
1162 nview.propagateInsertions(profileseq, al, origseq);
1169 * - sequence in al which corresponds to origseq
1171 * - alignment which is to have gaps inserted into it
1173 * - sequence corresponding to profileseq which defines gap map for
1176 private void propagateInsertions(SequenceI profileseq, AlignmentI al,
1179 char gc = al.getGapCharacter();
1181 // take the set of hidden columns, and the set of gaps in origseq,
1182 // and remove all the hidden gaps from hiddenColumns
1184 // first get the gaps as a Bitset
1185 BitSet gaps = origseq.gapBitset();
1187 // now calculate hidden ^ not(gap)
1188 BitSet hidden = new BitSet();
1189 markHiddenRegions(hidden);
1190 hidden.andNot(gaps);
1191 hiddenColumns = null;
1192 this.hideMarkedBits(hidden);
1194 // for each sequence in the alignment, except the profile sequence,
1195 // insert gaps corresponding to each hidden region
1196 // but where each hidden column region is shifted backwards by the number of
1197 // preceding visible gaps
1198 // update hidden columns at the same time
1199 ArrayList<int[]> regions = getHiddenColumnsCopy();
1200 ArrayList<int[]> newhidden = new ArrayList<>();
1202 int numGapsBefore = 0;
1203 int gapPosition = 0;
1204 for (int[] region : regions)
1206 // get region coordinates accounting for gaps
1207 // we can rely on gaps not being *in* hidden regions because we already
1209 while (gapPosition < region[0])
1212 if (gaps.get(gapPosition))
1218 int left = region[0] - numGapsBefore;
1219 int right = region[1] - numGapsBefore;
1220 newhidden.add(new int[] { left, right });
1222 // make a string with number of gaps = length of hidden region
1223 StringBuffer sb = new StringBuffer();
1224 for (int s = 0; s < right - left + 1; s++)
1228 padGaps(sb, left, profileseq, al);
1231 hiddenColumns = newhidden;
1235 * Pad gaps in all sequences in alignment except profileseq
1238 * gap string to insert
1240 * position to insert at
1242 * sequence not to pad
1244 * alignment to pad sequences in
1246 private void padGaps(StringBuffer sb, int pos, SequenceI profileseq,
1249 // loop over the sequences and pad with gaps where required
1250 for (int s = 0, ns = al.getHeight(); s < ns; s++)
1252 SequenceI sqobj = al.getSequenceAt(s);
1253 if (sqobj != profileseq)
1255 String sq = al.getSequenceAt(s).getSequenceAsString();
1256 if (sq.length() <= pos)
1259 int diff = pos - sq.length() - 1;
1264 while ((diff = pos - sq.length() - 1) > 0)
1266 if (diff >= sb.length())
1268 sq += sb.toString();
1272 char[] buf = new char[diff];
1273 sb.getChars(0, diff, buf, 0);
1274 sq += buf.toString();
1278 sq += sb.toString();
1282 al.getSequenceAt(s).setSequence(
1283 sq.substring(0, pos) + sb.toString() + sq.substring(pos));
1290 * Returns a hashCode built from hidden column ranges
1293 public int hashCode()
1297 LOCK.readLock().lock();
1299 if (hiddenColumns != null)
1301 for (int[] hidden : hiddenColumns)
1303 hashCode = HASH_MULTIPLIER * hashCode + hidden[0];
1304 hashCode = HASH_MULTIPLIER * hashCode + hidden[1];
1310 LOCK.readLock().unlock();
1315 * Hide columns corresponding to the marked bits
1318 * - columns map to bits starting from zero
1320 public void hideMarkedBits(BitSet inserts)
1324 LOCK.writeLock().lock();
1325 for (int firstSet = inserts
1326 .nextSetBit(0), lastSet = 0; firstSet >= 0; firstSet = inserts
1327 .nextSetBit(lastSet))
1329 lastSet = inserts.nextClearBit(firstSet);
1330 hideColumns(firstSet, lastSet - 1);
1334 LOCK.writeLock().unlock();
1341 * BitSet where hidden columns will be marked
1343 public void markHiddenRegions(BitSet inserts)
1347 LOCK.readLock().lock();
1348 if (hiddenColumns == null)
1352 for (int[] range : hiddenColumns)
1354 inserts.set(range[0], range[1] + 1);
1358 LOCK.readLock().unlock();
1363 * Calculate the visible start and end index of an alignment.
1366 * full alignment width
1367 * @return integer array where: int[0] = startIndex, and int[1] = endIndex
1369 public int[] getVisibleStartAndEndIndex(int width)
1373 LOCK.readLock().lock();
1374 int[] alignmentStartEnd = new int[] { 0, width - 1 };
1375 int startPos = alignmentStartEnd[0];
1376 int endPos = alignmentStartEnd[1];
1378 int[] lowestRange = new int[] { -1, -1 };
1379 int[] higestRange = new int[] { -1, -1 };
1381 if (hiddenColumns == null)
1383 return new int[] { startPos, endPos };
1386 for (int[] hiddenCol : hiddenColumns)
1388 lowestRange = (hiddenCol[0] <= startPos) ? hiddenCol : lowestRange;
1389 higestRange = (hiddenCol[1] >= endPos) ? hiddenCol : higestRange;
1392 if (lowestRange[0] == -1 && lowestRange[1] == -1)
1394 startPos = alignmentStartEnd[0];
1398 startPos = lowestRange[1] + 1;
1401 if (higestRange[0] == -1 && higestRange[1] == -1)
1403 endPos = alignmentStartEnd[1];
1407 endPos = higestRange[0] - 1;
1409 return new int[] { startPos, endPos };
1412 LOCK.readLock().unlock();
1418 * Finds the hidden region (if any) which starts or ends at res
1421 * visible residue position, unadjusted for hidden columns
1422 * @return region as [start,end] or null if no matching region is found
1424 public int[] getRegionWithEdgeAtRes(int res)
1428 LOCK.readLock().lock();
1429 int adjres = adjustForHiddenColumns(res);
1431 int[] reveal = null;
1432 if (hiddenColumns != null)
1434 for (int[] region : hiddenColumns)
1436 if (adjres + 1 == region[0] || adjres - 1 == region[1])
1446 LOCK.readLock().unlock();