X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FCigarArray.java;h=17e9ea6fc65e17faad9b7f76656fa0f1a30cdf68;hb=afffa24481a7d3cb65ae41e0948c16a5f490f302;hp=ef0db4f90ec097f663a3b7e8e3b1bbfde7f26480;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git
diff --git a/src/jalview/datamodel/CigarArray.java b/src/jalview/datamodel/CigarArray.java
index ef0db4f..17e9ea6 100644
--- a/src/jalview/datamodel/CigarArray.java
+++ b/src/jalview/datamodel/CigarArray.java
@@ -1,23 +1,26 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.datamodel;
-import java.util.Vector;
+import java.util.Iterator;
public class CigarArray extends CigarBase
{
@@ -65,7 +68,8 @@ public class CigarArray extends CigarBase
for (int c = 0; c < cigars.length; c++)
{
refCigars[c] = cigars[c];
- if (!((cigars[c] instanceof SeqCigar) || cigars[c] instanceof CigarCigar))
+ if (!((cigars[c] instanceof SeqCigar)
+ || cigars[c] instanceof CigarCigar))
{
seqcigararray = false;
}
@@ -82,20 +86,17 @@ public class CigarArray extends CigarBase
* @param columnSelection
* @param selectionGroup
*/
- public CigarArray(AlignmentI alignment, ColumnSelection columnSelection,
+ public CigarArray(AlignmentI alignment, HiddenColumns hidden,
SequenceGroup selectionGroup)
{
this(constructSeqCigarArray(alignment, selectionGroup));
- constructFromAlignment(alignment,
- columnSelection != null ? columnSelection.getHiddenColumns()
- : null, selectionGroup);
+ constructFromAlignment(alignment, hidden, selectionGroup);
}
private static int[] _calcStartEndBounds(AlignmentI alignment,
SequenceGroup selectionGroup)
{
- int[] startend = new int[]
- { 0, 0, 0 };
+ int[] startend = new int[] { 0, 0, 0 };
if (selectionGroup != null)
{
startend[0] = selectionGroup.getSize();
@@ -145,54 +146,44 @@ public class CigarArray extends CigarBase
* internal constructor function - called by CigarArray(AlignmentI, ...);
*
* @param alignment
- * @param columnSelection
+ * @param list
* - vector of visible regions as returned from
* columnSelection.getHiddenColumns()
* @param selectionGroup
*/
private void constructFromAlignment(AlignmentI alignment,
- Vector columnSelection, SequenceGroup selectionGroup)
+ HiddenColumns hidden, SequenceGroup selectionGroup)
{
int[] _startend = _calcStartEndBounds(alignment, selectionGroup);
- int start = _startend[1], end = _startend[2];
+ int start = _startend[1];
+ int end = _startend[2];
// now construct the CigarArray operations
- if (columnSelection != null)
+ if (hidden != null)
{
int[] region;
- int hideStart, hideEnd;
+ int hideStart;
+ int hideEnd;
int last = start;
- for (int j = 0; last < end & j < columnSelection.size(); j++)
+
+ Iterator regions = hidden.getBoundedIterator(start, end);
+ while (regions.hasNext())
{
- region = (int[]) columnSelection.elementAt(j);
+ region = regions.next();
hideStart = region[0];
hideEnd = region[1];
- // edit hidden regions to selection range
- if (hideStart < last)
- {
- if (hideEnd > last)
- {
- hideStart = last;
- }
- else
- {
- continue;
- }
- }
- if (hideStart > end)
+ // truncate region at start if last falls in region
+ if ((hideStart < last) && (hideEnd >= last))
{
- break;
+ hideStart = last;
}
- if (hideEnd > end)
+ // truncate region at end if end falls in region
+ if (hideEnd > end) // already checked that hideStart<=end
{
hideEnd = end;
}
- if (hideStart > hideEnd)
- {
- break;
- }
/**
* form operations...
*/
@@ -203,8 +194,9 @@ public class CigarArray extends CigarBase
addOperation(CigarArray.D, 1 + hideEnd - hideStart);
last = hideEnd + 1;
}
+
// Final match if necessary.
- if (last < end)
+ if (last <= end)
{
addOperation(CigarArray.M, end - last + 1);
}
@@ -216,7 +208,7 @@ public class CigarArray extends CigarBase
}
/**
- * @see Cigar.getSequenceAndDeletions
+ * @see CigarBase.getSequenceAndDeletions
* @param GapChar
* char
* @return Object[][]
@@ -340,8 +332,11 @@ public class CigarArray extends CigarBase
delpos = new java.util.Vector();
}
int delstart = cursor, delend = cursor + range[i] - 1; // inclusive
- delpos.addElement(new int[]
- { vcursor + offset, range[i] }); // index of right hand column after
+ delpos.addElement(new int[] { vcursor + offset, range[i] }); // index of
+ // right
+ // hand
+ // column
+ // after
// hidden region boundary
offset += range[i] - 1; // shift in visible column coordinates
System.arraycopy(operation, i + 1, operation, i, length - i);