public static final int DELETE_GAP = 1;
public static final int CUT = 2;
public static final int PASTE = 3;
+ public static final int REPLACE = 4;
Edit[] edits;
performEdit(0);
}
+ public EditCommand(String description,
+ int command,
+ String replace,
+ SequenceI[] seqs,
+ int position,
+ int number,
+ AlignmentI al)
+ {
+ this.description = description;
+ if (command == REPLACE)
+ {
+ edits = new Edit[]
+ { new Edit(command, seqs, position, number, al, replace)};
+ }
+
+ performEdit(0);
+ }
+
final public String getDescription()
{
return description;
int eSize = edits.length;
for (int e = commandIndex; e < eSize; e++)
{
- if (edits[e].command == INSERT_GAP)
+ switch(edits[e].command)
{
+ case INSERT_GAP:
insertGap(edits[e]);
- }
- else if (edits[e].command == DELETE_GAP)
- {
+ break;
+ case DELETE_GAP:
deleteGap(edits[e]);
- }
- else if (edits[e].command == CUT)
- {
+ break;
+ case CUT:
cut(edits[e]);
- }
- else if (edits[e].command == PASTE)
- {
+ break;
+ case PASTE:
paste(edits[e]);
+ break;
+ case REPLACE:
+ replace(edits[e]);
+ break;
}
}
}
int e = 0, eSize = edits.length;
for (e = eSize - 1; e > -1; e--)
{
- if (edits[e].command == INSERT_GAP)
+ switch (edits[e].command)
{
+ case INSERT_GAP:
deleteGap(edits[e]);
- }
- else if (edits[e].command == DELETE_GAP)
- {
+ break;
+ case DELETE_GAP:
insertGap(edits[e]);
- }
- else if (edits[e].command == CUT)
- {
+ break;
+ case CUT:
paste(edits[e]);
- }
- else if (edits[e].command == PASTE)
- {
+ break;
+ case PASTE:
cut(edits[e]);
+ break;
+ case REPLACE:
+ replace(edits[e]);
+ break;
}
}
}
command.string = null;
}
+ void replace(Edit command)
+ {
+ StringBuffer tmp;
+ String oldstring;
+ int start = command.position;
+ int end = command.number;
+
+ command.number = start + command.string[0].length;
+ for (int i = 0; i < command.seqs.length; i++)
+ {
+ oldstring = command.seqs[i].getSequenceAsString();
+ tmp = new StringBuffer(oldstring.substring(0, start));
+ tmp.append(command.string[i]);
+ tmp.append(oldstring.substring(end));
+ command.seqs[i].setSequence(tmp.toString());
+ command.string[i] = oldstring.substring(start, end).toCharArray();
+ tmp = null;
+ oldstring = null;
+ }
+ }
+
final void adjustAnnotations(Edit command, boolean insert, boolean modifyVisibility)
{
AlignmentAnnotation[] tmp;
for (int s = 0; s < command.seqs.length; s++)
{
- if (modifyVisibility)
+ if (modifyVisibility)
{
// Rows are only removed or added to sequence object.
if (!insert) {
}
int tSize = 0;
-
+ if (annotations[a].annotations == null)
+ {
+ // nothing to edit here ?
+ continue;
+ }
aSize = annotations[a].annotations.length;
if (insert)
{
temp = new Annotation[aSize + command.number];
+ if(annotations[a].padGaps)
+ for (int aa = 0; aa < temp.length; aa++)
+ {
+ temp[aa] = new Annotation(
+ command.gapChar+"",
+ null, ' ', 0);
+ }
}
else
{
fullAlignmentHeight = (al.getHeight() == seqs.length);
}
- }
+ Edit(int command,
+ SequenceI[] seqs,
+ int position,
+ int number,
+ AlignmentI al,
+ String replace)
+ {
+ this.command = command;
+ this.seqs = seqs;
+ this.position = position;
+ this.number = number;
+ this.al = al;
+ this.gapChar = al.getGapCharacter();
+ string = new char[seqs.length][];
+ for (int i = 0; i < seqs.length; i++)
+ {
+ string[i] = replace.toCharArray();
+ }
+
+ fullAlignmentHeight = (al.getHeight() == seqs.length);
+ }
+ }
}