+ sequence = seq;
+
+ /*
+ * always hold in forwards order, even if given in reverse order
+ * (such as from a mapping to a reverse strand); this avoids
+ * trouble for routines that highlight search results etc
+ */
+ if (start <= end)
+ {
+ this.start = start;
+ this.end = end;
+ }
+ else
+ {
+ this.start = end;
+ this.end = start;
+ }
+ }
+
+ public SequenceI getSequence()
+ {
+ return sequence;
+ }
+
+ public int getStart()
+ {
+ return start;
+ }
+
+ public int getEnd()
+ {
+ return end;
+ }
+
+ /**
+ * Returns the string of characters in the matched region, prefixed by the
+ * start position, e.g. "12CGT" or "208K"
+ */
+ @Override
+ public String toString()
+ {
+ final int from = Math.max(start - 1, 0);
+ String startPosition = String.valueOf(from);
+ return startPosition + getCharacters();
+ }
+
+ /**
+ * Returns the string of characters in the matched region.
+ */
+ public String getCharacters()
+ {
+ char[] chars = sequence.getSequence();
+ // convert start/end to base 0 (with bounds check)
+ final int from = Math.max(start - 1, 0);
+ final int to = Math.min(end, chars.length + 1);
+ return String.valueOf(Arrays.copyOfRange(chars, from, to));
+ }
+
+ public void setSequence(SequenceI seq)
+ {
+ this.sequence = seq;