JAL-3748 reusable assert to trace specific issues with recovering the correct Sequenc...
authorJim Procter <jprocter@issues.jalview.org>
Wed, 23 Sep 2020 15:38:50 +0000 (16:38 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 23 Sep 2020 15:38:50 +0000 (16:38 +0100)
test/jalview/analysis/AlignmentUtilsTests.java

index 128bc5c..cf6ef13 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.analysis;
 
+import static org.junit.Assert.assertNotEquals;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertNotNull;
@@ -41,6 +42,7 @@ import jalview.datamodel.SearchResultsI;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
 import jalview.datamodel.features.SequenceFeatures;
 import jalview.gui.JvOptionPane;
 import jalview.io.AppletFormatAdapter;
@@ -55,6 +57,7 @@ import jalview.util.MappingUtils;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -1787,7 +1790,10 @@ public class AlignmentUtilsTests
     ArrayList<AlignedCodonFrame> acfs = new ArrayList<>();
     acfs.add(acf);
     protein.setCodonFrames(acfs);
-
+    Iterator<SequenceI> protseq = protein.getSequences().iterator();
+    for (SequenceI dnaseq:dna.getSequences()) {
+      assertCanResolveProteinCDS(dnaseq,protseq.next(),protein);
+    }
     /*
      * verify X is included in the aligned proteins, and placed just
      * before the first mapped residue 
@@ -1800,6 +1806,43 @@ public class AlignmentUtilsTests
   }
 
   /**
+   * assert that we can resolve the protein product in the given alignment given a DNA sequence with CDS mapping 
+   * @param dnaseq
+   * @param protein
+   */
+  private void assertCanResolveProteinCDS(SequenceI dnaseq, SequenceI expProtein, AlignmentI protein)
+  {
+    // try a few different methods to check all work
+    SequenceI aprot=null;
+    for (AlignedCodonFrame cf:protein.getCodonFrame(dnaseq))
+    {
+      aprot=cf.getAaForDnaSeq(dnaseq);
+      if (aprot!=null)
+      {
+        assertTrue("getAaForDnaSeq didn't return expected protein sequence",aprot!=expProtein);
+        break;
+      }
+    }
+    assertNotNull("Didn't locate any proteins via AlignmentI.getCodonFrame .. AlignCodonFrame.getAaForDnaSeq", aprot);
+    // try mapping utils - 
+    List<AlignedCodonFrame> mu_mappings=MappingUtils.findMappingsForSequence(dnaseq, protein.getCodonFrames());
+    assertNotNull("No mappings found for dnaseq in protein alignment via MappingUtils.findMappingsForSequence",mu_mappings);
+    assertNotEquals("No mappings found for dnaseq in protein alignment via MappingUtils.findMappingsForSequence",0,mu_mappings.size());
+    SequenceI mu_alignedprot=null;
+    List<SequenceToSequenceMapping> foundMap=null;
+    for (AlignedCodonFrame cf:mu_mappings)
+    {
+      foundMap=new ArrayList<>();
+      mu_alignedprot = cf.findAlignedSequence(dnaseq, protein,foundMap);
+      if (mu_alignedprot!=null) {
+        break;
+      }
+    }
+    assertNotNull("Didn't locate proteins via MappingUtils.findMappingsForSequence",mu_alignedprot);
+    assertTrue("findAlignedSequence didn't return expected protein sequence",mu_alignedprot==expProtein);
+  }
+
+  /**
    * Tests for the method that maps the subset of a dna sequence that has CDS
    * (or subtype) feature - case where the start codon is incomplete.
    */