3322ee84680fdcf3f98031109d58a8a70b8c6776
[jalview.git] / test / jalview / gui / PairwiseAlignmentPanelTest.java
1 package jalview.gui;
2
3 import static org.testng.Assert.assertEquals;
4
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.SequenceGroup;
7 import jalview.io.DataSourceType;
8 import jalview.io.FileLoader;
9
10 import javax.swing.JTextArea;
11
12 import junit.extensions.PA;
13
14 import org.testng.annotations.Test;
15
16 public class PairwiseAlignmentPanelTest
17 {
18   @Test(groups = "Functional")
19   public void testConstructor_withSelectionGroup()
20   {
21     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
22             "examples/uniref50.fa", DataSourceType.FILE);
23     AlignViewport viewport = af.getViewport();
24     AlignmentI al = viewport.getAlignment();
25
26     /*
27      * select columns 29-36 of sequences 4 and 5 for alignment
28      * Q93XJ9_SOLTU/23-29 L-KAISNV
29      * FER1_PEA/26-32     V-TTTKAF
30      */
31     SequenceGroup sg = new SequenceGroup();
32     sg.addSequence(al.getSequenceAt(3), false);
33     sg.addSequence(al.getSequenceAt(4), false);
34     sg.setStartRes(28);
35     sg.setEndRes(35);
36     viewport.setSelectionGroup(sg);
37
38     PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport);
39
40     String text = ((JTextArea) PA.getValue(testee, "textarea")).getText();
41     String expected = "Score = 80.0\n" + "Length of alignment = 4\n"
42             + "Sequence     FER1_PEA/29-32 (Sequence length = 7)\n"
43             + "Sequence Q93XJ9_SOLTU/23-26 (Sequence length = 7)\n\n"
44             + "    FER1_PEA/29-32 TKAF\n" + "                    ||.\n"
45             + "Q93XJ9_SOLTU/23-26 LKAI\n\n" + "Percentage ID = 50.00\n\n";
46     assertEquals(text, expected);
47   }
48
49   /**
50    * This test aligns the same sequences as testConstructor_withSelectionGroup
51    * but as a complete alignment (no selection). Note that in fact the user is
52    * currently required to make a selection in order to calculate pairwise
53    * alignments, so this case does not arise.
54    */
55   @Test(groups = "Functional")
56   public void testConstructor_noSelectionGroup()
57   {
58     String seqs = ">Q93XJ9_SOLTU/23-29\nL-KAISNV\n>FER1_PEA/26-32\nV-TTTKAF\n";
59     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqs,
60             DataSourceType.PASTE);
61     AlignViewport viewport = af.getViewport();
62
63     PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport);
64
65     String text = ((JTextArea) PA.getValue(testee, "textarea")).getText();
66     String expected = "Score = 80.0\n" + "Length of alignment = 4\n"
67             + "Sequence     FER1_PEA/29-32 (Sequence length = 7)\n"
68             + "Sequence Q93XJ9_SOLTU/23-26 (Sequence length = 7)\n\n"
69             + "    FER1_PEA/29-32 TKAF\n" + "                    ||.\n"
70             + "Q93XJ9_SOLTU/23-26 LKAI\n\n" + "Percentage ID = 50.00\n\n";
71     assertEquals(text, expected);
72   }
73 }