{
fixedColumns = true;
int y1 = av.getAlignment().getHiddenColumns()
- .getHiddenBoundaryLeft(startres);
+ .getNextHiddenBoundary(true, startres);
int y2 = av.getAlignment().getHiddenColumns()
- .getHiddenBoundaryRight(startres);
+ .getNextHiddenBoundary(false, startres);
if ((insertGap && startres > y1 && lastres < y1)
|| (!insertGap && startres < y2 && lastres > y2))
if (sg.getSize() == av.getAlignment().getHeight())
{
if ((av.hasHiddenColumns() && startres < av.getAlignment()
- .getHiddenColumns().getHiddenBoundaryRight(startres)))
+ .getHiddenColumns()
+ .getNextHiddenBoundary(false, startres)))
{
endEditing();
return;
* @return the index of the next hidden column, or alPos if there is no next
* hidden column
*/
- public int getHiddenBoundaryRight(int alPos)
+ public int getNextHiddenBoundary(boolean left, int alPos)
{
try
{
if (!hiddenColumns.isEmpty())
{
int index = cursor.findRegionForColumn(alPos).getRegionIndex();
- if (index < hiddenColumns.size())
+
+ if (left && index > 0)
+ {
+ int[] region = hiddenColumns.get(index - 1);
+ return region[1];
+ }
+ else if (!left && index < hiddenColumns.size())
{
int[] region = hiddenColumns.get(index);
if (alPos < region[0])
}
/**
- * This method returns the leftmost limit of a region of an alignment with
- * hidden columns. In otherwords, the previous hidden column.
- *
- * @param alPos
- * the absolute (visible) alignmentPosition to find the previous
- * hidden column for
- */
- public int getHiddenBoundaryLeft(int alPos)
- {
- try
- {
- LOCK.readLock().lock();
-
- if (!hiddenColumns.isEmpty())
- {
- int index = cursor.findRegionForColumn(alPos).getRegionIndex();
-
- if (index > 0)
- {
- int[] region = hiddenColumns.get(index - 1);
- return region[1];
- }
- }
- return alPos;
- } finally
- {
- LOCK.readLock().unlock();
- }
- }
-
-
- /**
* Answers if a column in the alignment is visible
*
* @param column
}
/**
- * Get the visible sections of a set of sequences
- *
- * @param start
- * sequence position to start from
- * @param end
- * sequence position to end at
- * @param seqs
- * an array of sequences
- * @return an array of strings encoding the visible parts of each sequence
- */
- public String[] getVisibleSequenceStrings(int start, int end,
- SequenceI[] seqs)
- {
- try
- {
- LOCK.readLock().lock();
- int iSize = seqs.length;
- String[] selections = new String[iSize];
- if (!hiddenColumns.isEmpty())
- {
- for (int i = 0; i < iSize; i++)
- {
- StringBuilder visibleSeq = new StringBuilder();
-
- Iterator<int[]> blocks = new VisibleContigsIterator(start,
- end + 1, hiddenColumns);
-
- while (blocks.hasNext())
- {
- int[] block = blocks.next();
- if (blocks.hasNext())
- {
- visibleSeq
- .append(seqs[i].getSequence(block[0], block[1] + 1));
- }
- else
- {
- visibleSeq
- .append(seqs[i].getSequence(block[0], block[1]));
- }
- }
-
- selections[i] = visibleSeq.toString();
- }
- }
- else
- {
- for (int i = 0; i < iSize; i++)
- {
- selections[i] = seqs[i].getSequenceAsString(start, end);
- }
- }
-
- return selections;
- } finally
- {
- LOCK.readLock().unlock();
- }
- }
-
- /**
* Locate the first position visible for this sequence. If seq isn't visible
* then return the position of the left side of the hidden boundary region.
*
import java.util.BitSet;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
return count;
}
+
+ @Override
+ public String getSequenceStringFromIterator(Iterator<int[]> it)
+ {
+ StringBuilder newSequence = new StringBuilder();
+ while (it.hasNext())
+ {
+ int[] block = it.next();
+ if (it.hasNext())
+ {
+ newSequence.append(getSequence(block[0], block[1] + 1));
+ }
+ else
+ {
+ newSequence.append(getSequence(block[0], block[1]));
+ }
+ }
+
+ return newSequence.toString();
+ }
}
import jalview.datamodel.features.SequenceFeaturesI;
import java.util.BitSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Vector;
* @param c2
*/
public int replace(char c1, char c2);
+
+ /**
+ * Returns the sequence string constructed from the substrings of a sequence
+ * defined by the int[] ranges provided by an iterator. E.g. the iterator
+ * could iterate over all visible regions of the alignment
+ *
+ * @param it
+ * the iterator to use
+ * @return a String corresponding to the sequence
+ */
+ public String getSequenceStringFromIterator(Iterator<int[]> it);
}
import java.awt.image.BufferedImage;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Iterator;
import java.util.regex.Pattern;
import javax.swing.JCheckBoxMenuItem;
Alignment ds = new Alignment(dseqs);
if (av.hasHiddenColumns())
{
- omitHidden = av.getAlignment().getHiddenColumns()
- .getVisibleSequenceStrings(0, sq.getLength(), seqs);
+ Iterator<int[]> it = av.getAlignment().getHiddenColumns()
+ .getVisContigsIterator(0, sq.getLength(), false);
+ omitHidden = new String[] { sq.getSequenceStringFromIterator(it) };
}
int[] alignmentStartEnd = new int[] { 0, ds.getWidth() - 1 };
{
fixedColumns = true;
int y1 = av.getAlignment().getHiddenColumns()
- .getHiddenBoundaryLeft(startres);
+ .getNextHiddenBoundary(true, startres);
int y2 = av.getAlignment().getHiddenColumns()
- .getHiddenBoundaryRight(startres);
+ .getNextHiddenBoundary(false, startres);
if ((insertGap && startres > y1 && lastres < y1)
|| (!insertGap && startres < y2 && lastres > y2))
if (sg.getSize() == av.getAlignment().getHeight())
{
if ((av.hasHiddenColumns() && startres < av.getAlignment()
- .getHiddenColumns().getHiddenBoundaryRight(startres)))
+ .getHiddenColumns()
+ .getNextHiddenBoundary(false, startres)))
{
endEditing();
return;
import java.util.Deque;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
if (alignment.getHiddenColumns() != null
&& alignment.getHiddenColumns().hasHiddenColumns())
{
- selection = alignment.getHiddenColumns()
- .getVisibleSequenceStrings(start, end, seqs);
+ for (i = 0; i < iSize; i++)
+ {
+ Iterator<int[]> blocks = alignment.getHiddenColumns()
+ .getVisContigsIterator(start, end + 1, false);
+ selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
+ }
}
else
{
start = hidden.visibleToAbsoluteColumn(start);
}
- end = hidden.getHiddenBoundaryRight(start);
+ end = hidden.getNextHiddenBoundary(false, start);
if (start == end)
{
end = max;
if (hidden != null && hidden.hasHiddenColumns())
{
start = hidden.visibleToAbsoluteColumn(end);
- start = hidden.getHiddenBoundaryLeft(start) + 1;
+ start = hidden.getNextHiddenBoundary(true, start) + 1;
}
} while (end < max);
// hide columns around most of sequence - leave one residue remaining
cs.hideColumns(1, 3);
cs.hideColumns(6, 11);
- assertEquals("-D",
- cs.getVisibleSequenceStrings(0, 5, new SequenceI[]
- { seq })[0]);
+
+ Iterator<int[]> it = cs.getVisContigsIterator(0, 6, false);
+
+ assertEquals("-D", seq.getSequenceStringFromIterator(it));
+ // cs.getVisibleSequenceStrings(0, 5, new SequenceI[]
+ // { seq })[0]);
assertEquals(1, cs.locateVisibleStartOfSequence(seq));
cs.revealAllHiddenColumns(colsel);
HiddenColumns h = new HiddenColumns();
// returns same value if no hidden cols
- assertEquals(3, h.getHiddenBoundaryLeft(3));
+ assertEquals(3, h.getNextHiddenBoundary(true, 3));
h.hideColumns(5, 10);
- assertEquals(10, h.getHiddenBoundaryLeft(15));
- assertEquals(3, h.getHiddenBoundaryLeft(3));
- assertEquals(7, h.getHiddenBoundaryLeft(7));
+ assertEquals(10, h.getNextHiddenBoundary(true, 15));
+ assertEquals(3, h.getNextHiddenBoundary(true, 3));
+ assertEquals(7, h.getNextHiddenBoundary(true, 7));
h.hideColumns(15, 20);
- assertEquals(10, h.getHiddenBoundaryLeft(15));
- assertEquals(20, h.getHiddenBoundaryLeft(21));
+ assertEquals(10, h.getNextHiddenBoundary(true, 15));
+ assertEquals(20, h.getNextHiddenBoundary(true, 21));
}
@Test(groups = "Functional")
- public void testGetHiddenBoundaryRight()
+ public void testGetNextHiddenBoundary()
{
HiddenColumns h = new HiddenColumns();
// returns same value if no hidden cols
- assertEquals(3, h.getHiddenBoundaryRight(3));
+ assertEquals(3, h.getNextHiddenBoundary(false, 3));
h.hideColumns(5, 10);
- assertEquals(5, h.getHiddenBoundaryRight(3));
- assertEquals(15, h.getHiddenBoundaryRight(15));
- assertEquals(7, h.getHiddenBoundaryRight(7));
+ assertEquals(5, h.getNextHiddenBoundary(false, 3));
+ assertEquals(15, h.getNextHiddenBoundary(false, 15));
+ assertEquals(7, h.getNextHiddenBoundary(false, 7));
h.hideColumns(15, 20);
- assertEquals(15, h.getHiddenBoundaryRight(7));
- assertEquals(15, h.getHiddenBoundaryRight(14));
+ assertEquals(15, h.getNextHiddenBoundary(false, 7));
+ assertEquals(15, h.getNextHiddenBoundary(false, 14));
// returns same value if there is no next hidden column
- assertEquals(22, h.getHiddenBoundaryRight(22));
+ assertEquals(22, h.getNextHiddenBoundary(false, 22));
}
@Test(groups = "Functional")
assertFalse(result.hasNext());
}
- @Test(groups = "Functional")
+ /* @Test(groups = "Functional")
public void testGetVisibleSequenceStrings()
{
HiddenColumns h = new HiddenColumns();
assertEquals(2, result.length);
assertEquals("WKQES", result[0]);
assertEquals("RNDTG", result[1]);
-
+
h.hideColumns(6, 8);
result = h.getVisibleSequenceStrings(5, 10, seqs);
assertEquals(2, result.length);
assertEquals("WS", result[0]);
assertEquals("RG", result[1]);
-
+
SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---");
ColumnSelection sel = new ColumnSelection();
h.revealAllHiddenColumns(sel);
assertEquals("-D",
h.getVisibleSequenceStrings(0, 5, new SequenceI[]
{ seq })[0]);
- }
+ }*/
@Test(groups = "Functional")
public void testHideInsertionsFor()