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.
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.JvOptionPane;
31 import jalview.io.gff.GffConstants;
33 import java.util.HashMap;
34 import java.util.Hashtable;
37 import junit.extensions.PA;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.Test;
42 public class SequenceAnnotationReportTest
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 @Test(groups = "Functional")
53 public void testAppendFeature_disulfideBond()
55 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
56 StringBuilder sb = new StringBuilder();
58 SequenceFeature sf = new SequenceFeature("disulfide bond", "desc", 1,
61 // residuePos == 2 does not match start or end of feature, nothing done:
62 sar.appendFeature(sb, 2, null, sf);
63 assertEquals("123456", sb.toString());
65 // residuePos == 1 matches start of feature, text appended (but no <br>)
66 // feature score is not included
67 sar.appendFeature(sb, 1, null, sf);
68 assertEquals("123456disulfide bond 1:3", sb.toString());
70 // residuePos == 3 matches end of feature, text appended
71 // <br> is prefixed once sb.length() > 6
72 sar.appendFeature(sb, 3, null, sf);
73 assertEquals("123456disulfide bond 1:3<br>disulfide bond 1:3",
77 @Test(groups = "Functional")
78 public void testAppendFeature_status()
80 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
81 StringBuilder sb = new StringBuilder();
82 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
84 sf.setStatus("Confirmed");
86 sar.appendFeature(sb, 1, null, sf);
87 assertEquals("METAL 1 3; Fe2-S; (Confirmed)", sb.toString());
90 @Test(groups = "Functional")
91 public void testAppendFeature_withScore()
93 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
94 StringBuilder sb = new StringBuilder();
95 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
98 Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
99 sar.appendFeature(sb, 1, minmax, sf);
101 * map has no entry for this feature type - score is not shown:
103 assertEquals("METAL 1 3; Fe2-S", sb.toString());
106 * map has entry for this feature type - score is shown:
108 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
109 sar.appendFeature(sb, 1, minmax, sf);
110 // <br> is appended to a buffer > 6 in length
111 assertEquals("METAL 1 3; Fe2-S<br>METAL 1 3; Fe2-S Score=1.3",
115 * map has min == max for this feature type - score is not shown:
117 minmax.put("METAL", new float[][] { { 2f, 2f }, null });
119 sar.appendFeature(sb, 1, minmax, sf);
120 assertEquals("METAL 1 3; Fe2-S", sb.toString());
123 @Test(groups = "Functional")
124 public void testAppendFeature_noScore()
126 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
127 StringBuilder sb = new StringBuilder();
128 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
131 sar.appendFeature(sb, 1, null, sf);
132 assertEquals("METAL 1 3; Fe2-S", sb.toString());
135 @Test(groups = "Functional")
136 public void testAppendFeature_clinicalSignificance()
138 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
139 StringBuilder sb = new StringBuilder();
140 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
142 sf.setValue("clinical_significance", "Benign");
144 sar.appendFeature(sb, 1, null, sf);
145 assertEquals("METAL 1 3; Fe2-S; Benign", sb.toString());
148 @Test(groups = "Functional")
149 public void testAppendFeature_withScoreStatusClinicalSignificance()
151 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
152 StringBuilder sb = new StringBuilder();
153 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
155 sf.setStatus("Confirmed");
156 sf.setValue("clinical_significance", "Benign");
157 Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
158 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
159 sar.appendFeature(sb, 1, minmax, sf);
161 assertEquals("METAL 1 3; Fe2-S Score=1.3; (Confirmed); Benign",
165 @Test(groups = "Functional")
166 public void testAppendFeature_DescEqualsType()
168 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
169 StringBuilder sb = new StringBuilder();
170 SequenceFeature sf = new SequenceFeature("METAL", "METAL", 1, 3,
173 // description is not included if it duplicates type:
174 sar.appendFeature(sb, 1, null, sf);
175 assertEquals("METAL 1 3", sb.toString());
178 sf.setDescription("Metal");
179 // test is case-sensitive:
180 sar.appendFeature(sb, 1, null, sf);
181 assertEquals("METAL 1 3; Metal", sb.toString());
184 @Test(groups = "Functional")
185 public void testAppendFeature_stripHtml()
187 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
188 StringBuilder sb = new StringBuilder();
189 SequenceFeature sf = new SequenceFeature("METAL",
190 "<html><body>hello<em>world</em></body></html>", 1, 3,
193 sar.appendFeature(sb, 1, null, sf);
194 // !! strips off </body> but not <body> ??
195 assertEquals("METAL 1 3; <body>hello<em>world</em>", sb.toString());
198 sf.setDescription("<br>&kHD>6");
199 sar.appendFeature(sb, 1, null, sf);
200 // if no <html> tag, html-encodes > and < (only):
201 assertEquals("METAL 1 3; <br>&kHD>6", sb.toString());
204 @Test(groups = "Functional")
205 public void testCreateSequenceAnnotationReport()
207 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
208 StringBuilder sb = new StringBuilder();
210 SequenceI seq = new Sequence("s1", "MAKLKRFQSSTLL");
211 seq.setDescription("SeqDesc");
213 sar.createSequenceAnnotationReport(sb, seq, true, true, null);
216 * positional features are ignored
218 seq.addSequenceFeature(new SequenceFeature("Domain", "Ferredoxin", 5,
220 assertEquals("<i><br>SeqDesc</i>", sb.toString());
223 * non-positional feature
225 seq.addSequenceFeature(new SequenceFeature("Type1", "Nonpos", 0, 0, 1f,
228 sar.createSequenceAnnotationReport(sb, seq, true, true, null);
229 String expected = "<i><br>SeqDesc<br>Type1 ; Nonpos</i>";
230 assertEquals(expected, sb.toString());
233 * non-positional features not wanted
236 sar.createSequenceAnnotationReport(sb, seq, true, false, null);
237 assertEquals("<i><br>SeqDesc</i>", sb.toString());
240 * add non-pos feature with score inside min-max range for feature type
241 * minmax holds { [positionalMin, positionalMax], [nonPosMin, nonPosMax] }
242 * score is only appended for positional features so ignored here!
243 * minMax are not recorded for non-positional features
245 seq.addSequenceFeature(new SequenceFeature("Metal", "Desc", 0, 0, 5f,
247 Map<String, float[][]> minmax = new HashMap<String, float[][]>();
248 minmax.put("Metal", new float[][] { null, new float[] { 2f, 5f } });
250 sar.createSequenceAnnotationReport(sb, seq, true, true, minmax);
251 expected = "<i><br>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos</i>";
252 assertEquals(expected, sb.toString());
255 * 'linkonly' features are ignored; this is obsolete, as linkonly
256 * is only set by DasSequenceFetcher, and DAS is history
258 SequenceFeature sf = new SequenceFeature("Metal", "Desc", 0, 0, 5f,
260 sf.setValue("linkonly", Boolean.TRUE);
261 seq.addSequenceFeature(sf);
263 sar.createSequenceAnnotationReport(sb, seq, true, true, minmax);
264 assertEquals(expected, sb.toString()); // unchanged!
267 * 'clinical_significance' currently being specially included
269 SequenceFeature sf2 = new SequenceFeature("Variant", "Havana", 0, 0,
271 sf2.setValue(GffConstants.CLINICAL_SIGNIFICANCE, "benign");
272 seq.addSequenceFeature(sf2);
274 sar.createSequenceAnnotationReport(sb, seq, true, true, minmax);
275 expected = "<i><br>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos<br>Variant ; Havana; benign</i>";
276 assertEquals(expected, sb.toString());
281 seq.addDBRef(new DBRefEntry("PDB", "0", "3iu1"));
282 seq.addDBRef(new DBRefEntry("Uniprot", "1", "P30419"));
283 // with showDbRefs = false
285 sar.createSequenceAnnotationReport(sb, seq, false, true, minmax);
286 assertEquals(expected, sb.toString()); // unchanged
287 // with showDbRefs = true
289 sar.createSequenceAnnotationReport(sb, seq, true, true, minmax);
290 expected = "<i><br>SeqDesc<br>UNIPROT P30419<br>PDB 3iu1<br>Metal ; Desc<br>Type1 ; Nonpos<br>Variant ; Havana; benign</i>";
291 assertEquals(expected, sb.toString());
292 // with showNonPositionalFeatures = false
294 sar.createSequenceAnnotationReport(sb, seq, true, false, minmax);
295 expected = "<i><br>SeqDesc<br>UNIPROT P30419<br>PDB 3iu1</i>";
296 assertEquals(expected, sb.toString());
298 // see other tests for treatment of status and html
302 * Test that exercises an abbreviated sequence details report, with ellipsis
303 * where there are more than 40 different sources, or more than 4 dbrefs for a
306 @Test(groups = "Functional")
307 public void testCreateSequenceAnnotationReport_withEllipsis()
309 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
310 StringBuilder sb = new StringBuilder();
312 SequenceI seq = new Sequence("s1", "ABC");
314 int maxSources = (int) PA.getValue(sar, "MAX_SOURCES");
315 for (int i = 0; i <= maxSources; i++)
317 seq.addDBRef(new DBRefEntry("PDB" + i, "0", "3iu1"));
320 int maxRefs = (int) PA.getValue(sar, "MAX_REFS_PER_SOURCE");
321 for (int i = 0; i <= maxRefs; i++)
323 seq.addDBRef(new DBRefEntry("Uniprot", "0", "P3041" + i));
326 sar.createSequenceAnnotationReport(sb, seq, true, true, null, true);
327 String report = sb.toString();
329 .startsWith("<i><br>UNIPROT P30410, P30411, P30412, P30413,...<br>PDB0 3iu1"));
331 .endsWith("<br>PDB7 3iu1<br>PDB8,...<br>(Output Sequence Details to list all database references)</i>"));