import jalview.datamodel.AlignmentI;
import jalview.datamodel.ContiguousI;
import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
public class JustifyLeftOrRightCommand extends EditCommand
{
{
continue;
}
+ char[] range = seq.getSequence(from, to+1);
+ if (range==null || range.length==0)
+ {
+ continue;
+ }
int dsstart = seq.getDatasetSequence().getStart();
char[] sqchar = seq.getDatasetSequence().getSequence(
-dsstart + cont.getBegin(), -dsstart + cont.getEnd() + 1);
alseq[gapstart + gp] = gc;
}
- for (int sqp = 0; sqp < sqchar.length; sqp++)
+ for (int sqp = 0,insp=0; sqp<alseq.length; sqp++)
{
- alseq[sqp + sqstart] = sqchar[sqp];
+ if (sqp < range.length && !Comparison.isGap(range[sqp]))
+ {
+ alseq[insp++ + sqstart] = range[sqp];
+ }
}
SequenceI[] sqa = new SequenceI[1];
sqa[0] = seq;
addEdit(new jalview.commands.EditCommand.Edit(
jalview.commands.EditCommand.Action.REPLACE, sqa, from,
to + 1, al, new String(alseq)));
- // addEdit(new jalview.commands.EditCommand("justify",
- // jalview.commands.EditCommand.Action.REPLACE,
- // new String(alseq), sqa, from, to + 1, al).getEdit(0));
}
performEdit(0, null);
Alignment al = new Alignment(sqs.toArray(new SequenceI[0]));
EditCommand lefj = new JustifyLeftOrRightCommand("Left J", true, sqs, 1, 7, al);
String exp = "-ABcD---EF";
- assertEquals(exp.toUpperCase(Locale.ROOT),seq1.getSequenceAsString());
+ // check without case conservation
+ assertEquals(exp.toUpperCase(Locale.ROOT),seq1.getSequenceAsString().toUpperCase(Locale.ROOT));
// check case
assertEquals(exp,seq1.getSequenceAsString());
+ // and other seqs
+ assertEquals("-GHiJ---",seq2.getSequenceAsString());
+ assertEquals("-MNoP---Q",seq3.getSequenceAsString());
+ lefj.undoCommand(new AlignmentI[] { al});
+ assertEquals(original3,seq3.getSequenceAsString());
+ assertEquals(original1,seq1.getSequenceAsString());
+ assertEquals(original2,seq2.getSequenceAsString());
+
+ EditCommand righj = new JustifyLeftOrRightCommand("Right J", false, sqs, 2, 7, al);
+ assertEquals("----ABcDEF",seq1.getSequenceAsString());
+ assertEquals("-G---HiJ",seq2.getSequenceAsString());
+ assertEquals("-M---NoPQ",seq3.getSequenceAsString());
+ righj.undoCommand(new AlignmentI[] { al});
+ assertEquals(original3,seq3.getSequenceAsString());
+ assertEquals(original1,seq1.getSequenceAsString());
+ assertEquals(original2,seq2.getSequenceAsString());
+
}
}