command.oldds = new SequenceI[command.seqs.length];
}
command.oldds[i] = oldds;
+ if (oldds != sequence.getDatasetSequence())
+ {
+ oldds.getFeatures().deleteAll();
+ }
if (cutPositions != null)
{
*/
static void paste(Edit command, AlignmentI[] views)
{
- StringBuffer tmp;
- boolean newDSNeeded;
- boolean newDSWasNeeded;
- int newstart, newend;
boolean seqWasDeleted = false;
- int start = 0, end = 0;
for (int i = 0; i < command.seqs.length; i++)
{
- newDSNeeded = false;
- newDSWasNeeded = command.oldds != null && command.oldds[i] != null;
+ int start = 0;
+ int end = 0;
+ boolean newDSNeeded = false;
+ boolean newDSWasNeeded = command.oldds != null
+ && command.oldds[i] != null;
SequenceI sequence = command.seqs[i];
if (sequence.getLength() < 1)
{
- // ie this sequence was deleted, we need to
- // readd it to the alignment
+ /*
+ * sequence was deleted; re-add it to the alignment
+ */
if (command.alIndex[i] < command.al.getHeight())
{
List<SequenceI> sequences;
}
seqWasDeleted = true;
}
- newstart = sequence.getStart();
- newend = sequence.getEnd();
+ int newStart = sequence.getStart();
+ int newEnd = sequence.getEnd();
- tmp = new StringBuffer();
+ StringBuilder tmp = new StringBuilder();
tmp.append(sequence.getSequence());
// Undo of a delete does not replace original dataset sequence on to
// alignment sequence.
}
if (sequence.getStart() == start)
{
- newstart--;
+ newStart--;
}
else
{
- newend++;
+ newEnd++;
}
}
}
}
sequence.setSequence(tmp.toString());
- sequence.setStart(newstart);
- sequence.setEnd(newend);
+ sequence.setStart(newStart);
+ sequence.setEnd(newEnd);
+
+ /*
+ * command and Undo share the same dataset sequence if cut was
+ * at start or end of sequence
+ */
+ boolean sameDatasetSequence = false;
if (newDSNeeded)
{
if (sequence.getDatasetSequence() != null)
command.oldds = new SequenceI[command.seqs.length];
}
command.oldds[i] = sequence.getDatasetSequence();
+ sameDatasetSequence = ds == sequence.getDatasetSequence();
+ ds.setSequenceFeatures(sequence.getSequenceFeatures());
sequence.setDatasetSequence(ds);
}
- undoCutFeatures(command, i, start, end);
+ undoCutFeatures(command, i, start, end, sameDatasetSequence);
}
}
adjustAnnotations(command, true, seqWasDeleted, views);
}
final static void undoCutFeatures(Edit command, int index, final int i,
- final int j)
+ final int j, boolean sameDatasetSequence)
{
SequenceI seq = command.seqs[index];
SequenceI sequence = seq.getDatasetSequence();
}
/*
- * TODO: shift right features that lie to the right of the restored cut
- * Currently not needed as all features restored with saved dataset sequence
- * nor if no saved dataset sequence (as coordinates left unchanged by Cut)
+ * shift right features that lie to the right of the restored cut
+ * (but not if dataset sequence unchanged - coordinates left unchanged by Cut)
*/
+ if (!sameDatasetSequence)
+ {
+ seq.getFeatures().shiftFeatures(i + 1, j - i);
+ }
/*
* restore any features that were deleted or truncated
* truncate left, adjust end of feature
*/
newBegin = cutIsInternal ? cutStartPos : cutEndPos + 1;
- // newEnd = newBegin + (sfEnd - sfBegin) - overlapsBy;
newEnd = newBegin + sfEnd - cutEndPos - 1;
if (sf.isContactFeature())
{