X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2FMappedFeaturesTest.java;fp=test%2Fjalview%2Fdatamodel%2FMappedFeaturesTest.java;h=5d00089205fa8d622d015be2751f3f186b696f0b;hb=881dd37ce1077bce230b6b04690112d9d6eafecd;hp=de4ce6cb49f5ec8437ab99d23a636588215ac4c2;hpb=e6a84268f419fa16fd87f484842150cb0a103ce6;p=jalview.git diff --git a/test/jalview/datamodel/MappedFeaturesTest.java b/test/jalview/datamodel/MappedFeaturesTest.java index de4ce6c..5d00089 100644 --- a/test/jalview/datamodel/MappedFeaturesTest.java +++ b/test/jalview/datamodel/MappedFeaturesTest.java @@ -2,8 +2,6 @@ package jalview.datamodel; import static org.testng.Assert.assertEquals; -import jalview.util.MapList; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -11,6 +9,8 @@ import java.util.Map; import org.testng.annotations.Test; +import jalview.util.MapList; + public class MappedFeaturesTest { @Test(groups = "Functional") @@ -21,7 +21,7 @@ public class MappedFeaturesTest * dna/10-20 aCGTaGctGAa (codons CGT=R, GGA = G) * mapping: 3:1 from [11-13,15,18-19] to peptide/1-2 RG */ - SequenceI from = new Sequence("dna/10-20", "acgTAGCTGAA"); + SequenceI from = new Sequence("dna/10-20", "aCGTaGctGAa"); SequenceI to = new Sequence("peptide", "RG"); MapList map = new MapList(new int[] { 11, 13, 15, 15, 18, 19 }, new int[] @@ -117,4 +117,45 @@ public class MappedFeaturesTest variant = mf.findProteinVariants(sf9); assertEquals(variant, ""); } + + @Test(groups = "Functional") + public void testGetMappedPositions() + { + // CDS including stop codon taa + SequenceI cds = new Sequence("cds/10-21", "ATGcgtGGAtaa"); + SequenceI peptide = new Sequence("peptide", "MRG"); // ATG, CGT, GGA + + /* + * emulate 'map from' range based on CDS _including_ stop codon + */ + MapList map = new MapList(new int[] { 10, 21 }, new int[] { 1, 3 }, 3, + 1); + Mapping mapping = new Mapping(peptide, map); + + MappedFeatures mf = new MappedFeatures(mapping, cds, 2, 'M', null); + + /* + * scenario: sequence_variant feature on CDS at position 14; + * find the corresponding position on peptide + */ + int[] pepPos = mf.getMappedPositions(14, 14); + assertEquals(pepPos[0], 2); + assertEquals(pepPos[1], 2); + + /* + * scenario: exon feature on CDS including stop codon; + */ + pepPos = mf.getMappedPositions(10, 21); + assertEquals(pepPos[0], 1); + assertEquals(pepPos[1], 3); + + /* + * now with the mapping from protein to CDS + */ + mapping = new Mapping(cds, map.getInverse()); + mf = new MappedFeatures(mapping, peptide, 15, 't', null); + int[] cdsPos = mf.getMappedPositions(2, 2); + assertEquals(cdsPos[0], 13); + assertEquals(cdsPos[1], 15); + } }