Skip to content

Commit 3c045a7

Browse files
committed
test MSA
1 parent 4b33b8f commit 3c045a7

3 files changed

Lines changed: 60 additions & 11 deletions

File tree

biojava-core/src/main/java/org/biojava/nbio/core/sequence/MultipleSequenceAlignment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public String toString() {
180180
// helper methods
181181

182182
/**
183-
* Helper method that does all the formating work
183+
* Helper method that does all the formatting work
184184
* @param width
185185
* @param header
186186
* @param idFormat

biojava-core/src/test/java/org/biojava/nbio/core/sequence/MultipleSequenceAlignmentTest.java

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,34 @@
2828
import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet;
2929
import org.biojava.nbio.core.sequence.compound.DNACompoundSet;
3030
import org.biojava.nbio.core.sequence.compound.NucleotideCompound;
31-
import org.junit.Before;
32-
import org.junit.Test;
31+
import org.biojava.nbio.core.sequence.template.LightweightProfile;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.params.ParameterizedTest;
35+
import org.junit.jupiter.params.provider.EnumSource;
3336

3437
import java.util.ArrayList;
38+
import java.util.Arrays;
3539
import java.util.List;
40+
import java.util.Set;
41+
import java.util.stream.Collectors;
3642

37-
import static org.junit.Assert.assertEquals;
43+
import static org.junit.jupiter.api.Assertions.*;
3844

39-
public class MultipleSequenceAlignmentTest {
45+
46+
class MultipleSequenceAlignmentTest {
4047

4148
private MultipleSequenceAlignment<ProteinSequence, AminoAcidCompound> msaProteins;
4249
private MultipleSequenceAlignment<DNASequence,NucleotideCompound> msaDNA;
4350

44-
@Before
45-
public void setup() throws CompoundNotFoundException {
51+
private static final String aaSeq = "ARNDCEQGHILKMFPSTWYVBZJX";
52+
@BeforeEach
53+
void setup() throws CompoundNotFoundException {
4654
msaProteins = new MultipleSequenceAlignment<>();
4755
for (int i = 0; i < 8; i++) {
48-
msaProteins.addAlignedSequence(new ProteinSequence("ARNDCEQGHILKMFPSTWYVBZJX"));
56+
ProteinSequence ps = new ProteinSequence(aaSeq);
57+
ps.setAccession(new AccessionID(i+""));
58+
msaProteins.addAlignedSequence(ps);
4959
}
5060
msaDNA = new MultipleSequenceAlignment<>();
5161
for (int i = 0; i < 7; i++) {
@@ -54,7 +64,46 @@ public void setup() throws CompoundNotFoundException {
5464
}
5565

5666
@Test
57-
public void testGetCompoundsAt() {
67+
void allSequencesMustBeSameLength() throws CompoundNotFoundException {
68+
ProteinSequence differentLength = new ProteinSequence("ARNDC");
69+
assertThrows(IllegalArgumentException.class, ()->msaProteins.addAlignedSequence(differentLength));
70+
}
71+
72+
@Test
73+
void addRemoveAlignments() throws CompoundNotFoundException {
74+
assertEquals(8, msaProteins.getSize());
75+
assertEquals(8, msaProteins.getAlignedSequences().size());
76+
assertEquals(aaSeq.length(), msaProteins.getLength());
77+
msaProteins.removeAlignedSequence(new ProteinSequence(aaSeq));
78+
assertEquals(7, msaProteins.getSize());
79+
assertEquals(7, msaProteins.getAlignedSequences().size());
80+
}
81+
82+
@ParameterizedTest
83+
@EnumSource(LightweightProfile.StringFormat.class)
84+
void formattedAlignmentToString(LightweightProfile.StringFormat format){
85+
String formatted = msaProteins.toString(format);
86+
assertTrue(formatted.length() > 0);
87+
}
88+
89+
@Test
90+
void alignmentToBasicString(){
91+
String alnStr = msaProteins.toString();
92+
String [] lines = alnStr.split(System.lineSeparator());
93+
assertEquals(8, lines.length);
94+
95+
//lines all same length
96+
Set<Integer> collect = Arrays.stream(lines).map(String::length).collect(Collectors.toSet());
97+
assertEquals(1, collect.size());
98+
}
99+
@Test
100+
void alignmentToWidth() {
101+
String alnStr = msaProteins.toString(10);
102+
assertEquals(29, alnStr.split(System.lineSeparator()).length);
103+
}
104+
105+
@Test
106+
void testGetCompoundsAt() {
58107
AminoAcidCompound aminoAcid = AminoAcidCompoundSet.getAminoAcidCompoundSet().getCompoundForString("N");
59108
List<AminoAcidCompound> colProteins = new ArrayList<>();
60109
for (int i = 0; i < 8; i++) {
@@ -69,4 +118,5 @@ public void testGetCompoundsAt() {
69118
assertEquals(msaDNA.getCompoundsAt(3), colDNA);
70119
}
71120

121+
72122
}

biojava-core/src/test/java/org/biojava/nbio/core/sequence/SequenceTestUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public class SequenceTestUtils {
1515
*/
1616
static GeneSequence anyGeneSequence() throws CompoundNotFoundException {
1717
ChromosomeSequence chr = new ChromosomeSequence(ChromosomeSequenceTest.CHROMOSOME_SEQ);
18-
GeneSequence gene = new GeneSequence(chr, new AccessionID("someGeneId"), 10, 200, Strand.POSITIVE);
19-
return gene;
18+
return new GeneSequence(chr, new AccessionID("someGeneId"), 10, 200, Strand.POSITIVE);
2019
}
2120

2221
/**

0 commit comments

Comments
 (0)