- * Test the method that computes a map of codon variants for each protein
- * position from "sequence_variant" features on dna
- */
- @Test(groups = "Functional")
- public void testBuildDnaVariantsMap()
- {
- SequenceI dna = new Sequence("dna", "atgAAATTTGGGCCCtag");
- MapList map = new MapList(new int[] { 1, 18 }, new int[] { 1, 5 }, 3, 1);
-
- /*
- * first with no variants on dna
- */
- LinkedHashMap<Integer, List<DnaVariant>[]> variantsMap = AlignmentUtils
- .buildDnaVariantsMap(dna, map);
- assertTrue(variantsMap.isEmpty());
-
- /*
- * single allele codon 1, on base 1
- */
- SequenceFeature sf1 = new SequenceFeature("sequence_variant", "", 1, 1,
- 0f, null);
- sf1.setValue("alleles", "T");
- sf1.setValue("ID", "sequence_variant:rs758803211");
- dna.addSequenceFeature(sf1);
-
- /*
- * two alleles codon 2, on bases 2 and 3 (distinct variants)
- */
- SequenceFeature sf2 = new SequenceFeature("sequence_variant", "", 5, 5,
- 0f, null);
- sf2.setValue("alleles", "T");
- sf2.setValue("ID", "sequence_variant:rs758803212");
- dna.addSequenceFeature(sf2);
- SequenceFeature sf3 = new SequenceFeature("sequence_variant", "", 6, 6,
- 0f, null);
- sf3.setValue("alleles", "G");
- sf3.setValue("ID", "sequence_variant:rs758803213");
- dna.addSequenceFeature(sf3);
-
- /*
- * two alleles codon 3, both on base 2 (one variant)
- */
- SequenceFeature sf4 = new SequenceFeature("sequence_variant", "", 8, 8,
- 0f, null);
- sf4.setValue("alleles", "C, G");
- sf4.setValue("ID", "sequence_variant:rs758803214");
- dna.addSequenceFeature(sf4);
-
- // no alleles on codon 4
-
- /*
- * alleles on codon 5 on all 3 bases (distinct variants)
- */
- SequenceFeature sf5 = new SequenceFeature("sequence_variant", "", 13,
- 13, 0f, null);
- sf5.setValue("alleles", "C, G"); // (C duplicates given base value)
- sf5.setValue("ID", "sequence_variant:rs758803215");
- dna.addSequenceFeature(sf5);
- SequenceFeature sf6 = new SequenceFeature("sequence_variant", "", 14,
- 14, 0f, null);
- sf6.setValue("alleles", "g, a"); // should force to upper-case
- sf6.setValue("ID", "sequence_variant:rs758803216");
- dna.addSequenceFeature(sf6);
-
- SequenceFeature sf7 = new SequenceFeature("sequence_variant", "", 15,
- 15, 0f, null);
- sf7.setValue("alleles", "A, T");
- sf7.setValue("ID", "sequence_variant:rs758803217");
- dna.addSequenceFeature(sf7);
-
- /*
- * build map - expect variants on positions 1, 2, 3, 5
- */
- variantsMap = AlignmentUtils.buildDnaVariantsMap(dna, map);
- assertEquals(4, variantsMap.size());
-
- /*
- * protein residue 1: variant on codon (ATG) base 1, not on 2 or 3
- */
- List<DnaVariant>[] pep1Variants = variantsMap.get(1);
- assertEquals(3, pep1Variants.length);
- assertEquals(1, pep1Variants[0].size());
- assertEquals("A", pep1Variants[0].get(0).base); // codon[1] base
- assertSame(sf1, pep1Variants[0].get(0).variant); // codon[1] variant
- assertEquals(1, pep1Variants[1].size());
- assertEquals("T", pep1Variants[1].get(0).base); // codon[2] base
- assertNull(pep1Variants[1].get(0).variant); // no variant here
- assertEquals(1, pep1Variants[2].size());
- assertEquals("G", pep1Variants[2].get(0).base); // codon[3] base
- assertNull(pep1Variants[2].get(0).variant); // no variant here
-
- /*
- * protein residue 2: variants on codon (AAA) bases 2 and 3
- */
- List<DnaVariant>[] pep2Variants = variantsMap.get(2);
- assertEquals(3, pep2Variants.length);
- assertEquals(1, pep2Variants[0].size());
- // codon[1] base recorded while processing variant on codon[2]
- assertEquals("A", pep2Variants[0].get(0).base);
- assertNull(pep2Variants[0].get(0).variant); // no variant here
- // codon[2] base and variant:
- assertEquals(1, pep2Variants[1].size());
- assertEquals("A", pep2Variants[1].get(0).base);
- assertSame(sf2, pep2Variants[1].get(0).variant);
- // codon[3] base was recorded when processing codon[2] variant
- // and then the variant for codon[3] added to it
- assertEquals(1, pep2Variants[2].size());
- assertEquals("A", pep2Variants[2].get(0).base);
- assertSame(sf3, pep2Variants[2].get(0).variant);
-
- /*
- * protein residue 3: variants on codon (TTT) base 2 only
- */
- List<DnaVariant>[] pep3Variants = variantsMap.get(3);
- assertEquals(3, pep3Variants.length);
- assertEquals(1, pep3Variants[0].size());
- assertEquals("T", pep3Variants[0].get(0).base); // codon[1] base
- assertNull(pep3Variants[0].get(0).variant); // no variant here
- assertEquals(1, pep3Variants[1].size());
- assertEquals("T", pep3Variants[1].get(0).base); // codon[2] base
- assertSame(sf4, pep3Variants[1].get(0).variant); // codon[2] variant
- assertEquals(1, pep3Variants[2].size());
- assertEquals("T", pep3Variants[2].get(0).base); // codon[3] base
- assertNull(pep3Variants[2].get(0).variant); // no variant here
-
- /*
- * three variants on protein position 5
- */
- List<DnaVariant>[] pep5Variants = variantsMap.get(5);
- assertEquals(3, pep5Variants.length);
- assertEquals(1, pep5Variants[0].size());
- assertEquals("C", pep5Variants[0].get(0).base); // codon[1] base
- assertSame(sf5, pep5Variants[0].get(0).variant); // codon[1] variant
- assertEquals(1, pep5Variants[1].size());
- assertEquals("C", pep5Variants[1].get(0).base); // codon[2] base
- assertSame(sf6, pep5Variants[1].get(0).variant); // codon[2] variant
- assertEquals(1, pep5Variants[2].size());
- assertEquals("C", pep5Variants[2].get(0).base); // codon[3] base
- assertSame(sf7, pep5Variants[2].get(0).variant); // codon[3] variant
- }
-
- /**
- * Tests for the method that computes all peptide variants given codon
- * variants
- */
- @Test(groups = "Functional")
- public void testComputePeptideVariants()
- {
- /*
- * scenario: AAATTTCCC codes for KFP
- * variants:
- * GAA -> E source: Ensembl
- * CAA -> Q source: dbSNP
- * TAA -> STOP source: dnSNP
- * AAG synonymous source: COSMIC
- * AAT -> N source: Ensembl
- * ...TTC synonymous source: dbSNP
- * ......CAC,CGC -> H,R source: COSMIC
- * (one variant with two alleles)
- */
- SequenceI peptide = new Sequence("pep/10-12", "KFP");
-
- /*
- * two distinct variants for codon 1 position 1
- * second one has clinical significance
- */
- String ensembl = "Ensembl";
- String dbSnp = "dbSNP";
- String cosmic = "COSMIC";
-
- /*
- * NB setting "id" (as returned by Ensembl for features in JSON format);
- * previously "ID" (as returned for GFF3 format)
- */
- SequenceFeature sf1 = new SequenceFeature("sequence_variant", "", 10,
- 10,
- 0f, ensembl);
- sf1.setValue("alleles", "A,G"); // AAA -> GAA -> K/E
- sf1.setValue("id", "var1.125A>G");
-
- SequenceFeature sf2 = new SequenceFeature("sequence_variant", "", 10,
- 10,
- 0f, dbSnp);
- sf2.setValue("alleles", "A,C"); // AAA -> CAA -> K/Q
- sf2.setValue("id", "var2");
- sf2.setValue("clinical_significance", "Dodgy");
-
- SequenceFeature sf3 = new SequenceFeature("sequence_variant", "", 11,
- 11,
- 0f, dbSnp);
- sf3.setValue("alleles", "A,T"); // AAA -> TAA -> stop codon
- sf3.setValue("id", "var3");
- sf3.setValue("clinical_significance", "Bad");
-
- SequenceFeature sf4 = new SequenceFeature("sequence_variant", "", 12,
- 12,
- 0f, cosmic);
- sf4.setValue("alleles", "A,G"); // AAA -> AAG synonymous
- sf4.setValue("id", "var4");
- sf4.setValue("clinical_significance", "None");
-
- SequenceFeature sf5 = new SequenceFeature("sequence_variant", "", 12,
- 12,
- 0f, ensembl);
- sf5.setValue("alleles", "A,T"); // AAA -> AAT -> K/N
- sf5.setValue("id", "sequence_variant:var5"); // prefix gets stripped off
- sf5.setValue("clinical_significance", "Benign");
-
- SequenceFeature sf6 = new SequenceFeature("sequence_variant", "", 15,
- 15,
- 0f, dbSnp);
- sf6.setValue("alleles", "T,C"); // TTT -> TTC synonymous
- sf6.setValue("id", "var6");
-
- SequenceFeature sf7 = new SequenceFeature("sequence_variant", "", 17,
- 17,
- 0f, cosmic);
- sf7.setValue("alleles", "C,A,G"); // CCC -> CAC,CGC -> P/H/R
- sf7.setValue("id", "var7");
- sf7.setValue("clinical_significance", "Good");
-
- List<DnaVariant> codon1Variants = new ArrayList<>();
- List<DnaVariant> codon2Variants = new ArrayList<>();
- List<DnaVariant> codon3Variants = new ArrayList<>();
-
- List<DnaVariant> codonVariants[] = new ArrayList[3];
- codonVariants[0] = codon1Variants;
- codonVariants[1] = codon2Variants;
- codonVariants[2] = codon3Variants;
-
- /*
- * compute variants for protein position 1
- */
- codon1Variants.add(new DnaVariant("A", sf1));
- codon1Variants.add(new DnaVariant("A", sf2));
- codon1Variants.add(new DnaVariant("A", sf3));
- codon2Variants.add(new DnaVariant("A"));
- // codon2Variants.add(new DnaVariant("A"));
- codon3Variants.add(new DnaVariant("A", sf4));
- codon3Variants.add(new DnaVariant("A", sf5));
- AlignmentUtils.computePeptideVariants(peptide, 10, codonVariants);
-
- /*
- * compute variants for protein position 2
- */
- codon1Variants.clear();
- codon2Variants.clear();
- codon3Variants.clear();
- codon1Variants.add(new DnaVariant("T"));
- codon2Variants.add(new DnaVariant("T"));
- codon3Variants.add(new DnaVariant("T", sf6));
- AlignmentUtils.computePeptideVariants(peptide, 11, codonVariants);
-
- /*
- * compute variants for protein position 3
- */
- codon1Variants.clear();
- codon2Variants.clear();
- codon3Variants.clear();
- codon1Variants.add(new DnaVariant("C"));
- codon2Variants.add(new DnaVariant("C", sf7));
- codon3Variants.add(new DnaVariant("C"));
- AlignmentUtils.computePeptideVariants(peptide, 12, codonVariants);
-
- /*
- * verify added sequence features for
- * var1 K -> E Ensembl
- * var2 K -> Q dbSNP
- * var3 K -> stop
- * var4 synonymous
- * var5 K -> N Ensembl
- * var6 synonymous
- * var7 P -> H COSMIC
- * var8 P -> R COSMIC
- */
- List<SequenceFeature> sfs = peptide.getSequenceFeatures();
- SequenceFeatures.sortFeatures(sfs, true);
- assertEquals(8, sfs.size());
-
- /*
- * features are sorted by start position ascending, but in no
- * particular order where start positions match; asserts here
- * simply match the data returned (the order is not important)
- */
- // AAA -> AAT -> K/N
- SequenceFeature sf = sfs.get(0);
- assertEquals(10, sf.getBegin());
- assertEquals(10, sf.getEnd());
- assertEquals("nonsynonymous_variant", sf.getType());
- assertEquals("p.Lys10Asn", sf.getDescription());
- assertEquals("var5", sf.getValue("id"));
- assertEquals("Benign", sf.getValue("clinical_significance"));
- assertEquals("id=var5;clinical_significance=Benign",
- sf.getAttributes());
- assertEquals(1, sf.links.size());
- assertEquals(
- "p.Lys10Asn var5|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var5",
- sf.links.get(0));
- assertEquals(ensembl, sf.getFeatureGroup());
-
- // AAA -> CAA -> K/Q
- sf = sfs.get(1);
- assertEquals(10, sf.getBegin());
- assertEquals(10, sf.getEnd());
- assertEquals("nonsynonymous_variant", sf.getType());
- assertEquals("p.Lys10Gln", sf.getDescription());
- assertEquals("var2", sf.getValue("id"));
- assertEquals("Dodgy", sf.getValue("clinical_significance"));
- assertEquals("id=var2;clinical_significance=Dodgy", sf.getAttributes());
- assertEquals(1, sf.links.size());
- assertEquals(
- "p.Lys10Gln var2|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var2",
- sf.links.get(0));
- assertEquals(dbSnp, sf.getFeatureGroup());
-
- // AAA -> GAA -> K/E
- sf = sfs.get(2);
- assertEquals(10, sf.getBegin());
- assertEquals(10, sf.getEnd());
- assertEquals("nonsynonymous_variant", sf.getType());
- assertEquals("p.Lys10Glu", sf.getDescription());
- assertEquals("var1.125A>G", sf.getValue("id"));
- assertNull(sf.getValue("clinical_significance"));
- assertEquals("id=var1.125A>G", sf.getAttributes());
- assertEquals(1, sf.links.size());
- // link to variation is urlencoded
- assertEquals(
- "p.Lys10Glu var1.125A>G|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var1.125A%3EG",
- sf.links.get(0));
- assertEquals(ensembl, sf.getFeatureGroup());
-
- // AAA -> TAA -> stop codon
- sf = sfs.get(3);
- assertEquals(10, sf.getBegin());
- assertEquals(10, sf.getEnd());
- assertEquals("stop_gained", sf.getType());
- assertEquals("Aaa/Taa", sf.getDescription());
- assertEquals("var3", sf.getValue("id"));
- assertEquals("Bad", sf.getValue("clinical_significance"));
- assertEquals("id=var3;clinical_significance=Bad", sf.getAttributes());
- assertEquals(1, sf.links.size());
- assertEquals(
- "Aaa/Taa var3|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var3",
- sf.links.get(0));
- assertEquals(dbSnp, sf.getFeatureGroup());
-
- // AAA -> AAG synonymous
- sf = sfs.get(4);
- assertEquals(10, sf.getBegin());
- assertEquals(10, sf.getEnd());
- assertEquals("synonymous_variant", sf.getType());
- assertEquals("aaA/aaG", sf.getDescription());
- assertEquals("var4", sf.getValue("id"));
- assertEquals("None", sf.getValue("clinical_significance"));
- assertEquals("id=var4;clinical_significance=None", sf.getAttributes());
- assertEquals(1, sf.links.size());
- assertEquals(
- "aaA/aaG var4|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var4",
- sf.links.get(0));
- assertEquals(cosmic, sf.getFeatureGroup());
-
- // TTT -> TTC synonymous
- sf = sfs.get(5);
- assertEquals(11, sf.getBegin());
- assertEquals(11, sf.getEnd());
- assertEquals("synonymous_variant", sf.getType());
- assertEquals("ttT/ttC", sf.getDescription());
- assertEquals("var6", sf.getValue("id"));
- assertNull(sf.getValue("clinical_significance"));
- assertEquals("id=var6", sf.getAttributes());
- assertEquals(1, sf.links.size());
- assertEquals(
- "ttT/ttC var6|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var6",
- sf.links.get(0));
- assertEquals(dbSnp, sf.getFeatureGroup());
-
- // var7 generates two distinct protein variant features (two alleles)
- // CCC -> CGC -> P/R
- sf = sfs.get(6);
- assertEquals(12, sf.getBegin());
- assertEquals(12, sf.getEnd());
- assertEquals("nonsynonymous_variant", sf.getType());
- assertEquals("p.Pro12Arg", sf.getDescription());
- assertEquals("var7", sf.getValue("id"));
- assertEquals("Good", sf.getValue("clinical_significance"));
- assertEquals("id=var7;clinical_significance=Good", sf.getAttributes());
- assertEquals(1, sf.links.size());
- assertEquals(
- "p.Pro12Arg var7|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var7",
- sf.links.get(0));
- assertEquals(cosmic, sf.getFeatureGroup());
-
- // CCC -> CAC -> P/H
- sf = sfs.get(7);
- assertEquals(12, sf.getBegin());
- assertEquals(12, sf.getEnd());
- assertEquals("nonsynonymous_variant", sf.getType());
- assertEquals("p.Pro12His", sf.getDescription());
- assertEquals("var7", sf.getValue("id"));
- assertEquals("Good", sf.getValue("clinical_significance"));
- assertEquals("id=var7;clinical_significance=Good", sf.getAttributes());
- assertEquals(1, sf.links.size());
- assertEquals(
- "p.Pro12His var7|http://www.ensembl.org/Homo_sapiens/Variation/Summary?v=var7",
- sf.links.get(0));
- assertEquals(cosmic, sf.getFeatureGroup());
- }
-
- /**