1 package jalview.datamodel;
3 import static org.testng.Assert.assertEquals;
5 import java.util.ArrayList;
6 import java.util.HashMap;
10 import org.testng.annotations.Test;
12 import jalview.util.MapList;
14 public class MappedFeaturesTest
16 @Test(groups = "Functional")
17 public void testFindProteinVariants()
21 * dna/10-20 aCGTaGctGAa (codons CGT=R, GGA = G)
22 * mapping: 3:1 from [11-13,15,18-19] to peptide/1-2 RG
24 SequenceI from = new Sequence("dna/10-20", "aCGTaGctGAa");
25 SequenceI to = new Sequence("peptide", "RG");
26 MapList map = new MapList(new int[] { 11, 13, 15, 15, 18, 19 },
29 Mapping mapping = new Mapping(to, map);
33 * C>T at dna11, consequence CGT>TGT=C
34 * T>C at dna13, consequence CGT>CGC synonymous
36 List<SequenceFeature> features = new ArrayList<>();
37 SequenceFeature sf1 = new SequenceFeature("sequence_variant", "C,T",
39 sf1.setValue("alleles", "C,T");
41 SequenceFeature sf2 = new SequenceFeature("sequence_variant", "T,C", 13,
43 sf2.setValue("alleles", "T,C");
47 * missense variant in first codon
49 MappedFeatures mf = new MappedFeatures(mapping, from, 1, 'R',
51 String variant = mf.findProteinVariants(sf1);
52 assertEquals(variant, "p.Arg1Cys");
55 * more than one alternative allele
56 * C>G consequence is GGT=G
57 * peptide variants as a comma-separated list
59 sf1.setValue("alleles", "C,T,G");
60 variant = mf.findProteinVariants(sf1);
61 assertEquals(variant, "p.Arg1Cys,p.Arg1Gly");
64 * synonymous variant in first codon
65 * shown in HGVS notation on peptide
67 variant = mf.findProteinVariants(sf2);
68 assertEquals(variant, "c.13T>C(p.=)");
71 * CSQ:HGVSp value is used if present
72 * _and_ it contains "p." following a colon
74 Map<String, String> csq = new HashMap<>();
75 csq.put("HGVSp", "hello:world");
76 sf2.setValue("CSQ", csq);
77 variant = mf.findProteinVariants(sf2);
78 assertEquals(variant, "c.13T>C(p.=)");
79 csq.put("HGVSp", "p.HelloWorld");
80 variant = mf.findProteinVariants(sf2);
81 assertEquals(variant, "c.13T>C(p.=)");
82 csq.put("HGVSp", "try this:hellop.world");
83 variant = mf.findProteinVariants(sf2);
84 assertEquals(variant, "hellop.world");
87 * missense and indel variants in second codon
88 * - codon is GGA spliced from dna positions 15,18,19
89 * - SNP G>T in second position mutates GGA>G to GTA>V
90 * - indel variants are not computed or reported
92 mf = new MappedFeatures(mapping, from, 2, 'G', features);
94 SequenceFeature sf3 = new SequenceFeature("sequence_variant",
95 "G,-,CG,T", 18, 18, null);
96 sf3.setValue("alleles", "G,-,CG,T");
98 variant = mf.findProteinVariants(sf3);
99 assertEquals(variant, "p.Gly2Val");
102 * G>T in first position gives TGA Stop
103 * shown with HGVS notation as 'Ter'
105 SequenceFeature sf4 = new SequenceFeature("sequence_variant", "G,T", 15,
107 sf4.setValue("alleles", "G,-,CG,T");
109 variant = mf.findProteinVariants(sf4);
110 assertEquals(variant, "p.Gly2Ter");
113 * feature must be one of those in MappedFeatures
115 SequenceFeature sf9 = new SequenceFeature("sequence_variant", "G,C", 15,
117 variant = mf.findProteinVariants(sf9);
118 assertEquals(variant, "");
121 @Test(groups = "Functional")
122 public void testGetMappedPositions()
124 // CDS including stop codon taa
125 SequenceI cds = new Sequence("cds/10-21", "ATGcgtGGAtaa");
126 SequenceI peptide = new Sequence("peptide", "MRG"); // ATG, CGT, GGA
129 * emulate 'map from' range based on CDS _including_ stop codon
131 MapList map = new MapList(new int[] { 10, 21 }, new int[] { 1, 3 }, 3,
133 Mapping mapping = new Mapping(peptide, map);
135 MappedFeatures mf = new MappedFeatures(mapping, cds, 2, 'M', null);
138 * scenario: sequence_variant feature on CDS at position 14;
139 * find the corresponding position on peptide
141 int[] pepPos = mf.getMappedPositions(14, 14);
142 assertEquals(pepPos[0], 2);
143 assertEquals(pepPos[1], 2);
146 * scenario: exon feature on CDS including stop codon;
148 pepPos = mf.getMappedPositions(10, 21);
149 assertEquals(pepPos[0], 1);
150 assertEquals(pepPos[1], 3);
153 * now with the mapping from protein to CDS
155 mapping = new Mapping(cds, map.getInverse());
156 mf = new MappedFeatures(mapping, peptide, 15, 't', null);
157 int[] cdsPos = mf.getMappedPositions(2, 2);
158 assertEquals(cdsPos[0], 13);
159 assertEquals(cdsPos[1], 15);