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 java.util.Arrays;
28 import java.util.List;
31 import org.testng.annotations.Test;
33 public class GffHelperBaseTest
37 * Test the method that parses lines like <br>
38 * ID=2345;Name=Something,Another thing;Notes=Hello;Notes=World
40 @Test(groups = { "Functional" })
41 public void testParseNameValuePairs()
43 assertTrue(GffHelperBase.parseNameValuePairs(null, ";", ' ', ",")
45 assertTrue(GffHelperBase.parseNameValuePairs("", ";", ' ', ",")
47 assertTrue(GffHelperBase.parseNameValuePairs("hello=world", ";", ' ',
50 Map<String, List<String>> map = GffHelperBase.parseNameValuePairs(
51 "hello world", ";", ' ', ", ");
52 assertEquals(1, map.size());
53 assertEquals(1, map.get("hello").size());
54 assertEquals("world", map.get("hello").get(0));
58 "Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny; Type=",
61 // Type is ignored as no value was supplied
62 assertEquals(2, map.size());
64 assertEquals(1, map.get("Method").size());
65 assertEquals("manual curation", map.get("Method").get(0)); // trimmed
67 assertEquals(3, map.get("Notes").size());
68 assertEquals("F2 S", map.get("Notes").get(0));
69 assertEquals("Metal", map.get("Notes").get(1));
70 assertEquals("Shiny", map.get("Notes").get(2));
74 * Test for the method that tries to trim mappings to equivalent lengths
76 @Test(groups = "Functional")
77 public void testTrimMapping()
79 int[] from = { 1, 12 };
80 int[] to = { 20, 31 };
81 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
82 assertEquals("[1, 12]", Arrays.toString(from)); // unchanged
83 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
86 from = new int[] { 1, 13 };
87 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
88 assertEquals("[1, 12]", Arrays.toString(from)); // trimmed
89 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
92 to = new int[] { 20, 33 };
93 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
94 assertEquals("[1, 12]", Arrays.toString(from)); // unchanged
95 assertEquals("[20, 31]", Arrays.toString(to)); // trimmed
98 from = new int[] { 12, 1 };
99 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
100 assertEquals("[12, 1]", Arrays.toString(from)); // unchanged
101 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
104 to = new int[] { 31, 20 };
105 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
106 assertEquals("[12, 1]", Arrays.toString(from)); // unchanged
107 assertEquals("[31, 20]", Arrays.toString(to)); // unchanged
109 // from reversed and too long:
110 from = new int[] { 14, 1 };
111 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
112 assertEquals("[14, 3]", Arrays.toString(from)); // end trimmed
113 assertEquals("[31, 20]", Arrays.toString(to)); // unchanged
115 // to reversed and too long:
116 to = new int[] { 31, 10 };
117 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
118 assertEquals("[14, 3]", Arrays.toString(from)); // unchanged
119 assertEquals("[31, 20]", Arrays.toString(to)); // end trimmed
121 // cdna to peptide (matching)
122 from = new int[] { 1, 18 };
123 to = new int[] { 4, 9 };
124 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
125 assertEquals("[1, 18]", Arrays.toString(from)); // unchanged
126 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
128 // overlong cdna to peptide
129 from = new int[] { 1, 20 };
130 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
131 assertEquals("[1, 18]", Arrays.toString(from)); // end trimmed
132 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
134 // overlong cdna (reversed) to peptide
135 from = new int[] { 20, 1 };
136 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
137 assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed
138 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
140 // overlong cdna (reversed) to peptide (reversed)
141 from = new int[] { 20, 1 };
142 to = new int[] { 9, 4 };
143 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
144 assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed
145 assertEquals("[9, 4]", Arrays.toString(to)); // unchanged
147 // peptide to cdna (matching)
148 from = new int[] { 4, 9 };
149 to = new int[] { 1, 18 };
150 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
151 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
152 assertEquals("[1, 18]", Arrays.toString(to)); // unchanged
154 // peptide to overlong cdna
155 to = new int[] { 1, 20 };
156 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
157 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
158 assertEquals("[1, 18]", Arrays.toString(to)); // end trimmed
160 // peptide to overlong cdna (reversed)
161 to = new int[] { 20, 1 };
162 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
163 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
164 assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed
166 // peptide (reversed) to overlong cdna (reversed)
167 from = new int[] { 9, 4 };
168 to = new int[] { 20, 1 };
169 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
170 assertEquals("[9, 4]", Arrays.toString(from)); // unchanged
171 assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed
173 // overlong peptide to word-length cdna
174 from = new int[] { 4, 10 };
175 to = new int[] { 1, 18 };
176 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
177 assertEquals("[4, 9]", Arrays.toString(from)); // end trimmed
178 assertEquals("[1, 18]", Arrays.toString(to)); // unchanged
180 // overlong peptide to non-word-length cdna
181 from = new int[] { 4, 10 };
182 to = new int[] { 1, 19 };
183 assertFalse(GffHelperBase.trimMapping(from, to, 1, 3));
184 assertEquals("[4, 10]", Arrays.toString(from)); // unchanged
185 assertEquals("[1, 19]", Arrays.toString(to)); // unchanged