From: gmungoc Date: Tue, 11 Aug 2020 11:10:14 +0000 (+0100) Subject: JAL-3706 handle e.g. mapped exon feature extending beyond mapped range X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=62c6e630bd24574d279417dd6b4ee921b5537131;p=jalview.git JAL-3706 handle e.g. mapped exon feature extending beyond mapped range --- diff --git a/src/jalview/datamodel/MappedFeatures.java b/src/jalview/datamodel/MappedFeatures.java index 1f672be..2bc82bc 100644 --- a/src/jalview/datamodel/MappedFeatures.java +++ b/src/jalview/datamodel/MappedFeatures.java @@ -296,21 +296,30 @@ public class MappedFeatures { int[] result = null; MapList map = mapping.getMap(); + + /* + * mapping may be in either direction, so handle either case; + * limit feature extent to the range of the mapping if it is greater + * (e.g. an overlapping exon); if that still fails, try reducing by + * 3 positions (to omit a mapped stop codon) + */ if (mapping.to == featureSequence) { + begin = Math.max(begin, map.getToLowest()); + end = Math.min(end, map.getToHighest()); result = map.locateInFrom(begin, end); if (result == null) { - // fudge for feature (e.g. CDS) extending to a mapped stop codon result = map.locateInFrom(begin, end-3); } } else { + begin = Math.max(begin, map.getFromLowest()); + end = Math.min(end, map.getFromHighest()); result = map.locateInTo(begin, end); if (result == null) { - // fudge for feature (e.g. CDS) extending to a mapped stop codon result = map.locateInTo(begin, end-3); } } diff --git a/test/jalview/datamodel/MappedFeaturesTest.java b/test/jalview/datamodel/MappedFeaturesTest.java index 5d00089..06fb303 100644 --- a/test/jalview/datamodel/MappedFeaturesTest.java +++ b/test/jalview/datamodel/MappedFeaturesTest.java @@ -143,13 +143,20 @@ public class MappedFeaturesTest assertEquals(pepPos[1], 2); /* - * scenario: exon feature on CDS including stop codon; + * scenario: CDS feature on CDS including stop codon; */ pepPos = mf.getMappedPositions(10, 21); assertEquals(pepPos[0], 1); assertEquals(pepPos[1], 3); /* + * scenario: exon feature on CDS extending beyond start and stop codons + */ + pepPos = mf.getMappedPositions(2, 222); + assertEquals(pepPos[0], 1); + assertEquals(pepPos[1], 3); + + /* * now with the mapping from protein to CDS */ mapping = new Mapping(cds, map.getInverse());