2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.analysis;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertNull;
26 import jalview.datamodel.Mapping;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceI;
29 import jalview.gui.JvOptionPane;
31 import java.io.PrintStream;
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.BeforeMethod;
35 import org.testng.annotations.Test;
38 * Test the alignment -> Mapping routines
43 public class TestAlignSeq
45 private static final String NL = System.lineSeparator();
47 @BeforeClass(alwaysRun = true)
48 public void setUpJvOptionPane()
50 JvOptionPane.setInteractiveMode(false);
51 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
57 * @throws java.lang.Exception
59 @BeforeMethod(alwaysRun = true)
60 public void setUp() throws Exception
62 s1 = new Sequence("Seq1", "ASDFAQQQRRRSSS");
65 s2 = new Sequence("Seq2", "ASDFA");
68 s3 = new Sequence("Seq3", "SDFAQQQSSS");
72 @Test(groups = { "Functional" })
74 * simple test that mapping from alignment corresponds identical positions.
76 public void testGetMappingForS1()
78 AlignSeq as = AlignSeq.doGlobalNWAlignment(s1, s2, AlignSeq.PEP);
79 System.out.println("s1: " + as.getAStr1());
80 System.out.println("s2: " + as.getAStr2());
82 // aligned results match
83 assertEquals("ASDFA", as.getAStr1());
84 assertEquals(as.getAStr1(), as.getAStr2());
86 Mapping s1tos2 = as.getMappingFromS1(false);
87 System.out.println(s1tos2.getMap().toString());
88 for (int i = s2.getStart(); i < s2.getEnd(); i++)
90 System.out.println("Position in s2: " + i
91 + " maps to position in s1: " + s1tos2.getPosition(i));
92 // TODO fails: getCharAt doesn't allow for the start position??
93 // assertEquals(String.valueOf(s2.getCharAt(i)),
94 // String.valueOf(s1.getCharAt(s1tos2.getPosition(i))));
98 @Test(groups = { "Functional" })
99 public void testExtractGaps()
101 assertNull(AlignSeq.extractGaps(null, null));
102 assertNull(AlignSeq.extractGaps(". -", null));
103 assertNull(AlignSeq.extractGaps(null, "AB-C"));
105 assertEquals("ABCD", AlignSeq.extractGaps(" .-", ". -A-B.C D."));
108 @Test(groups = { "Functional" })
109 public void testPrintAlignment()
111 AlignSeq as = AlignSeq.doGlobalNWAlignment(s1, s3, AlignSeq.PEP);
113 // s1 = new Sequence("Seq1", "ASDFAQQQRRRSSS");
116 // s3 = new Sequence("Seq3", "SDFAQQQSSS");
118 final StringBuilder baos = new StringBuilder();
119 PrintStream ps = new PrintStream(System.out)
122 public void print(String x)
128 public void println()
134 as.printAlignment(ps);
135 String expected = "Score = 320.0" + NL + "Length of alignment = 10" + NL
136 + "Sequence Seq1/4-13 (Sequence length = 14)" + NL
137 + "Sequence Seq3/1-10 (Sequence length = 10)" + NL + NL
138 + "Seq1/4-13 SDFAQQQRRR" + NL + " ||||||| " + NL
139 + "Seq3/1-10 SDFAQQQSSS" + NL + NL + "Percentage ID = 70.00"
142 String s = baos.toString();
143 System.out.println(s);
145 assertEquals(expected, s);