char[] originalSequence = sequence.toCharArray();
int length = originalSequence.length;
char[] reversedSequence = new char[length];
-
+ int bases = 0;
for (int i = 0; i < length; i++)
{
- reversedSequence[length - i - 1] = complement ? getComplement(originalSequence[i])
+ char c = complement ? getComplement(originalSequence[i])
: originalSequence[i];
+ reversedSequence[length - i - 1] = c;
+ if (!Comparison.isGap(c))
+ {
+ bases++;
+ }
}
- SequenceI reversed = new Sequence(newName, reversedSequence, 1, length);
+ SequenceI reversed = new Sequence(newName, reversedSequence, 1, bases);
return reversed;
}
{
char result = c;
switch (c) {
+ case '-':
+ case '.':
+ case ' ':
+ break;
case 'a':
result = 't';
break;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignViewport;
import jalview.io.FormatAdapter;
@Test(groups = "Functional")
public void testReverseSequence()
{
- String seq = "AcGtUrYkMbVdHNX";
+ String seq = "-Ac-GtU--rYkMbVdHNX-";
+ String seqRev = new StringBuilder(seq).reverse().toString();
// reverse:
SequenceI reversed = Dna.reverseSequence("Seq1", seq, false);
- assertEquals(new StringBuilder(seq).reverse()
- .toString(), reversed.getSequenceAsString());
+ assertEquals(1, reversed.getStart());
+ assertEquals(15, reversed.getEnd());
+ assertEquals(20, reversed.getLength());
+ assertEquals(seqRev, reversed.getSequenceAsString());
assertEquals("Seq1|rev", reversed.getName());
// reverse complement:
SequenceI revcomp = Dna.reverseSequence("Seq1", seq, true);
- assertEquals("XNDhBvKmRyAaCgT", revcomp.getSequenceAsString());
+ assertEquals("-XNDhBvKmRy--AaC-gT-", revcomp.getSequenceAsString());
assertEquals("Seq1|revcomp", revcomp.getName());
}
+
+ @Test(groups = "Functional")
+ public void testReverseCdna()
+ {
+ String seq = "-Ac-GtU--rYkMbVdHNX-";
+ String seqRev = new StringBuilder(seq).reverse().toString();
+ String seqDs = seq.replaceAll("-", "");
+ String seqDsRev = new StringBuilder(seqDs).reverse().toString();
+
+ SequenceI dna = new Sequence("Seq1", seq);
+ Alignment al = new Alignment(new SequenceI[] {dna});
+ al.createDatasetAlignment();
+ assertEquals(seqDs, al.getSequenceAt(0).getDatasetSequence()
+ .getSequenceAsString());
+
+ ColumnSelection cs = new ColumnSelection();
+ AlignViewportI av = new AlignViewport(al, cs);
+ Dna testee = new Dna(av, new int[] { 0, al.getWidth() - 1 });
+ AlignmentI reversed = testee.reverseCdna(false);
+ assertEquals(1, reversed.getHeight());
+ assertEquals(seqRev, reversed.getSequenceAt(0).getSequenceAsString());
+ assertEquals(seqDsRev, reversed.getSequenceAt(0).getDatasetSequence()
+ .getSequenceAsString());
+ }
}