From b59e6ecc36fb98f4285213a685d0546e98ebd556 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 22 Oct 2020 14:48:25 +0100 Subject: [PATCH] JAL-3763 Javadoc, check for null, additional tests --- src/jalview/datamodel/AlignedCodonFrame.java | 6 +- src/jalview/gui/PopupMenu.java | 7 ++- test/jalview/datamodel/AlignedCodonFrameTest.java | 63 +++++++++++++++++++++ 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/jalview/datamodel/AlignedCodonFrame.java b/src/jalview/datamodel/AlignedCodonFrame.java index 049a5f4..6faf7a6 100644 --- a/src/jalview/datamodel/AlignedCodonFrame.java +++ b/src/jalview/datamodel/AlignedCodonFrame.java @@ -954,9 +954,9 @@ public class AlignedCodonFrame } /** - * Returns the first mapping found which is between the given sequence and - * another, is a triplet mapping (3:1 or 1:3), and covers the full extent of - * both sequences involved. + * Returns the first mapping found which is between the given dataset sequence + * and another, is a triplet mapping (3:1 or 1:3), and covers the full extent + * of both sequences involved * * @param seq * @return diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 568f7f1..fc3c342 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -832,8 +832,13 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener * show local rather than linked feature coordinates */ int[] beginRange = mf.getMappedPositions(start, start); - start = beginRange[0]; int[] endRange = mf.getMappedPositions(end, end); + if (beginRange == null || endRange == null) + { + // e.g. variant extending to stop codon so not mappable + return; + } + start = beginRange[0]; end = endRange[endRange.length - 1]; } StringBuilder desc = new StringBuilder(); diff --git a/test/jalview/datamodel/AlignedCodonFrameTest.java b/test/jalview/datamodel/AlignedCodonFrameTest.java index 0cfc380..337ac1a 100644 --- a/test/jalview/datamodel/AlignedCodonFrameTest.java +++ b/test/jalview/datamodel/AlignedCodonFrameTest.java @@ -648,4 +648,67 @@ public class AlignedCodonFrameTest expected.addResult(dna1.getDatasetSequence(), 17, 18); assertEquals(sr, expected); } + + @Test(groups = { "Functional" }) + public void testGetCoveringCodonMapping() + { + SequenceI dna = new Sequence("dna/10-30", "acttcaATGGCGGACtaattt"); + // CDS sequence with its own dataset sequence (JAL-3763) + SequenceI cds = new Sequence("cds/1-9", "-A--TGGC-GGAC"); + cds.createDatasetSequence(); + SequenceI pep = new Sequence("pep/1-3", "MAD"); + + /* + * with null argument or no mappings + */ + AlignedCodonFrame acf = new AlignedCodonFrame(); + assertNull(acf.getCoveringCodonMapping(null)); + assertNull(acf.getCoveringCodonMapping(dna)); + assertNull(acf.getCoveringCodonMapping(pep)); + + /* + * with a non-covering mapping e.g. overlapping exon + */ + MapList map = new MapList(new int[] { 16, 18 }, new int[] { + 1, 1 }, 3, 1); + acf.addMap(dna, pep, map); + assertNull(acf.getCoveringCodonMapping(dna)); + assertNull(acf.getCoveringCodonMapping(pep)); + + acf = new AlignedCodonFrame(); + MapList map2 = new MapList(new int[] { 13, 18 }, new int[] { + 2, 2 }, 3, 1); + acf.addMap(dna, pep, map2); + assertNull(acf.getCoveringCodonMapping(dna)); + assertNull(acf.getCoveringCodonMapping(pep)); + + /* + * with a covering mapping from CDS (dataset) to protein + */ + acf = new AlignedCodonFrame(); + MapList map3 = new MapList(new int[] { 1, 9 }, new int[] { + 1, 3 }, 3, 1); + acf.addMap(cds.getDatasetSequence(), pep, map3); + assertNull(acf.getCoveringCodonMapping(dna)); + SequenceToSequenceMapping mapping = acf.getCoveringCodonMapping(pep); + assertNotNull(mapping); + SequenceToSequenceMapping mapping2 = acf.getCoveringCodonMapping(cds.getDatasetSequence()); + assertSame(mapping, mapping2); + + /* + * with a mapping that extends to stop codon + * (EMBL CDS location often includes the stop codon) + * - getCoveringCodonMapping is lenient (doesn't require exact length match) + */ + SequenceI cds2 = new Sequence("cds/1-12", "-A--TGGC-GGACTAA"); + cds2.createDatasetSequence(); + acf = new AlignedCodonFrame(); + MapList map4 = new MapList(new int[] { 1, 12 }, new int[] { + 1, 3 }, 3, 1); + acf.addMap(cds2, pep, map4); + mapping = acf.getCoveringCodonMapping(cds2.getDatasetSequence()); + assertNotNull(mapping); + mapping2 = acf.getCoveringCodonMapping(pep); + assertSame(mapping, mapping2); + } } -- 1.7.10.2