1 package jalview.io.gff;
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertTrue;
7 import java.util.Arrays;
11 import org.testng.annotations.Test;
13 public class GffHelperBaseTest
17 * Test the method that parses lines like <br>
18 * ID=2345;Name=Something,Another thing;Notes=Hello;Notes=World
20 @Test(groups = { "Functional" })
21 public void testParseNameValuePairs()
23 assertTrue(GffHelperBase.parseNameValuePairs(null, ";", ' ', ",")
25 assertTrue(GffHelperBase.parseNameValuePairs("", ";", ' ', ",")
27 assertTrue(GffHelperBase.parseNameValuePairs("hello=world", ";", ' ',
30 Map<String, List<String>> map = GffHelperBase.parseNameValuePairs(
31 "hello world", ";", ' ', ", ");
32 assertEquals(1, map.size());
33 assertEquals(1, map.get("hello").size());
34 assertEquals("world", map.get("hello").get(0));
38 "Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny; Type=",
41 // Type is ignored as no value was supplied
42 assertEquals(2, map.size());
44 assertEquals(1, map.get("Method").size());
45 assertEquals("manual curation", map.get("Method").get(0)); // trimmed
47 assertEquals(3, map.get("Notes").size());
48 assertEquals("F2 S", map.get("Notes").get(0));
49 assertEquals("Metal", map.get("Notes").get(1));
50 assertEquals("Shiny", map.get("Notes").get(2));
54 * Test for the method that tries to trim mappings to equivalent lengths
56 @Test(groups = "Functional")
57 public void testTrimMapping()
59 int[] from = { 1, 12 };
60 int[] to = { 20, 31 };
61 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
62 assertEquals("[1, 12]", Arrays.toString(from)); // unchanged
63 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
66 from = new int[] { 1, 13 };
67 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
68 assertEquals("[1, 12]", Arrays.toString(from)); // trimmed
69 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
72 to = new int[] { 20, 33 };
73 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
74 assertEquals("[1, 12]", Arrays.toString(from)); // unchanged
75 assertEquals("[20, 31]", Arrays.toString(to)); // trimmed
78 from = new int[] { 12, 1 };
79 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
80 assertEquals("[12, 1]", Arrays.toString(from)); // unchanged
81 assertEquals("[20, 31]", Arrays.toString(to)); // unchanged
84 to = new int[] { 31, 20 };
85 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
86 assertEquals("[12, 1]", Arrays.toString(from)); // unchanged
87 assertEquals("[31, 20]", Arrays.toString(to)); // unchanged
89 // from reversed and too long:
90 from = new int[] { 14, 1 };
91 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
92 assertEquals("[14, 3]", Arrays.toString(from)); // end trimmed
93 assertEquals("[31, 20]", Arrays.toString(to)); // unchanged
95 // to reversed and too long:
96 to = new int[] { 31, 10 };
97 assertTrue(GffHelperBase.trimMapping(from, to, 1, 1));
98 assertEquals("[14, 3]", Arrays.toString(from)); // unchanged
99 assertEquals("[31, 20]", Arrays.toString(to)); // end trimmed
101 // cdna to peptide (matching)
102 from = new int[] { 1, 18 };
103 to = new int[] { 4, 9 };
104 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
105 assertEquals("[1, 18]", Arrays.toString(from)); // unchanged
106 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
108 // overlong cdna to peptide
109 from = new int[] { 1, 20 };
110 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
111 assertEquals("[1, 18]", Arrays.toString(from)); // end trimmed
112 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
114 // overlong cdna (reversed) to peptide
115 from = new int[] { 20, 1 };
116 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
117 assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed
118 assertEquals("[4, 9]", Arrays.toString(to)); // unchanged
120 // overlong cdna (reversed) to peptide (reversed)
121 from = new int[] { 20, 1 };
122 to = new int[] { 9, 4 };
123 assertTrue(GffHelperBase.trimMapping(from, to, 3, 1));
124 assertEquals("[20, 3]", Arrays.toString(from)); // end trimmed
125 assertEquals("[9, 4]", Arrays.toString(to)); // unchanged
127 // peptide to cdna (matching)
128 from = new int[] { 4, 9 };
129 to = new int[] { 1, 18 };
130 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
131 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
132 assertEquals("[1, 18]", Arrays.toString(to)); // unchanged
134 // peptide to overlong cdna
135 to = new int[] { 1, 20 };
136 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
137 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
138 assertEquals("[1, 18]", Arrays.toString(to)); // end trimmed
140 // peptide to overlong cdna (reversed)
141 to = new int[] { 20, 1 };
142 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
143 assertEquals("[4, 9]", Arrays.toString(from)); // unchanged
144 assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed
146 // peptide (reversed) to overlong cdna (reversed)
147 from = new int[] { 9, 4 };
148 to = new int[] { 20, 1 };
149 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
150 assertEquals("[9, 4]", Arrays.toString(from)); // unchanged
151 assertEquals("[20, 3]", Arrays.toString(to)); // end trimmed
153 // overlong peptide to word-length cdna
154 from = new int[] { 4, 10 };
155 to = new int[] { 1, 18 };
156 assertTrue(GffHelperBase.trimMapping(from, to, 1, 3));
157 assertEquals("[4, 9]", Arrays.toString(from)); // end trimmed
158 assertEquals("[1, 18]", Arrays.toString(to)); // unchanged
160 // overlong peptide to non-word-length cdna
161 from = new int[] { 4, 10 };
162 to = new int[] { 1, 19 };
163 assertFalse(GffHelperBase.trimMapping(from, to, 1, 3));
164 assertEquals("[4, 10]", Arrays.toString(from)); // unchanged
165 assertEquals("[1, 19]", Arrays.toString(to)); // unchanged