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;
25 import jalview.datamodel.SequenceFeature;
26 import jalview.gui.JvOptionPane;
28 import java.util.Hashtable;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.Test;
34 public class SequenceAnnotationReportTest
37 @BeforeClass(alwaysRun = true)
38 public void setUpJvOptionPane()
40 JvOptionPane.setInteractiveMode(false);
41 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
44 @Test(groups = "Functional")
45 public void testAppendFeature_disulfideBond()
47 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
48 StringBuilder sb = new StringBuilder();
50 SequenceFeature sf = new SequenceFeature("disulfide bond", "desc", 1,
53 // residuePos == 2 does not match start or end of feature, nothing done:
54 sar.appendFeature(sb, 2, null, sf);
55 assertEquals("123456", sb.toString());
57 // residuePos == 1 matches start of feature, text appended (but no <br>)
58 // feature score is not included
59 sar.appendFeature(sb, 1, null, sf);
60 assertEquals("123456disulfide bond 1:3", sb.toString());
62 // residuePos == 3 matches end of feature, text appended
63 // <br> is prefixed once sb.length() > 6
64 sar.appendFeature(sb, 3, null, sf);
65 assertEquals("123456disulfide bond 1:3<br>disulfide bond 1:3",
69 @Test(groups = "Functional")
70 public void testAppendFeature_status()
72 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
73 StringBuilder sb = new StringBuilder();
74 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
76 sf.setStatus("Confirmed");
78 sar.appendFeature(sb, 1, null, sf);
79 assertEquals("METAL 1 3; Fe2-S; (Confirmed)", sb.toString());
82 @Test(groups = "Functional")
83 public void testAppendFeature_withScore()
85 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
86 StringBuilder sb = new StringBuilder();
87 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
90 Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
91 sar.appendFeature(sb, 1, minmax, sf);
93 * map has no entry for this feature type - score is not shown:
95 assertEquals("METAL 1 3; Fe2-S", sb.toString());
98 * map has entry for this feature type - score is shown:
100 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
101 sar.appendFeature(sb, 1, minmax, sf);
102 // <br> is appended to a buffer > 6 in length
103 assertEquals("METAL 1 3; Fe2-S<br>METAL 1 3; Fe2-S Score=1.3",
107 * map has min == max for this feature type - score is not shown:
109 minmax.put("METAL", new float[][] { { 2f, 2f }, null });
111 sar.appendFeature(sb, 1, minmax, sf);
112 assertEquals("METAL 1 3; Fe2-S", sb.toString());
115 @Test(groups = "Functional")
116 public void testAppendFeature_noScore()
118 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
119 StringBuilder sb = new StringBuilder();
120 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
123 sar.appendFeature(sb, 1, null, sf);
124 assertEquals("METAL 1 3; Fe2-S", sb.toString());
127 @Test(groups = "Functional")
128 public void testAppendFeature_clinicalSignificance()
130 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
131 StringBuilder sb = new StringBuilder();
132 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
134 sf.setValue("clinical_significance", "Benign");
136 sar.appendFeature(sb, 1, null, sf);
137 assertEquals("METAL 1 3; Fe2-S; Benign", sb.toString());
140 @Test(groups = "Functional")
141 public void testAppendFeature_withScoreStatusClinicalSignificance()
143 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
144 StringBuilder sb = new StringBuilder();
145 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
147 sf.setStatus("Confirmed");
148 sf.setValue("clinical_significance", "Benign");
149 Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
150 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
151 sar.appendFeature(sb, 1, minmax, sf);
153 assertEquals("METAL 1 3; Fe2-S Score=1.3; (Confirmed); Benign",
157 @Test(groups = "Functional")
158 public void testAppendFeature_DescEqualsType()
160 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
161 StringBuilder sb = new StringBuilder();
162 SequenceFeature sf = new SequenceFeature("METAL", "METAL", 1, 3,
165 // description is not included if it duplicates type:
166 sar.appendFeature(sb, 1, null, sf);
167 assertEquals("METAL 1 3", sb.toString());
170 sf.setDescription("Metal");
171 // test is case-sensitive:
172 sar.appendFeature(sb, 1, null, sf);
173 assertEquals("METAL 1 3; Metal", sb.toString());
176 @Test(groups = "Functional")
177 public void testAppendFeature_stripHtml()
179 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
180 StringBuilder sb = new StringBuilder();
181 SequenceFeature sf = new SequenceFeature("METAL",
182 "<html><body>hello<em>world</em></body></html>", 1, 3,
185 sar.appendFeature(sb, 1, null, sf);
186 // !! strips off </body> but not <body> ??
187 assertEquals("METAL 1 3; <body>hello<em>world</em>", sb.toString());
190 sf.setDescription("<br>&kHD>6");
191 sar.appendFeature(sb, 1, null, sf);
192 // if no <html> tag, html-encodes > and < (only):
193 assertEquals("METAL 1 3; <br>&kHD>6", sb.toString());