1 package jalview.io.vcf;
3 import static jalview.io.gff.SequenceOntologyI.SEQUENCE_VARIANT;
4 import static org.testng.Assert.assertEquals;
5 import static org.testng.Assert.assertNull;
6 import static org.testng.Assert.assertSame;
7 import static org.testng.Assert.assertTrue;
9 import jalview.bin.Cache;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.DBRefEntry;
12 import jalview.datamodel.Mapping;
13 import jalview.datamodel.Sequence;
14 import jalview.datamodel.SequenceFeature;
15 import jalview.datamodel.SequenceI;
16 import jalview.datamodel.features.FeatureAttributes;
17 import jalview.datamodel.features.SequenceFeatures;
18 import jalview.gui.AlignFrame;
19 import jalview.io.DataSourceType;
20 import jalview.io.FileLoader;
21 import jalview.io.gff.Gff3Helper;
22 import jalview.util.MapList;
25 import java.io.IOException;
26 import java.io.PrintWriter;
27 import java.util.List;
30 import org.testng.annotations.BeforeClass;
31 import org.testng.annotations.BeforeTest;
32 import org.testng.annotations.Test;
34 public class VCFLoaderTest
36 private static final float DELTA = 0.00001f;
38 // columns 9717- of gene P30419 from Ensembl (much modified)
39 private static final String FASTA = ""
42 * forward strand 'gene' and 'transcript' with two exons
44 ">gene1/1-25 chromosome:GRCh38:17:45051610:45051634:1\n"
45 + "CAAGCTGGCGGACGAGAGTGTGACA\n"
46 + ">transcript1/1-18\n--AGCTGGCG----AGAGTGTGAC-\n"
49 * reverse strand gene and transcript (reverse complement alleles!)
51 + ">gene2/1-25 chromosome:GRCh38:17:45051610:45051634:-1\n"
52 + "TGTCACACTCTCGTCCGCCAGCTTG\n"
53 + ">transcript2/1-18\n" + "-GTCACACTCT----CGCCAGCT--\n"
56 * 'gene' on chromosome 5 with two transcripts
58 + ">gene3/1-25 chromosome:GRCh38:5:45051610:45051634:1\n"
59 + "CAAGCTGGCGGACGAGAGTGTGACA\n"
60 + ">transcript3/1-18\n--AGCTGGCG----AGAGTGTGAC-\n"
61 + ">transcript4/1-18\n-----TGG-GGACGAGAGTGTGA-A\n";
63 private static final String[] VCF = { "##fileformat=VCFv4.2",
64 // fields other than AF are ignored when parsing as they have no INFO definition
65 "##INFO=<ID=AF,Number=A,Type=Float,Description=\"Allele Frequency, for each ALT allele, in the same order as listed\">",
66 "##INFO=<ID=AC_Female,Number=A,Type=Integer,Description=\"Allele count in Female genotypes\"",
67 "##INFO=<ID=AF_AFR,Number=A,Type=Float,Description=\"Allele Frequency among African/African American genotypes\"",
68 "##reference=Homo_sapiens/GRCh38",
69 "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO",
70 // A/T,C variants in position 2 of gene sequence (precedes transcript)
71 // should create 2 variant features with respective AF values
72 // malformed values for AC_Female and AF_AFR should be ignored
73 "17\t45051611\trs384765\tA\tT,C\t1666.64\tRF;XYZ\tAC=15;AF=5.0e-03,4.0e-03;AC_Female=12,3d;AF_AFR=low,2.3e-4",
74 // SNP G/C in position 4 of gene sequence, position 2 of transcript
75 // insertion G/GA is transferred to nucleotide but not to peptide
76 "17\t45051613\t.\tG\tGA,C\t1666.65\t.\tAC=15;AF=3.0e-03,2.0e-03",
77 // '.' in INFO field should be ignored
78 "17\t45051615\t.\tG\tC\t1666.66\tRF\tAC=16;AF=." };
80 @BeforeClass(alwaysRun = true)
84 * configure to capture all available VCF and VEP (CSQ) fields
86 Cache.loadProperties("test/jalview/io/testProps.jvprops");
87 Cache.setProperty("VCF_FIELDS", ".*");
88 Cache.setProperty("VEP_FIELDS", ".*");
89 Cache.setProperty("VCF_ASSEMBLY", "GRCh38=GRCh38");
93 @BeforeTest(alwaysRun = true)
94 public void setUpBeforeTest()
97 * clear down feature attributes metadata
99 FeatureAttributes.getInstance().clear();
102 @Test(groups = "Functional")
103 public void testDoLoad() throws IOException
105 AlignmentI al = buildAlignment();
107 File f = makeVcfFile();
108 VCFLoader loader = new VCFLoader(f.getPath());
110 loader.doLoad(al.getSequencesArray(), null);
113 * verify variant feature(s) added to gene
114 * NB alleles at a locus may not be processed, and features added,
115 * in the order in which they appear in the VCF record as method
116 * VariantContext.getAlternateAlleles() does not guarantee order
117 * - order of assertions here matches what we find (is not important)
119 List<SequenceFeature> geneFeatures = al.getSequenceAt(0)
120 .getSequenceFeatures();
121 SequenceFeatures.sortFeatures(geneFeatures, true);
122 assertEquals(geneFeatures.size(), 5);
123 SequenceFeature sf = geneFeatures.get(0);
124 assertEquals(sf.getFeatureGroup(), "VCF");
125 assertEquals(sf.getBegin(), 2);
126 assertEquals(sf.getEnd(), 2);
127 assertEquals(sf.getScore(), 0f);
128 assertEquals(sf.getValue("AF"), "4.0e-03");
129 assertEquals(sf.getValue("AF_AFR"), "2.3e-4");
130 assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,C");
131 assertEquals(sf.getType(), SEQUENCE_VARIANT);
132 assertEquals(sf.getValue("POS"), "45051611");
133 assertEquals(sf.getValue("ID"), "rs384765");
134 assertEquals(sf.getValue("QUAL"), "1666.64");
135 assertEquals(sf.getValue("FILTER"), "RF;XYZ");
136 // malformed integer for AC_Female is ignored (JAL-3375)
137 assertNull(sf.getValue("AC_Female"));
139 sf = geneFeatures.get(1);
140 assertEquals(sf.getFeatureGroup(), "VCF");
141 assertEquals(sf.getBegin(), 2);
142 assertEquals(sf.getEnd(), 2);
143 assertEquals(sf.getType(), SEQUENCE_VARIANT);
144 assertEquals(sf.getScore(), 0f);
145 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
147 assertEquals(sf.getValue("AC_Female"), "12");
148 // malformed float for AF_AFR is ignored (JAL-3375)
149 assertNull(sf.getValue("AC_AFR"));
150 assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,T");
152 sf = geneFeatures.get(2);
153 assertEquals(sf.getFeatureGroup(), "VCF");
154 assertEquals(sf.getBegin(), 4);
155 assertEquals(sf.getEnd(), 4);
156 assertEquals(sf.getType(), SEQUENCE_VARIANT);
157 assertEquals(sf.getScore(), 0f);
158 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
160 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
162 sf = geneFeatures.get(3);
163 assertEquals(sf.getFeatureGroup(), "VCF");
164 assertEquals(sf.getBegin(), 4);
165 assertEquals(sf.getEnd(), 4);
166 assertEquals(sf.getType(), SEQUENCE_VARIANT);
167 assertEquals(sf.getScore(), 0f);
168 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
170 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
171 assertNull(sf.getValue("ID")); // '.' is ignored
172 assertNull(sf.getValue("FILTER")); // '.' is ignored
174 sf = geneFeatures.get(4);
175 assertEquals(sf.getFeatureGroup(), "VCF");
176 assertEquals(sf.getBegin(), 6);
177 assertEquals(sf.getEnd(), 6);
178 assertEquals(sf.getType(), SEQUENCE_VARIANT);
179 assertEquals(sf.getScore(), 0f);
180 // AF=. should not have been captured
181 assertNull(sf.getValue("AF"));
182 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
185 * verify variant feature(s) added to transcript
187 List<SequenceFeature> transcriptFeatures = al.getSequenceAt(1)
188 .getSequenceFeatures();
189 assertEquals(transcriptFeatures.size(), 3);
190 sf = transcriptFeatures.get(0);
191 assertEquals(sf.getFeatureGroup(), "VCF");
192 assertEquals(sf.getBegin(), 2);
193 assertEquals(sf.getEnd(), 2);
194 assertEquals(sf.getType(), SEQUENCE_VARIANT);
195 assertEquals(sf.getScore(), 0f);
196 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
198 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
199 sf = transcriptFeatures.get(1);
200 assertEquals(sf.getFeatureGroup(), "VCF");
201 assertEquals(sf.getBegin(), 2);
202 assertEquals(sf.getEnd(), 2);
203 assertEquals(sf.getType(), SEQUENCE_VARIANT);
204 assertEquals(sf.getScore(), 0f);
205 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
207 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
210 * verify SNP variant feature(s) computed and added to protein
211 * first codon AGC varies to ACC giving S/T
213 List<DBRefEntry> dbRefs = al.getSequenceAt(1).getDBRefs();
214 SequenceI peptide = null;
215 for (DBRefEntry dbref : dbRefs)
217 if (dbref.getMap().getMap().getFromRatio() == 3)
219 peptide = dbref.getMap().getTo();
222 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
225 * JAL-3187 don't precompute protein features, do dynamically instead
227 assertTrue(proteinFeatures.isEmpty());
230 private File makeVcfFile() throws IOException
232 File f = File.createTempFile("Test", ".vcf");
234 PrintWriter pw = new PrintWriter(f);
235 for (String vcfLine : VCF)
244 * Make a simple alignment with one 'gene' and one 'transcript'
248 private AlignmentI buildAlignment()
250 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
251 DataSourceType.PASTE);
254 * map gene1 sequence to chromosome (normally done when the sequence is fetched
255 * from Ensembl and transcripts computed)
257 AlignmentI alignment = af.getViewport().getAlignment();
258 SequenceI gene1 = alignment.findName("gene1");
259 int[] to = new int[] { 45051610, 45051634 };
260 int[] from = new int[] { gene1.getStart(), gene1.getEnd() };
261 gene1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
265 * map 'transcript1' to chromosome via 'gene1'
266 * transcript1/1-18 is gene1/3-10,15-24
267 * which is chromosome 45051612-45051619,45051624-45051633
269 to = new int[] { 45051612, 45051619, 45051624, 45051633 };
270 SequenceI transcript1 = alignment.findName("transcript1");
271 from = new int[] { transcript1.getStart(), transcript1.getEnd() };
272 transcript1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
277 * map gene2 to chromosome reverse strand
279 SequenceI gene2 = alignment.findName("gene2");
280 to = new int[] { 45051634, 45051610 };
281 from = new int[] { gene2.getStart(), gene2.getEnd() };
282 gene2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
286 * map 'transcript2' to chromosome via 'gene2'
287 * transcript2/1-18 is gene2/2-11,16-23
288 * which is chromosome 45051633-45051624,45051619-45051612
290 to = new int[] { 45051633, 45051624, 45051619, 45051612 };
291 SequenceI transcript2 = alignment.findName("transcript2");
292 from = new int[] { transcript2.getStart(), transcript2.getEnd() };
293 transcript2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
298 * add a protein product as a DBRef on transcript1
300 SequenceI peptide1 = new Sequence("ENSP001", "SWRECD");
301 MapList mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 },
303 Mapping map = new Mapping(peptide1, mapList);
304 DBRefEntry product = new DBRefEntry("", "", "ENSP001", map);
305 transcript1.addDBRef(product);
308 * add a protein product as a DBRef on transcript2
310 SequenceI peptide2 = new Sequence("ENSP002", "VTLSPA");
311 mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 }, 3, 1);
312 map = new Mapping(peptide2, mapList);
313 product = new DBRefEntry("", "", "ENSP002", map);
314 transcript2.addDBRef(product);
317 * map gene3 to chromosome
319 SequenceI gene3 = alignment.findName("gene3");
320 to = new int[] { 45051610, 45051634 };
321 from = new int[] { gene3.getStart(), gene3.getEnd() };
322 gene3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(from, to,
326 * map 'transcript3' to chromosome
328 SequenceI transcript3 = alignment.findName("transcript3");
329 to = new int[] { 45051612, 45051619, 45051624, 45051633 };
330 from = new int[] { transcript3.getStart(), transcript3.getEnd() };
331 transcript3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
336 * map 'transcript4' to chromosome
338 SequenceI transcript4 = alignment.findName("transcript4");
339 to = new int[] { 45051615, 45051617, 45051619, 45051632, 45051634,
341 from = new int[] { transcript4.getStart(), transcript4.getEnd() };
342 transcript4.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
347 * add a protein product as a DBRef on transcript3
349 SequenceI peptide3 = new Sequence("ENSP003", "SWRECD");
350 mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 }, 3, 1);
351 map = new Mapping(peptide3, mapList);
352 product = new DBRefEntry("", "", "ENSP003", map);
353 transcript3.addDBRef(product);
359 * Test with 'gene' and 'transcript' mapped to the reverse strand of the
360 * chromosome. The VCF variant positions (in forward coordinates) should get
361 * correctly located on sequence positions.
363 * @throws IOException
365 @Test(groups = "Functional")
366 public void testDoLoad_reverseStrand() throws IOException
368 AlignmentI al = buildAlignment();
370 File f = makeVcfFile();
372 VCFLoader loader = new VCFLoader(f.getPath());
374 loader.doLoad(al.getSequencesArray(), null);
377 * verify variant feature(s) added to gene2
378 * gene2/1-25 maps to chromosome 45051634- reverse strand
380 List<SequenceFeature> geneFeatures = al.getSequenceAt(2)
381 .getSequenceFeatures();
382 SequenceFeatures.sortFeatures(geneFeatures, true);
383 assertEquals(geneFeatures.size(), 5);
387 * insertion G/GA at 45051613 maps to an insertion at
388 * the preceding position (21) on reverse strand gene
389 * reference: CAAGC -> GCTTG/21-25
390 * genomic variant: CAAGAC (G/GA)
391 * gene variant: GTCTTG (G/GT at 21)
393 sf = geneFeatures.get(1);
394 assertEquals(sf.getFeatureGroup(), "VCF");
395 assertEquals(sf.getBegin(), 21);
396 assertEquals(sf.getEnd(), 21);
397 assertEquals(sf.getType(), SEQUENCE_VARIANT);
398 assertEquals(sf.getScore(), 0f);
399 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
400 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
404 * variant G/C at 45051613 maps to C/G at gene position 22
406 sf = geneFeatures.get(2);
407 assertEquals(sf.getFeatureGroup(), "VCF");
408 assertEquals(sf.getBegin(), 22);
409 assertEquals(sf.getEnd(), 22);
410 assertEquals(sf.getType(), SEQUENCE_VARIANT);
411 assertEquals(sf.getScore(), 0f);
412 assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
413 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
417 * variant A/C at 45051611 maps to T/G at gene position 24
419 sf = geneFeatures.get(3);
420 assertEquals(sf.getFeatureGroup(), "VCF");
421 assertEquals(sf.getBegin(), 24);
422 assertEquals(sf.getEnd(), 24);
423 assertEquals(sf.getType(), SEQUENCE_VARIANT);
424 assertEquals(sf.getScore(), 0f);
425 assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,G");
426 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
430 * variant A/T at 45051611 maps to T/A at gene position 24
432 sf = geneFeatures.get(4);
433 assertEquals(sf.getFeatureGroup(), "VCF");
434 assertEquals(sf.getBegin(), 24);
435 assertEquals(sf.getEnd(), 24);
436 assertEquals(sf.getType(), SEQUENCE_VARIANT);
437 assertEquals(sf.getScore(), 0f);
438 assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,A");
439 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
443 * verify 3 variant features added to transcript2
445 List<SequenceFeature> transcriptFeatures = al.getSequenceAt(3)
446 .getSequenceFeatures();
447 assertEquals(transcriptFeatures.size(), 3);
450 * insertion G/GT at position 21 of gene maps to position 16 of transcript
452 sf = transcriptFeatures.get(1);
453 assertEquals(sf.getFeatureGroup(), "VCF");
454 assertEquals(sf.getBegin(), 16);
455 assertEquals(sf.getEnd(), 16);
456 assertEquals(sf.getType(), SEQUENCE_VARIANT);
457 assertEquals(sf.getScore(), 0f);
458 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
459 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
463 * SNP C/G at position 22 of gene maps to position 17 of transcript
465 sf = transcriptFeatures.get(2);
466 assertEquals(sf.getFeatureGroup(), "VCF");
467 assertEquals(sf.getBegin(), 17);
468 assertEquals(sf.getEnd(), 17);
469 assertEquals(sf.getType(), SEQUENCE_VARIANT);
470 assertEquals(sf.getScore(), 0f);
471 assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
472 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
476 * verify variant feature(s) computed and added to protein
477 * last codon GCT varies to GGT giving A/G in the last peptide position
479 List<DBRefEntry> dbRefs = al.getSequenceAt(3).getDBRefs();
480 SequenceI peptide = null;
481 for (DBRefEntry dbref : dbRefs)
483 if (dbref.getMap().getMap().getFromRatio() == 3)
485 peptide = dbref.getMap().getTo();
488 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
491 * JAL-3187 don't precompute protein features, do dynamically instead
493 assertTrue(proteinFeatures.isEmpty());
497 * Tests that if VEP consequence (CSQ) data is present in the VCF data, then
498 * it is added to the variant feature, but restricted where possible to the
499 * consequences for a specific transcript
501 * @throws IOException
503 @Test(groups = "Functional")
504 public void testDoLoad_vepCsq() throws IOException
506 AlignmentI al = buildAlignment();
508 VCFLoader loader = new VCFLoader("test/jalview/io/vcf/testVcf.vcf");
511 * VCF data file with variants at gene3 positions
516 * 17 A/AC (insertion), A/G
518 loader.doLoad(al.getSequencesArray(), null);
521 * verify variant feature(s) added to gene3
523 List<SequenceFeature> geneFeatures = al.findName("gene3")
524 .getSequenceFeatures();
525 SequenceFeatures.sortFeatures(geneFeatures, true);
526 assertEquals(geneFeatures.size(), 7);
527 SequenceFeature sf = geneFeatures.get(0);
528 assertEquals(sf.getBegin(), 1);
529 assertEquals(sf.getEnd(), 1);
530 assertEquals(sf.getScore(), 0f);
531 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.1f, DELTA);
532 assertEquals(sf.getValue("alleles"), "C,A");
533 // gene features include Consequence for all transcripts
534 Map map = (Map) sf.getValue("CSQ");
535 assertEquals(map.size(), 9);
536 assertEquals(map.get("PolyPhen"), "Bad");
538 sf = geneFeatures.get(1);
539 assertEquals(sf.getBegin(), 5);
540 assertEquals(sf.getEnd(), 5);
541 assertEquals(sf.getScore(), 0f);
542 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
543 assertEquals(sf.getValue("alleles"), "C,T");
544 map = (Map) sf.getValue("CSQ");
545 assertEquals(map.size(), 9);
546 assertEquals(map.get("PolyPhen"), "Bad++"); // %3B%3B decoded
548 sf = geneFeatures.get(2);
549 assertEquals(sf.getBegin(), 9);
550 assertEquals(sf.getEnd(), 11); // deletion over 3 positions
551 assertEquals(sf.getScore(), 0f);
552 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.3f, DELTA);
553 assertEquals(sf.getValue("alleles"), "CGG,C");
554 map = (Map) sf.getValue("CSQ");
555 assertEquals(map.size(), 9);
557 sf = geneFeatures.get(3);
558 assertEquals(sf.getBegin(), 13);
559 assertEquals(sf.getEnd(), 13);
560 assertEquals(sf.getScore(), 0f);
561 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
562 assertEquals(sf.getValue("alleles"), "C,T");
563 map = (Map) sf.getValue("CSQ");
564 assertEquals(map.size(), 9);
566 sf = geneFeatures.get(4);
567 assertEquals(sf.getBegin(), 13);
568 assertEquals(sf.getEnd(), 13);
569 assertEquals(sf.getScore(), 0f);
570 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
571 assertEquals(sf.getValue("alleles"), "C,G");
572 map = (Map) sf.getValue("CSQ");
573 assertEquals(map.size(), 9);
575 sf = geneFeatures.get(5);
576 assertEquals(sf.getBegin(), 17);
577 assertEquals(sf.getEnd(), 17);
578 assertEquals(sf.getScore(), 0f);
579 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
580 assertEquals(sf.getValue("alleles"), "A,G");
581 map = (Map) sf.getValue("CSQ");
582 assertEquals(map.size(), 9);
584 sf = geneFeatures.get(6);
585 assertEquals(sf.getBegin(), 17);
586 assertEquals(sf.getEnd(), 17); // insertion
587 assertEquals(sf.getScore(), 0f);
588 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
589 assertEquals(sf.getValue("alleles"), "A,AC");
590 map = (Map) sf.getValue("CSQ");
591 assertEquals(map.size(), 9);
594 * verify variant feature(s) added to transcript3
595 * at columns 5 (1), 17 (2), positions 3, 11
596 * note the deletion at columns 9-11 is not transferred since col 11
597 * has no mapping to transcript 3
599 List<SequenceFeature> transcriptFeatures = al.findName("transcript3")
600 .getSequenceFeatures();
601 SequenceFeatures.sortFeatures(transcriptFeatures, true);
602 assertEquals(transcriptFeatures.size(), 3);
603 sf = transcriptFeatures.get(0);
604 assertEquals(sf.getBegin(), 3);
605 assertEquals(sf.getEnd(), 3);
606 assertEquals(sf.getScore(), 0f);
607 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
608 assertEquals(sf.getValue("alleles"), "C,T");
609 // transcript features only have Consequence for that transcripts
610 map = (Map) sf.getValue("CSQ");
611 assertEquals(map.size(), 9);
612 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
614 sf = transcriptFeatures.get(1);
615 assertEquals(sf.getBegin(), 11);
616 assertEquals(sf.getEnd(), 11);
617 assertEquals(sf.getScore(), 0f);
618 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
619 assertEquals(sf.getValue("alleles"), "A,G");
620 assertEquals(map.size(), 9);
621 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
623 sf = transcriptFeatures.get(2);
624 assertEquals(sf.getBegin(), 11);
625 assertEquals(sf.getEnd(), 11);
626 assertEquals(sf.getScore(), 0f);
627 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
628 assertEquals(sf.getValue("alleles"), "A,AC");
629 assertEquals(map.size(), 9);
630 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
633 * verify variants computed on protein product for transcript3
635 * codon variants are AGC/AGT position 1 which is synonymous
636 * and GAG/GGG which is E/G in position 4
637 * the insertion variant is not transferred to the peptide
639 List<DBRefEntry> dbRefs = al.findName("transcript3").getDBRefs();
640 SequenceI peptide = null;
641 for (DBRefEntry dbref : dbRefs)
643 if (dbref.getMap().getMap().getFromRatio() == 3)
645 peptide = dbref.getMap().getTo();
648 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
650 * JAL-3187 don't precompute protein features, do dynamically instead
652 assertTrue(proteinFeatures.isEmpty());
653 // SequenceFeatures.sortFeatures(proteinFeatures, true);
654 // assertEquals(proteinFeatures.size(), 2);
655 // sf = proteinFeatures.get(0);
656 // assertEquals(sf.getFeatureGroup(), "VCF");
657 // assertEquals(sf.getBegin(), 1);
658 // assertEquals(sf.getEnd(), 1);
659 // assertEquals(sf.getType(), SequenceOntologyI.SYNONYMOUS_VARIANT);
660 // assertEquals(sf.getDescription(), "agC/agT");
661 // sf = proteinFeatures.get(1);
662 // assertEquals(sf.getFeatureGroup(), "VCF");
663 // assertEquals(sf.getBegin(), 4);
664 // assertEquals(sf.getEnd(), 4);
665 // assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
666 // assertEquals(sf.getDescription(), "p.Glu4Gly");
669 * verify variant feature(s) added to transcript4
670 * at columns 13 (2) and 17 (2), positions 7 and 11
672 transcriptFeatures = al.findName("transcript4").getSequenceFeatures();
673 SequenceFeatures.sortFeatures(transcriptFeatures, true);
674 assertEquals(transcriptFeatures.size(), 4);
675 sf = transcriptFeatures.get(0);
676 assertEquals(sf.getBegin(), 7);
677 assertEquals(sf.getEnd(), 7);
678 assertEquals(sf.getScore(), 0f);
679 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
680 assertEquals(sf.getValue("alleles"), "C,T");
681 assertEquals(map.size(), 9);
682 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
684 sf = transcriptFeatures.get(1);
685 assertEquals(sf.getBegin(), 7);
686 assertEquals(sf.getEnd(), 7);
687 assertEquals(sf.getScore(), 0f);
688 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
689 assertEquals(sf.getValue("alleles"), "C,G");
690 assertEquals(map.size(), 9);
691 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
693 sf = transcriptFeatures.get(2);
694 assertEquals(sf.getBegin(), 11);
695 assertEquals(sf.getEnd(), 11);
696 assertEquals(sf.getScore(), 0f);
697 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
698 assertEquals(sf.getValue("alleles"), "A,G");
699 assertEquals(map.size(), 9);
700 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
702 sf = transcriptFeatures.get(3);
703 assertEquals(sf.getBegin(), 11);
704 assertEquals(sf.getEnd(), 11);
705 assertEquals(sf.getScore(), 0f);
706 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
707 assertEquals(sf.getValue("alleles"), "A,AC");
708 assertEquals(map.size(), 9);
709 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
713 * A test that demonstrates loading a contig sequence from an indexed sequence
714 * database which is the reference for a VCF file
716 * @throws IOException
718 @Test(groups = "Functional")
719 public void testLoadVCFContig() throws IOException
721 VCFLoader loader = new VCFLoader(
722 "test/jalview/io/vcf/testVcf2.vcf");
724 SequenceI seq = loader.loadVCFContig("contig123");
725 assertEquals(seq.getLength(), 15);
726 assertEquals(seq.getSequenceAsString(), "AAAAACCCCCGGGGG");
727 List<SequenceFeature> features = seq.getSequenceFeatures();
728 SequenceFeatures.sortFeatures(features, true);
729 assertEquals(features.size(), 2);
730 SequenceFeature sf = features.get(0);
731 assertEquals(sf.getBegin(), 8);
732 assertEquals(sf.getEnd(), 8);
733 assertEquals(sf.getDescription(), "C,A");
734 sf = features.get(1);
735 assertEquals(sf.getBegin(), 12);
736 assertEquals(sf.getEnd(), 12);
737 assertEquals(sf.getDescription(), "G,T");
739 seq = loader.loadVCFContig("contig789");
740 assertEquals(seq.getLength(), 25);
741 assertEquals(seq.getSequenceAsString(), "GGGGGTTTTTAAAAACCCCCGGGGG");
742 features = seq.getSequenceFeatures();
743 SequenceFeatures.sortFeatures(features, true);
744 assertEquals(features.size(), 2);
745 sf = features.get(0);
746 assertEquals(sf.getBegin(), 2);
747 assertEquals(sf.getEnd(), 2);
748 assertEquals(sf.getDescription(), "G,T");
749 sf = features.get(1);
750 assertEquals(sf.getBegin(), 21);
751 assertEquals(sf.getEnd(), 21);
752 assertEquals(sf.getDescription(), "G,A");
754 seq = loader.loadVCFContig("contig456");
755 assertEquals(seq.getLength(), 20);
756 assertEquals(seq.getSequenceAsString(), "CCCCCGGGGGTTTTTAAAAA");
757 features = seq.getSequenceFeatures();
758 SequenceFeatures.sortFeatures(features, true);
759 assertEquals(features.size(), 1);
760 sf = features.get(0);
761 assertEquals(sf.getBegin(), 15);
762 assertEquals(sf.getEnd(), 15);
763 assertEquals(sf.getDescription(), "T,C");
766 @Test(groups = "Functional")
767 public void testDecodeSpecialCharacters() throws IOException
769 String encoded = "hello world";
770 String decoded = VCFLoader.decodeSpecialCharacters(encoded);
771 assertSame(encoded, decoded); // no change needed
773 encoded = "ab%3Acd%3Bef%3Dgh%25ij%2Ckl%3A";
774 decoded = VCFLoader.decodeSpecialCharacters(encoded);
775 assertEquals(decoded, "ab:cd;ef=gh%ij,kl:");