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.api.FeatureColourI;
27 import jalview.datamodel.DBRefEntry;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceFeature;
30 import jalview.datamodel.SequenceI;
31 import jalview.gui.JvOptionPane;
32 import jalview.io.gff.GffConstants;
33 import jalview.renderer.seqfeatures.FeatureRenderer;
34 import jalview.schemes.FeatureColour;
35 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
37 import java.awt.Color;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.Test;
43 import junit.extensions.PA;
45 public class SequenceAnnotationReportTest
48 @BeforeClass(alwaysRun = true)
49 public void setUpJvOptionPane()
51 JvOptionPane.setInteractiveMode(false);
52 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55 @Test(groups = "Functional")
56 public void testAppendFeature_disulfideBond()
58 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
59 StringBuilder sb = new StringBuilder();
61 SequenceFeature sf = new SequenceFeature("disulfide bond", "desc", 1,
64 // residuePos == 2 does not match start or end of feature, nothing done:
65 sar.appendFeature(sb, 2, null, sf, null);
66 assertEquals("123456", sb.toString());
68 // residuePos == 1 matches start of feature, text appended (but no <br>)
69 // feature score is not included
70 sar.appendFeature(sb, 1, null, sf, null);
71 assertEquals("123456disulfide bond 1:3", sb.toString());
73 // residuePos == 3 matches end of feature, text appended
74 // <br> is prefixed once sb.length() > 6
75 sar.appendFeature(sb, 3, null, sf, null);
76 assertEquals("123456disulfide bond 1:3<br>disulfide bond 1:3",
80 @Test(groups = "Functional")
81 public void testAppendFeature_status()
83 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
84 StringBuilder sb = new StringBuilder();
85 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
87 sf.setStatus("Confirmed");
89 sar.appendFeature(sb, 1, null, sf, null);
90 assertEquals("METAL 1 3; Fe2-S; (Confirmed)", sb.toString());
93 @Test(groups = "Functional")
94 public void testAppendFeature_withScore()
96 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
97 StringBuilder sb = new StringBuilder();
98 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
101 FeatureRendererModel fr = new FeatureRenderer(null);
102 Map<String, float[][]> minmax = fr.getMinMax();
103 sar.appendFeature(sb, 1, fr, sf, null);
105 * map has no entry for this feature type - score is not shown:
107 assertEquals("METAL 1 3; Fe2-S", sb.toString());
110 * map has entry for this feature type - score is shown:
112 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
113 sar.appendFeature(sb, 1, fr, sf, null);
114 // <br> is appended to a buffer > 6 in length
115 assertEquals("METAL 1 3; Fe2-S<br>METAL 1 3; Fe2-S Score=1.3",
119 * map has min == max for this feature type - score is not shown:
121 minmax.put("METAL", new float[][] { { 2f, 2f }, null });
123 sar.appendFeature(sb, 1, fr, sf, null);
124 assertEquals("METAL 1 3; Fe2-S", sb.toString());
127 @Test(groups = "Functional")
128 public void testAppendFeature_noScore()
130 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
131 StringBuilder sb = new StringBuilder();
132 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
135 sar.appendFeature(sb, 1, null, sf, null);
136 assertEquals("METAL 1 3; Fe2-S", sb.toString());
140 * A specific attribute value is included if it is used to colour the feature
142 @Test(groups = "Functional")
143 public void testAppendFeature_colouredByAttribute()
145 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
146 StringBuilder sb = new StringBuilder();
147 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
149 sf.setValue("clinical_significance", "Benign");
152 * first with no colour by attribute
154 FeatureRendererModel fr = new FeatureRenderer(null);
155 sar.appendFeature(sb, 1, fr, sf, null);
156 assertEquals("METAL 1 3; Fe2-S", sb.toString());
159 * then with colour by an attribute the feature lacks
161 FeatureColourI fc = new FeatureColour(null, Color.white, Color.black,
163 fc.setAttributeName("Pfam");
164 fr.setColour("METAL", fc);
166 sar.appendFeature(sb, 1, fr, sf, null);
167 assertEquals("METAL 1 3; Fe2-S", sb.toString()); // no change
170 * then with colour by an attribute the feature has
172 fc.setAttributeName("clinical_significance");
174 sar.appendFeature(sb, 1, fr, sf, null);
175 assertEquals("METAL 1 3; Fe2-S; clinical_significance=Benign",
179 @Test(groups = "Functional")
180 public void testAppendFeature_withScoreStatusAttribute()
182 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
183 StringBuilder sb = new StringBuilder();
184 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
186 sf.setStatus("Confirmed");
187 sf.setValue("clinical_significance", "Benign");
189 FeatureRendererModel fr = new FeatureRenderer(null);
190 Map<String, float[][]> minmax = fr.getMinMax();
191 FeatureColourI fc = new FeatureColour(null, Color.white, Color.blue,
193 fc.setAttributeName("clinical_significance");
194 fr.setColour("METAL", fc);
195 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
196 sar.appendFeature(sb, 1, fr, sf, null);
199 "METAL 1 3; Fe2-S Score=1.3; (Confirmed); clinical_significance=Benign",
203 @Test(groups = "Functional")
204 public void testAppendFeature_DescEqualsType()
206 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
207 StringBuilder sb = new StringBuilder();
208 SequenceFeature sf = new SequenceFeature("METAL", "METAL", 1, 3,
211 // description is not included if it duplicates type:
212 sar.appendFeature(sb, 1, null, sf, null);
213 assertEquals("METAL 1 3", sb.toString());
216 sf.setDescription("Metal");
217 // test is case-sensitive:
218 sar.appendFeature(sb, 1, null, sf, null);
219 assertEquals("METAL 1 3; Metal", sb.toString());
222 @Test(groups = "Functional")
223 public void testAppendFeature_stripHtml()
225 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
226 StringBuilder sb = new StringBuilder();
227 SequenceFeature sf = new SequenceFeature("METAL",
228 "<html><body>hello<em>world</em></body></html>", 1, 3,
231 sar.appendFeature(sb, 1, null, sf, null);
232 // !! strips off </body> but not <body> ??
233 assertEquals("METAL 1 3; <body>hello<em>world</em>", sb.toString());
236 sf.setDescription("<br>&kHD>6");
237 sar.appendFeature(sb, 1, null, sf, null);
238 // if no <html> tag, html-encodes > and < (only):
239 assertEquals("METAL 1 3; <br>&kHD>6", sb.toString());
242 @Test(groups = "Functional")
243 public void testCreateSequenceAnnotationReport()
245 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
246 StringBuilder sb = new StringBuilder();
248 SequenceI seq = new Sequence("s1", "MAKLKRFQSSTLL");
249 seq.setDescription("SeqDesc");
252 * positional features are ignored
254 seq.addSequenceFeature(new SequenceFeature("Domain", "Ferredoxin", 5,
256 sar.createSequenceAnnotationReport(sb, seq, true, true, null);
257 assertEquals("<i>SeqDesc</i>", sb.toString());
260 * non-positional feature
262 seq.addSequenceFeature(new SequenceFeature("Type1", "Nonpos", 0, 0, 1f,
265 sar.createSequenceAnnotationReport(sb, seq, true, true, null);
266 String expected = "<i>SeqDesc<br>Type1 ; Nonpos Score=1.0</i>";
267 assertEquals(expected, sb.toString());
270 * non-positional features not wanted
273 sar.createSequenceAnnotationReport(sb, seq, true, false, null);
274 assertEquals("<i>SeqDesc</i>", sb.toString());
277 * add non-pos feature with score inside min-max range for feature type
278 * minmax holds { [positionalMin, positionalMax], [nonPosMin, nonPosMax] }
279 * score is only appended for positional features so ignored here!
280 * minMax are not recorded for non-positional features
282 seq.addSequenceFeature(new SequenceFeature("Metal", "Desc", 0, 0, 5f,
285 FeatureRendererModel fr = new FeatureRenderer(null);
286 Map<String, float[][]> minmax = fr.getMinMax();
287 minmax.put("Metal", new float[][] { null, new float[] { 2f, 5f } });
290 sar.createSequenceAnnotationReport(sb, seq, true, true, fr);
291 expected = "<i>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos</i>";
292 assertEquals(expected, sb.toString());
295 * 'linkonly' features are ignored; this is obsolete, as linkonly
296 * is only set by DasSequenceFetcher, and DAS is history
298 SequenceFeature sf = new SequenceFeature("Metal", "Desc", 0, 0, 5f,
300 sf.setValue("linkonly", Boolean.TRUE);
301 seq.addSequenceFeature(sf);
303 sar.createSequenceAnnotationReport(sb, seq, true, true, fr);
304 assertEquals(expected, sb.toString()); // unchanged!
307 * 'clinical_significance' attribute is only included in description
308 * when used for feature colouring
310 SequenceFeature sf2 = new SequenceFeature("Variant", "Havana", 0, 0,
312 sf2.setValue(GffConstants.CLINICAL_SIGNIFICANCE, "benign");
313 seq.addSequenceFeature(sf2);
315 sar.createSequenceAnnotationReport(sb, seq, true, true, fr);
316 expected = "<i>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos<br>Variant ; Havana</i>";
317 assertEquals(expected, sb.toString());
322 seq.addDBRef(new DBRefEntry("PDB", "0", "3iu1"));
323 seq.addDBRef(new DBRefEntry("Uniprot", "1", "P30419"));
325 // with showDbRefs = false
327 sar.createSequenceAnnotationReport(sb, seq, false, true, fr);
328 assertEquals(expected, sb.toString()); // unchanged
330 // with showDbRefs = true, colour Variant features by clinical_significance
332 FeatureColourI fc = new FeatureColour(null, Color.green, Color.pink,
334 fc.setAttributeName("clinical_significance");
335 fr.setColour("Variant", fc);
336 sar.createSequenceAnnotationReport(sb, seq, true, true, fr);
337 expected = "<i>SeqDesc<br>UNIPROT P30419<br>PDB 3iu1<br>Metal ; Desc<br>"
338 + "Type1 ; Nonpos<br>Variant ; Havana; clinical_significance=benign</i>";
339 assertEquals(expected, sb.toString());
340 // with showNonPositionalFeatures = false
342 sar.createSequenceAnnotationReport(sb, seq, true, false, fr);
343 expected = "<i>SeqDesc<br>UNIPROT P30419<br>PDB 3iu1</i>";
344 assertEquals(expected, sb.toString());
347 * long feature description is truncated with ellipsis
351 "This is a very long description which should be truncated");
352 sar.createSequenceAnnotationReport(sb, seq, false, true, fr);
353 expected = "<i>SeqDesc<br>Metal ; Desc<br>Type1 ; Nonpos<br>Variant ; This is a very long description which sh...; clinical_significance=benign</i>";
354 assertEquals(expected, sb.toString());
356 // see other tests for treatment of status and html
360 * Test that exercises an abbreviated sequence details report, with ellipsis
361 * where there are more than 40 different sources, or more than 4 dbrefs for a
364 @Test(groups = "Functional")
365 public void testCreateSequenceAnnotationReport_withEllipsis()
367 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
368 StringBuilder sb = new StringBuilder();
370 SequenceI seq = new Sequence("s1", "ABC");
372 int maxSources = (int) PA.getValue(sar, "MAX_SOURCES");
373 for (int i = 0; i <= maxSources; i++)
375 seq.addDBRef(new DBRefEntry("PDB" + i, "0", "3iu1"));
378 int maxRefs = (int) PA.getValue(sar, "MAX_REFS_PER_SOURCE");
379 for (int i = 0; i <= maxRefs; i++)
381 seq.addDBRef(new DBRefEntry("Uniprot", "0", "P3041" + i));
384 sar.createSequenceAnnotationReport(sb, seq, true, true, null, true);
385 String report = sb.toString();
387 .startsWith("<i><br>UNIPROT P30410, P30411, P30412, P30413,...<br>PDB0 3iu1"));
389 .endsWith("<br>PDB7 3iu1<br>PDB8,...<br>(Output Sequence Details to list all database references)</i>"));