+ public CigarArray(AlignmentI alignment, HiddenColumns hidden,
+ SequenceGroup selectionGroup)
+ {
+ this(constructSeqCigarArray(alignment, selectionGroup));
+ constructFromAlignment(alignment,
+ hidden != null ? hidden.getHiddenColumnsCopy() : null,
+ selectionGroup);
+ }
+
+ private static int[] _calcStartEndBounds(AlignmentI alignment,
+ SequenceGroup selectionGroup)
+ {
+ int[] startend = new int[] { 0, 0, 0 };
+ if (selectionGroup != null)
+ {
+ startend[0] = selectionGroup.getSize();
+ startend[1] = selectionGroup.getStartRes();
+ startend[2] = selectionGroup.getEndRes(); // inclusive for start and end
+ // in
+ // SeqCigar constructor
+ }
+ else
+ {
+ startend[0] = alignment.getHeight();
+ startend[2] = alignment.getWidth() - 1;
+ }
+ return startend;
+ }
+
+ public static SeqCigar[] constructSeqCigarArray(AlignmentI alignment,
+ SequenceGroup selectionGroup)
+ {
+ SequenceI[] seqs = null;
+ int i, iSize;
+ int _startend[] = _calcStartEndBounds(alignment, selectionGroup);
+ int start = _startend[1], end = _startend[2];
+ if (selectionGroup != null)
+ {
+ iSize = selectionGroup.getSize();
+ seqs = selectionGroup.getSequencesInOrder(alignment);
+ start = selectionGroup.getStartRes();
+ end = selectionGroup.getEndRes(); // inclusive for start and end in
+ // SeqCigar constructor
+ }
+ else
+ {
+ iSize = alignment.getHeight();
+ seqs = alignment.getSequencesArray();
+ end = alignment.getWidth() - 1;
+ }
+ SeqCigar[] selseqs = new SeqCigar[iSize];
+ for (i = 0; i < iSize; i++)
+ {
+ selseqs[i] = new SeqCigar(seqs[i], start, end);
+ }
+ return selseqs;
+ }
+
+ /**
+ * internal constructor function - called by CigarArray(AlignmentI, ...);
+ *
+ * @param alignment
+ * @param list
+ * - vector of visible regions as returned from
+ * columnSelection.getHiddenColumns()
+ * @param selectionGroup
+ */
+ private void constructFromAlignment(AlignmentI alignment,
+ List<int[]> list, SequenceGroup selectionGroup)
+ {
+ int[] _startend = _calcStartEndBounds(alignment, selectionGroup);
+ int start = _startend[1], end = _startend[2];
+ // now construct the CigarArray operations
+ if (list != null)
+ {
+ int[] region;
+ int hideStart, hideEnd;
+ int last = start;
+ for (int j = 0; last < end & j < list.size(); j++)
+ {
+ region = list.get(j);
+ hideStart = region[0];
+ hideEnd = region[1];
+ // edit hidden regions to selection range
+
+ // just move on if hideEnd is before last
+ if (hideEnd < last)
+ {
+ continue;
+ }
+ // exit if next region is after end
+ if (hideStart > end)
+ {
+ break;
+ }
+
+ // truncate region at start if last falls in region
+ if ((hideStart < last) && (hideEnd >= last))