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.io.gff;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.gui.JvOptionPane;
29 import java.util.Arrays;
30 import java.util.List;
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.Test;
36 public class GffHelperBaseTest
39 @BeforeClass(alwaysRun = true)
40 public void setUpJvOptionPane()
42 JvOptionPane.setInteractiveMode(false);
43 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
47 * Test the method that parses lines like <br>
48 * ID=2345;Name=Something,Another thing;Notes=Hello;Notes=World
50 @Test(groups = { "Functional" })
51 public void testParseNameValuePairs()
53 assertTrue(GffHelperBase.parseNameValuePairs(null, ";", ' ', ",")
55 assertTrue(GffHelperBase.parseNameValuePairs("", ";", ' ', ",")
57 assertTrue(GffHelperBase.parseNameValuePairs("hello=world", ";", ' ',
60 Map<String, List<String>> map = GffHelperBase.parseNameValuePairs(
61 "hello world", ";", ' ', ", ");
62 assertEquals(1, map.size());
63 assertEquals(1, map.get("hello").size());
64 assertEquals("world", map.get("hello").get(0));
68 "Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny; Type=",
71 // Type is ignored as no value was supplied
72 assertEquals(2, map.size());
74 assertEquals(1, map.get("Method").size());
75 assertEquals("manual curation", map.get("Method").get(0)); // trimmed
77 assertEquals(3, map.get("Notes").size());
78 assertEquals("F2 S", map.get("Notes").get(0));
79 assertEquals("Metal", map.get("Notes").get(1));
80 assertEquals("Shiny", map.get("Notes").get(2));
84 * Test for the method that tries to trim mappings to equivalent lengths
86 @Test(groups = "Functional")
87 public void testTrimMapping()
89 int[] from = { 1, 12 };
90 int[] to = { 20, 31 };
91 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
92 assertEquals("[1, 12]", Arrays.toString(from)); // unchanged
93 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
96 from = new int[] { 1, 13 };
97 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
98 assertEquals("[1, 12]", Arrays.toString(from)); // trimmed
99 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
102 to = new int[] { 20, 33 };
103 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
104 assertEquals("[1, 12]", Arrays.toString(from)); // unchanged
105 assertEquals("[20, 31]", Arrays.toString(to)); // trimmed
108 from = new int[] { 12, 1 };
109 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
110 assertEquals("[12, 1]", Arrays.toString(from)); // unchanged
111 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
114 to = new int[] { 31, 20 };
115 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
116 assertEquals("[12, 1]", Arrays.toString(from)); // unchanged
117 assertEquals("[31, 20]", Arrays.toString(to)); // unchanged
119 // from reversed and too long:
120 from = new int[] { 14, 1 };
121 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
122 assertEquals("[14, 3]", Arrays.toString(from)); // end trimmed
123 assertEquals("[31, 20]", Arrays.toString(to)); // unchanged
125 // to reversed and too long:
126 to = new int[] { 31, 10 };
127 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
128 assertEquals("[14, 3]", Arrays.toString(from)); // unchanged
129 assertEquals("[31, 20]", Arrays.toString(to)); // end trimmed
131 // cdna to peptide (matching)
132 from = new int[] { 1, 18 };
133 to = new int[] { 4, 9 };
134 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
135 assertEquals("[1, 18]", Arrays.toString(from)); // unchanged
136 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
138 // overlong cdna to peptide
139 from = new int[] { 1, 20 };
140 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
141 assertEquals("[1, 18]", Arrays.toString(from)); // end trimmed
142 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
144 // overlong cdna (reversed) to peptide
145 from = new int[] { 20, 1 };
146 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
147 assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed
148 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
150 // overlong cdna (reversed) to peptide (reversed)
151 from = new int[] { 20, 1 };
152 to = new int[] { 9, 4 };
153 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
154 assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed
155 assertEquals("[9, 4]", Arrays.toString(to)); // unchanged
157 // peptide to cdna (matching)
158 from = new int[] { 4, 9 };
159 to = new int[] { 1, 18 };
160 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
161 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
162 assertEquals("[1, 18]", Arrays.toString(to)); // unchanged
164 // peptide to overlong cdna
165 to = new int[] { 1, 20 };
166 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
167 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
168 assertEquals("[1, 18]", Arrays.toString(to)); // end trimmed
170 // peptide to overlong cdna (reversed)
171 to = new int[] { 20, 1 };
172 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
173 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
174 assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed
176 // peptide (reversed) to overlong cdna (reversed)
177 from = new int[] { 9, 4 };
178 to = new int[] { 20, 1 };
179 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
180 assertEquals("[9, 4]", Arrays.toString(from)); // unchanged
181 assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed
183 // overlong peptide to word-length cdna
184 from = new int[] { 4, 10 };
185 to = new int[] { 1, 18 };
186 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
187 assertEquals("[4, 9]", Arrays.toString(from)); // end trimmed
188 assertEquals("[1, 18]", Arrays.toString(to)); // unchanged
190 // overlong peptide to non-word-length cdna
191 from = new int[] { 4, 10 };
192 to = new int[] { 1, 19 };
193 assertFalse(GffHelperBase.trimMapping(from, to, 1, 3));
194 assertEquals("[4, 10]", Arrays.toString(from)); // unchanged
195 assertEquals("[1, 19]", Arrays.toString(to)); // unchanged