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;
27 import java.util.Hashtable;
30 import org.testng.annotations.Test;
32 public class SequenceAnnotationReportTest
34 @Test(groups = "Functional")
35 public void testAppendFeature_disulfideBond()
37 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
38 StringBuffer sb = new StringBuffer();
40 SequenceFeature sf = new SequenceFeature("disulfide bond", "desc", 1,
43 // residuePos == 2 does not match start or end of feature, nothing done:
44 sar.appendFeature(sb, 2, null, sf);
45 assertEquals("123456", sb.toString());
47 // residuePos == 1 matches start of feature, text appended (but no <br>)
48 // feature score is not included
49 sar.appendFeature(sb, 1, null, sf);
50 assertEquals("123456disulfide bond 1:3", sb.toString());
52 // residuePos == 3 matches end of feature, text appended
53 // <br> is prefixed once sb.length() > 6
54 sar.appendFeature(sb, 3, null, sf);
55 assertEquals("123456disulfide bond 1:3<br>disulfide bond 1:3",
59 @Test(groups = "Functional")
60 public void testAppendFeature_status()
62 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
63 StringBuffer sb = new StringBuffer();
64 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
66 sf.setStatus("Confirmed");
68 sar.appendFeature(sb, 1, null, sf);
69 assertEquals("METAL 1 3; Fe2-S; (Confirmed)", sb.toString());
72 @Test(groups = "Functional")
73 public void testAppendFeature_withScore()
75 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
76 StringBuffer sb = new StringBuffer();
77 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
80 Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
81 sar.appendFeature(sb, 1, minmax, sf);
83 * map has no entry for this feature type - score is not shown:
85 assertEquals("METAL 1 3; Fe2-S", sb.toString());
88 * map has entry for this feature type - score is shown:
90 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
91 sar.appendFeature(sb, 1, minmax, sf);
92 // <br> is appended to a buffer > 6 in length
93 assertEquals("METAL 1 3; Fe2-S<br>METAL 1 3; Fe2-S Score=1.3",
97 * map has min == max for this feature type - score is not shown:
99 minmax.put("METAL", new float[][] { { 2f, 2f }, null });
101 sar.appendFeature(sb, 1, minmax, sf);
102 assertEquals("METAL 1 3; Fe2-S", sb.toString());
105 @Test(groups = "Functional")
106 public void testAppendFeature_noScore()
108 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
109 StringBuffer sb = new StringBuffer();
110 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
113 sar.appendFeature(sb, 1, null, sf);
114 assertEquals("METAL 1 3; Fe2-S", sb.toString());
117 @Test(groups = "Functional")
118 public void testAppendFeature_clinicalSignificance()
120 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
121 StringBuffer sb = new StringBuffer();
122 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
124 sf.setValue("clinical_significance", "Benign");
126 sar.appendFeature(sb, 1, null, sf);
127 assertEquals("METAL 1 3; Fe2-S; Benign", sb.toString());
130 @Test(groups = "Functional")
131 public void testAppendFeature_withScoreStatusClinicalSignificance()
133 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
134 StringBuffer sb = new StringBuffer();
135 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
137 sf.setStatus("Confirmed");
138 sf.setValue("clinical_significance", "Benign");
139 Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
140 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
141 sar.appendFeature(sb, 1, minmax, sf);
143 assertEquals("METAL 1 3; Fe2-S Score=1.3; (Confirmed); Benign",
147 @Test(groups = "Functional")
148 public void testAppendFeature_DescEqualsType()
150 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
151 StringBuffer sb = new StringBuffer();
152 SequenceFeature sf = new SequenceFeature("METAL", "METAL", 1, 3,
155 // description is not included if it duplicates type:
156 sar.appendFeature(sb, 1, null, sf);
157 assertEquals("METAL 1 3", sb.toString());
160 sf.setDescription("Metal");
161 // test is case-sensitive:
162 sar.appendFeature(sb, 1, null, sf);
163 assertEquals("METAL 1 3; Metal", sb.toString());
166 @Test(groups = "Functional")
167 public void testAppendFeature_stripHtml()
169 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
170 StringBuffer sb = new StringBuffer();
171 SequenceFeature sf = new SequenceFeature("METAL",
172 "<html><body>hello<em>world</em></body></html>", 1, 3,
175 sar.appendFeature(sb, 1, null, sf);
176 // !! strips off </body> but not <body> ??
177 assertEquals("METAL 1 3; <body>hello<em>world</em>", sb.toString());
180 sf.setDescription("<br>&kHD>6");
181 sar.appendFeature(sb, 1, null, sf);
182 // if no <html> tag, html-encodes > and < (only):
183 assertEquals("METAL 1 3; <br>&kHD>6", sb.toString());