JAL-3187 unit test for findComplementFeaturesAtResidue
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 6 Mar 2020 16:06:13 +0000 (16:06 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 6 Mar 2020 16:06:13 +0000 (16:06 +0000)
src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java
test/jalview/renderer/seqfeatures/FeatureRendererTest.java

index aba5601..9a8a086 100644 (file)
@@ -1208,7 +1208,7 @@ public abstract class FeatureRendererModel
         int toRes = match.getEnd();
         mapFrom = match.getSequence();
         List<SequenceFeature> fs = findFeaturesAtResidue(
-                match.getSequence(), fromRes, toRes);
+                mapFrom, fromRes, toRes);
         for (SequenceFeature sf : fs)
         {
           if (!found.contains(sf))
index 723f3b8..2e04ecb 100644 (file)
@@ -22,17 +22,24 @@ package jalview.renderer.seqfeatures;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
+import jalview.analysis.GeneticCodes;
 import jalview.api.AlignViewportI;
 import jalview.api.FeatureColourI;
+import jalview.bin.Jalview;
+import jalview.datamodel.MappedFeatures;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.features.FeatureMatcher;
 import jalview.datamodel.features.FeatureMatcherSet;
 import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+import jalview.gui.Desktop;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 import jalview.schemes.FeatureColour;
@@ -604,4 +611,69 @@ public class FeatureRendererTest
     filter.and(FeatureMatcher.byScore(Condition.LE, "0.4"));
     assertFalse(fr.isVisible(sf)); // feature doesn't match filter
   }
+
+  @Test(groups = "Functional")
+  public void testFindComplementFeaturesAtResidue()
+  {
+    Jalview.main(
+            new String[]
+            { "-nonews", "-props", "test/jalview/testProps.jvprops" });
+
+    // codons for MCWHSE
+    String cdsSeq = ">cds\nATGtgtTGGcacTCAgaa";
+    AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(cdsSeq,
+            DataSourceType.PASTE);
+    af.showTranslation_actionPerformed(
+            GeneticCodes.getInstance().getStandardCodeTable());
+    af.closeMenuItem_actionPerformed(true);
+
+    /*
+     * find the complement frames (ugly)
+     */
+    AlignFrame[] frames = Desktop.getAlignFrames();
+    assertEquals(frames.length, 2);
+    AlignViewport av1 = frames[0].getViewport();
+    AlignViewport av2 = frames[1].getViewport();
+    AlignViewport cds = av1.getAlignment().isNucleotide() ? av1 : av2;
+    AlignViewport peptide = cds == av1 ? av2 : av1;
+    assertNotNull(cds);
+    assertNotNull(peptide);
+
+    /*
+     * add features to CDS at first codon, positions 2-3
+     */
+    SequenceI seq1 = cds.getAlignment().getSequenceAt(0);
+    SequenceFeature sf1 = new SequenceFeature("sequence_variant", "G,GT", 2,
+            2, "ensembl");
+    seq1.addSequenceFeature(sf1);
+    SequenceFeature sf2 = new SequenceFeature("sequence_variant", "C, CA",
+            3, 3, "ensembl");
+    seq1.addSequenceFeature(sf2);
+    
+    /*
+     * 'find' mapped features from the peptide position
+     * - first with CDS features _not_ shown on peptide alignment
+     */
+    SequenceI seq2 = peptide.getAlignment().getSequenceAt(0);
+    FeatureRenderer frC = new FeatureRenderer(cds);
+    frC.featuresAdded();
+    MappedFeatures mf = frC.findComplementFeaturesAtResidue(seq2, 1);
+    assertNotNull(mf);
+    assertEquals(mf.features.size(), 2);
+    assertSame(mf.features.get(0), sf1);
+    assertSame(mf.features.get(1), sf2);
+
+    /*
+     * add exon feature and verify it is only returned once for a
+     * peptide position, even though it is on all 3 codon positions
+     */
+    SequenceFeature sf3 = new SequenceFeature("exon", "exon1", 4, 12,
+            "ensembl");
+    seq1.addSequenceFeature(sf3);
+    frC.featuresAdded();
+    mf = frC.findComplementFeaturesAtResidue(seq2, 3);
+    assertNotNull(mf);
+    assertEquals(mf.features.size(), 1);
+    assertSame(mf.features.get(0), sf3);
+  }
 }