From 44d634a7732851685a37a502e48fbf2b967c6baf Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 23 Sep 2020 16:38:50 +0100 Subject: [PATCH] JAL-3748 reusable assert to trace specific issues with recovering the correct Sequence/Mapping (highlights points of failure for AlignmentUtilsTests with patch --- test/jalview/analysis/AlignmentUtilsTests.java | 45 +++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index 128bc5c..cf6ef13 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -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 acfs = new ArrayList<>(); acfs.add(acf); protein.setCodonFrames(acfs); - + Iterator 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 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 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. */ -- 1.7.10.2