JAL-2041 clinical_significance shown on sequence feature tooltip
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 14 Apr 2016 12:32:09 +0000 (13:32 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 14 Apr 2016 12:32:09 +0000 (13:32 +0100)
src/jalview/io/SequenceAnnotationReport.java
test/jalview/io/SequenceAnnotationReportTest.java [new file with mode: 0644]

index 676404b..8469355 100644 (file)
@@ -175,6 +175,11 @@ public class SequenceAnnotationReport
         {
           sb.append("; (").append(status).append(")");
         }
+        String clinSig = (String) feature.getValue("clinical_significance");
+        if (clinSig != null)
+        {
+          sb.append("; ").append(clinSig);
+        }
       }
     }
     appendLinks(sb, feature);
diff --git a/test/jalview/io/SequenceAnnotationReportTest.java b/test/jalview/io/SequenceAnnotationReportTest.java
new file mode 100644 (file)
index 0000000..f551571
--- /dev/null
@@ -0,0 +1,166 @@
+package jalview.io;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import jalview.datamodel.SequenceFeature;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.testng.annotations.Test;
+
+public class SequenceAnnotationReportTest
+{
+  @Test(groups = "Functional")
+  public void testAppendFeature_disulfideBond()
+  {
+    SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
+    StringBuffer sb = new StringBuffer();
+    sb.append("123456");
+    SequenceFeature sf = new SequenceFeature("disulfide bond", "desc", 1,
+            3, 1.2f, "group");
+
+    // residuePos == 2 does not match start or end of feature, nothing done:
+    sar.appendFeature(sb, 2, null, sf);
+    assertEquals("123456", sb.toString());
+
+    // residuePos == 1 matches start of feature, text appended (but no <br>)
+    // feature score is not included
+    sar.appendFeature(sb, 1, null, sf);
+    assertEquals("123456disulfide bond 1:3", sb.toString());
+
+    // residuePos == 3 matches end of feature, text appended
+    // <br> is prefixed once sb.length() > 6
+    sar.appendFeature(sb, 3, null, sf);
+    assertEquals("123456disulfide bond 1:3<br>disulfide bond 1:3",
+            sb.toString());
+  }
+
+  @Test(groups = "Functional")
+  public void testAppendFeature_status()
+  {
+    SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
+    StringBuffer sb = new StringBuffer();
+    SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
+            Float.NaN, "group");
+    sf.setStatus("Confirmed");
+  
+    sar.appendFeature(sb, 1, null, sf);
+    assertEquals("METAL 1 3; Fe2-S; (Confirmed)", sb.toString());
+  }
+
+  @Test(groups = "Functional")
+  public void testAppendFeature_withScore()
+  {
+    SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
+    StringBuffer sb = new StringBuffer();
+    SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
+            "group");
+
+    Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
+    sar.appendFeature(sb, 1, minmax, sf);
+    /*
+     * map has no entry for this feature type - score is not shown:
+     */
+    assertEquals("METAL 1 3; Fe2-S", sb.toString());
+
+    /*
+     * map has entry for this feature type - score is shown:
+     */
+    minmax.put("METAL", new float[][] { { 0f, 1f }, null });
+    sar.appendFeature(sb, 1, minmax, sf);
+    // <br> is appended to a buffer > 6 in length
+    assertEquals("METAL 1 3; Fe2-S<br>METAL 1 3; Fe2-S Score=1.3",
+            sb.toString());
+
+    /*
+     * map has min == max for this feature type - score is not shown:
+     */
+    minmax.put("METAL", new float[][] { { 2f, 2f }, null });
+    sb.setLength(0);
+    sar.appendFeature(sb, 1, minmax, sf);
+    assertEquals("METAL 1 3; Fe2-S", sb.toString());
+  }
+
+  @Test(groups = "Functional")
+  public void testAppendFeature_noScore()
+  {
+    SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
+    StringBuffer sb = new StringBuffer();
+    SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
+            Float.NaN, "group");
+  
+    sar.appendFeature(sb, 1, null, sf);
+    assertEquals("METAL 1 3; Fe2-S", sb.toString());
+  }
+
+  @Test(groups = "Functional")
+  public void testAppendFeature_clinicalSignificance()
+  {
+    SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
+    StringBuffer sb = new StringBuffer();
+    SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
+            Float.NaN, "group");
+    sf.setValue("clinical_significance", "Benign");
+  
+    sar.appendFeature(sb, 1, null, sf);
+    assertEquals("METAL 1 3; Fe2-S; Benign", sb.toString());
+  }
+
+  @Test(groups = "Functional")
+  public void testAppendFeature_withScoreStatusClinicalSignificance()
+  {
+    SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
+    StringBuffer sb = new StringBuffer();
+    SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
+            "group");
+    sf.setStatus("Confirmed");
+    sf.setValue("clinical_significance", "Benign");
+    Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
+    minmax.put("METAL", new float[][] { { 0f, 1f }, null });
+    sar.appendFeature(sb, 1, minmax, sf);
+
+    assertEquals("METAL 1 3; Fe2-S Score=1.3; (Confirmed); Benign",
+            sb.toString());
+  }
+
+  @Test(groups = "Functional")
+  public void testAppendFeature_DescEqualsType()
+  {
+    SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
+    StringBuffer sb = new StringBuffer();
+    SequenceFeature sf = new SequenceFeature("METAL", "METAL", 1, 3,
+            Float.NaN, "group");
+  
+    // description is not included if it duplicates type:
+    sar.appendFeature(sb, 1, null, sf);
+    assertEquals("METAL 1 3", sb.toString());
+
+    sb.setLength(0);
+    sf.setDescription("Metal");
+    // test is case-sensitive:
+    sar.appendFeature(sb, 1, null, sf);
+    assertEquals("METAL 1 3; Metal", sb.toString());
+  }
+
+  @Test(groups = "Functional")
+  public void testAppendFeature_stripHtml()
+  {
+    SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
+    StringBuffer sb = new StringBuffer();
+    SequenceFeature sf = new SequenceFeature("METAL",
+            "<html><body>hello<em>world</em></body></html>", 1, 3,
+            Float.NaN, "group");
+  
+    sar.appendFeature(sb, 1, null, sf);
+    // !! strips off </body> but not <body> ??
+    assertEquals("METAL 1 3; <body>hello<em>world</em>",
+            sb.toString());
+
+    sb.setLength(0);
+    sf.setDescription("<br>&kHD>6");
+    sar.appendFeature(sb, 1, null, sf);
+    // if no <html> tag, html-encodes > and < (only):
+    assertEquals("METAL 1 3; &lt;br&gt;&kHD&gt;6", sb.toString());
+  }
+}