JAL-3567 adjust layout of linked feature report, unit test
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 16 Apr 2020 17:43:21 +0000 (18:43 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 16 Apr 2020 17:43:21 +0000 (18:43 +0100)
src/jalview/datamodel/MappedFeatures.java
src/jalview/datamodel/SequenceFeature.java
test/jalview/datamodel/SequenceFeatureTest.java

index a42f34a..520ff92 100644 (file)
@@ -119,11 +119,14 @@ public class MappedFeatures
   /**
    * Computes and returns comma-delimited HGVS notation peptide variants derived
    * from codon allele variants. If no variants are found, answers an empty
-   * string.
+   * string. The peptide variant is either simply read from the "CSQ:HGVSp"
+   * attribute if present, else computed based on the "alleles" attribute if
+   * present. If neither attribute is found, no variant (empty string) is
+   * returned.
    * 
    * @param sf
-   *             a sequence feature (which must be one of those held in this
-   *             object)
+   *          a sequence feature (which must be one of those held in this
+   *          object)
    * @return
    */
   public String findProteinVariants(SequenceFeature sf)
index 7a539d0..01574e1 100755 (executable)
@@ -608,6 +608,8 @@ public class SequenceFeature implements FeatureLocationI
     sb.append(String.format(ROW_DATA, "Location", name,
             begin == end ? begin
                     : begin + (isContactFeature() ? ":" : "-") + end));
+
+    String consequence = "";
     if (mf != null)
     {
       int[] beginRange = mf.getMappedPositions(begin, begin);
@@ -619,8 +621,7 @@ public class SequenceFeature implements FeatureLocationI
               : from + (isContactFeature() ? ":" : "-") + to));
       if (mf.isFromCds())
       {
-        sb.append(String.format(ROW_DATA, "Consequence",
-                mf.findProteinVariants(this), "<i>imputed by Jalview</i>"));
+        consequence = mf.findProteinVariants(this);
       }
     }
     sb.append(String.format(ROW_DATA, "Type", type, ""));
@@ -635,6 +636,12 @@ public class SequenceFeature implements FeatureLocationI
       sb.append(String.format(ROW_DATA, "Group", featureGroup, ""));
     }
 
+    if (!consequence.isEmpty())
+    {
+      sb.append(String.format(ROW_DATA, "Consequence",
+              "<i>Imputed by Jalview</i>", consequence));
+    }
+
     if (otherDetails != null)
     {
       TreeMap<String, Object> ordered = new TreeMap<>(
index 673ea29..e105659 100644 (file)
@@ -26,10 +26,14 @@ import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 import jalview.gui.JvOptionPane;
+import jalview.util.MapList;
 
 public class SequenceFeatureTest
 {
@@ -319,4 +323,37 @@ public class SequenceFeatureTest
             + "<tr><td>Group</td><td>Uniprot</td><td></td></tr></table>";
     assertEquals(expected, sf.getDetailsReport(seqName, null));
   }
+
+  /**
+   * Feature details report for a virtual feature should include original and
+   * mapped locations, and also derived peptide consequence if it can be
+   * determined
+   */
+  @Test(groups = { "Functional" })
+  public void testGetDetailsReport_virtualFeature()
+  {
+    SequenceI cds = new Sequence("Cds/101-121", "CCTttgAGAtttCAAatgGAT");
+    SequenceI seq = new Sequence("TestSeq/8-14", "PLRFQMD");
+    MapList map = new MapList(new int[] { 101, 118 }, new int[] { 8, 13 },
+            3, 1);
+    Mapping mapping = new Mapping(seq.getDatasetSequence(), map);
+    List<SequenceFeature> features = new ArrayList<>();
+    // vary ttg (Leu) to ttc (Phe)
+    SequenceFeature sf = new SequenceFeature("variant", "G,C", 106, 106,
+            null);
+    sf.setValue("alleles", "G,C"); // needed to compute peptide consequence!
+    features.add(sf);
+
+    MappedFeatures mf = new MappedFeatures(mapping, cds, 9, 'L', features);
+
+    String expected = "<br><table><tr><td>Location</td><td>Cds</td><td>106</td></tr>"
+            + "<tr><td>Peptide Location</td><td>TestSeq</td><td>9</td></tr>"
+            + "<tr><td>Type</td><td>variant</td><td></td></tr>"
+            + "<tr><td>Description</td><td>G,C</td><td></td></tr>"
+            + "<tr><td>Consequence</td><td><i>Imputed by Jalview</i></td><td>p.Leu9Phe</td></tr>"
+            + "<tr><td>alleles</td><td></td><td>G,C</td></tr>"
+            + "</table>";
+
+    assertEquals(expected, sf.getDetailsReport(seq.getName(), mf));
+  }
 }