d4a49c69b2dbaa3027b8d79097154373137768f0
[jalview.git] / test / jalview / datamodel / MappedFeaturesTest.java
1 package jalview.datamodel;
2
3 import static org.testng.Assert.assertEquals;
4
5 import jalview.util.MapList;
6
7 import java.util.ArrayList;
8 import java.util.HashMap;
9 import java.util.List;
10 import java.util.Map;
11
12 import org.testng.annotations.Test;
13
14 public class MappedFeaturesTest
15 {
16   @Test(groups = "Functional")
17   public void testFindProteinVariants()
18   {
19     /*
20      * scenario: 
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 
23      */
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 },
27             new int[]
28             { 1, 2 }, 3, 1);
29     Mapping mapping = new Mapping(to, map);
30
31     /*
32      * variants
33      * C>T at dna11, consequence CGT>TGT=C
34      * T>C at dna13, consequence CGT>CGC synonymous
35      */
36     List<SequenceFeature> features = new ArrayList<>();
37     SequenceFeature sf1 = new SequenceFeature("sequence_variant", "C,T", 11,
38             11, null);
39     sf1.setValue("alleles", "C,T");
40     features.add(sf1);
41     SequenceFeature sf2 = new SequenceFeature("sequence_variant", "T,C", 13,
42             13, null);
43     sf2.setValue("alleles", "T,C");
44     features.add(sf2);
45
46     /*
47      * missense variant in first codon
48      */
49     MappedFeatures mf = new MappedFeatures(mapping, from, 1, 'R', features);
50     String variant = mf.findProteinVariants(sf1);
51     assertEquals(variant, "p.Arg1Cys");
52
53     /*
54      * more than one alternative allele
55      * C>G consequence is GGT=G
56      * peptide variants as a comma-separated list
57      */
58     sf1.setValue("alleles", "C,T,G");
59     variant = mf.findProteinVariants(sf1);
60     assertEquals(variant, "p.Arg1Cys,p.Arg1Gly");
61
62     /*
63      * synonymous variant in first codon
64      * shown in HGVS notation on peptide
65      */
66     variant = mf.findProteinVariants(sf2);
67     assertEquals(variant, "c.13T>C(p.=)");
68
69     /*
70      * CSQ:HGVSp value is used if present 
71      * _and_ it contains "p." following a colon
72      */
73     Map<String, String> csq = new HashMap<>();
74     csq.put("HGVSp", "hello:world");
75     sf2.setValue("CSQ", csq);
76     variant = mf.findProteinVariants(sf2);
77     assertEquals(variant, "c.13T>C(p.=)");
78     csq.put("HGVSp", "p.HelloWorld");
79     variant = mf.findProteinVariants(sf2);
80     assertEquals(variant, "c.13T>C(p.=)");
81     csq.put("HGVSp", "try this:hellop.world");
82     variant = mf.findProteinVariants(sf2);
83     assertEquals(variant, "hellop.world");
84
85     /*
86      * missense and indel variants in second codon
87      * - codon is GGA spliced from dna positions 15,18,19
88      * - SNP G>T in second position mutates GGA>G to GTA>V
89      * - indel variants are not computed or reported
90      */
91     mf = new MappedFeatures(mapping, from, 2, 'G', features);
92     features.clear();
93     SequenceFeature sf3 = new SequenceFeature("sequence_variant",
94             "G,-,CG,T", 18, 18, null);
95     sf3.setValue("alleles", "G,-,CG,T");
96     features.add(sf3);
97     variant = mf.findProteinVariants(sf3);
98     assertEquals(variant, "p.Gly2Val");
99
100     /*
101      * G>T in first position gives TGA Stop
102      * shown with HGVS notation as 'Ter'
103      */
104     SequenceFeature sf4 = new SequenceFeature("sequence_variant", "G,T", 15,
105             15, null);
106     sf4.setValue("alleles", "G,-,CG,T");
107     features.add(sf4);
108     variant = mf.findProteinVariants(sf4);
109     assertEquals(variant, "p.Gly2Ter");
110
111     /*
112      * feature must be one of those in MappedFeatures
113      */
114     SequenceFeature sf9 = new SequenceFeature("sequence_variant", "G,C", 15,
115             15, null);
116     variant = mf.findProteinVariants(sf9);
117     assertEquals(variant, "");
118   }
119 }