2828import org .biojava .nbio .core .sequence .compound .AminoAcidCompoundSet ;
2929import org .biojava .nbio .core .sequence .compound .DNACompoundSet ;
3030import 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
3437import java .util .ArrayList ;
38+ import java .util .Arrays ;
3539import 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}
0 commit comments