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.assertTrue;
8 import jalview.bin.Cache;
9 import jalview.datamodel.AlignmentI;
10 import jalview.datamodel.DBRefEntry;
11 import jalview.datamodel.Mapping;
12 import jalview.datamodel.Sequence;
13 import jalview.datamodel.SequenceFeature;
14 import jalview.datamodel.SequenceI;
15 import jalview.datamodel.features.FeatureAttributes;
16 import jalview.datamodel.features.SequenceFeatures;
17 import jalview.gui.AlignFrame;
18 import jalview.io.DataSourceType;
19 import jalview.io.FileLoader;
20 import jalview.io.gff.Gff3Helper;
21 import jalview.util.MapList;
24 import java.io.IOException;
25 import java.io.PrintWriter;
26 import java.util.List;
29 import org.testng.annotations.BeforeClass;
30 import org.testng.annotations.BeforeTest;
31 import org.testng.annotations.Test;
33 public class VCFLoaderTest
35 private static final float DELTA = 0.00001f;
37 // columns 9717- of gene P30419 from Ensembl (much modified)
38 private static final String FASTA = ""
41 * forward strand 'gene' and 'transcript' with two exons
43 ">gene1/1-25 chromosome:GRCh38:17:45051610:45051634:1\n"
44 + "CAAGCTGGCGGACGAGAGTGTGACA\n"
45 + ">transcript1/1-18\n--AGCTGGCG----AGAGTGTGAC-\n"
48 * reverse strand gene and transcript (reverse complement alleles!)
50 + ">gene2/1-25 chromosome:GRCh38:17:45051610:45051634:-1\n"
51 + "TGTCACACTCTCGTCCGCCAGCTTG\n"
52 + ">transcript2/1-18\n" + "-GTCACACTCT----CGCCAGCT--\n"
55 * 'gene' on chromosome 5 with two transcripts
57 + ">gene3/1-25 chromosome:GRCh38:5:45051610:45051634:1\n"
58 + "CAAGCTGGCGGACGAGAGTGTGACA\n"
59 + ">transcript3/1-18\n--AGCTGGCG----AGAGTGTGAC-\n"
60 + ">transcript4/1-18\n-----TGG-GGACGAGAGTGTGA-A\n";
62 private static final String[] VCF = { "##fileformat=VCFv4.2",
63 // note fields with no INFO definition are ignored when parsing
64 "##INFO=<ID=AF,Number=A,Type=Float,Description=\"Allele Frequency, for each ALT allele, in the same order as listed\">",
65 "##INFO=<ID=AC_Female,Number=A,Type=Integer,Description=\"Allele count in Female genotypes\"",
66 "##INFO=<ID=AF_AFR,Number=A,Type=Float,Description=\"Allele Frequency among African/African American genotypes\"",
67 "##INFO=<ID=CLNSIG,Number=.,Type=String,Description=\"Clinical significance for this single variant\"",
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;CLNSIG=benign,probably_benign",
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");
137 * if INFO declares Number=1, all values are attached to each allele
139 assertEquals(sf.getValue("CLNSIG"), "benign,probably_benign");
140 // malformed integer for AC_Female is ignored (JAL-3375)
141 assertNull(sf.getValue("AC_Female"));
143 sf = geneFeatures.get(1);
144 assertEquals(sf.getFeatureGroup(), "VCF");
145 assertEquals(sf.getBegin(), 2);
146 assertEquals(sf.getEnd(), 2);
147 assertEquals(sf.getType(), SEQUENCE_VARIANT);
148 assertEquals(sf.getScore(), 0f);
149 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
151 assertEquals(sf.getValue("AC_Female"), "12");
152 // malformed float for AF_AFR is ignored (JAL-3375)
153 assertNull(sf.getValue("AC_AFR"));
154 assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,T");
155 assertEquals(sf.getValue("CLNSIG"), "benign,probably_benign");
157 sf = geneFeatures.get(2);
158 assertEquals(sf.getFeatureGroup(), "VCF");
159 assertEquals(sf.getBegin(), 4);
160 assertEquals(sf.getEnd(), 4);
161 assertEquals(sf.getType(), SEQUENCE_VARIANT);
162 assertEquals(sf.getScore(), 0f);
163 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
165 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
167 sf = geneFeatures.get(3);
168 assertEquals(sf.getFeatureGroup(), "VCF");
169 assertEquals(sf.getBegin(), 4);
170 assertEquals(sf.getEnd(), 4);
171 assertEquals(sf.getType(), SEQUENCE_VARIANT);
172 assertEquals(sf.getScore(), 0f);
173 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
175 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
176 assertNull(sf.getValue("ID")); // '.' is ignored
177 assertNull(sf.getValue("FILTER")); // '.' is ignored
179 sf = geneFeatures.get(4);
180 assertEquals(sf.getFeatureGroup(), "VCF");
181 assertEquals(sf.getBegin(), 6);
182 assertEquals(sf.getEnd(), 6);
183 assertEquals(sf.getType(), SEQUENCE_VARIANT);
184 assertEquals(sf.getScore(), 0f);
185 // AF=. should not have been captured
186 assertNull(sf.getValue("AF"));
187 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
190 * verify variant feature(s) added to transcript
192 List<SequenceFeature> transcriptFeatures = al.getSequenceAt(1)
193 .getSequenceFeatures();
194 assertEquals(transcriptFeatures.size(), 3);
195 sf = transcriptFeatures.get(0);
196 assertEquals(sf.getFeatureGroup(), "VCF");
197 assertEquals(sf.getBegin(), 2);
198 assertEquals(sf.getEnd(), 2);
199 assertEquals(sf.getType(), SEQUENCE_VARIANT);
200 assertEquals(sf.getScore(), 0f);
201 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
203 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
204 sf = transcriptFeatures.get(1);
205 assertEquals(sf.getFeatureGroup(), "VCF");
206 assertEquals(sf.getBegin(), 2);
207 assertEquals(sf.getEnd(), 2);
208 assertEquals(sf.getType(), SEQUENCE_VARIANT);
209 assertEquals(sf.getScore(), 0f);
210 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
212 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
215 * verify SNP variant feature(s) computed and added to protein
216 * first codon AGC varies to ACC giving S/T
218 DBRefEntry[] dbRefs = al.getSequenceAt(1).getDBRefs();
219 SequenceI peptide = null;
220 for (DBRefEntry dbref : dbRefs)
222 if (dbref.getMap().getMap().getFromRatio() == 3)
224 peptide = dbref.getMap().getTo();
227 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
230 * JAL-3187 don't precompute protein features, do dynamically instead
232 assertTrue(proteinFeatures.isEmpty());
235 private File makeVcfFile() throws IOException
237 File f = File.createTempFile("Test", ".vcf");
239 PrintWriter pw = new PrintWriter(f);
240 for (String vcfLine : VCF)
249 * Make a simple alignment with one 'gene' and one 'transcript'
253 private AlignmentI buildAlignment()
255 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
256 DataSourceType.PASTE);
259 * map gene1 sequence to chromosome (normally done when the sequence is fetched
260 * from Ensembl and transcripts computed)
262 AlignmentI alignment = af.getViewport().getAlignment();
263 SequenceI gene1 = alignment.findName("gene1");
264 int[] to = new int[] { 45051610, 45051634 };
265 int[] from = new int[] { gene1.getStart(), gene1.getEnd() };
266 gene1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
270 * map 'transcript1' to chromosome via 'gene1'
271 * transcript1/1-18 is gene1/3-10,15-24
272 * which is chromosome 45051612-45051619,45051624-45051633
274 to = new int[] { 45051612, 45051619, 45051624, 45051633 };
275 SequenceI transcript1 = alignment.findName("transcript1");
276 from = new int[] { transcript1.getStart(), transcript1.getEnd() };
277 transcript1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
282 * map gene2 to chromosome reverse strand
284 SequenceI gene2 = alignment.findName("gene2");
285 to = new int[] { 45051634, 45051610 };
286 from = new int[] { gene2.getStart(), gene2.getEnd() };
287 gene2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
291 * map 'transcript2' to chromosome via 'gene2'
292 * transcript2/1-18 is gene2/2-11,16-23
293 * which is chromosome 45051633-45051624,45051619-45051612
295 to = new int[] { 45051633, 45051624, 45051619, 45051612 };
296 SequenceI transcript2 = alignment.findName("transcript2");
297 from = new int[] { transcript2.getStart(), transcript2.getEnd() };
298 transcript2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
303 * add a protein product as a DBRef on transcript1
305 SequenceI peptide1 = new Sequence("ENSP001", "SWRECD");
306 MapList mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 },
308 Mapping map = new Mapping(peptide1, mapList);
309 DBRefEntry product = new DBRefEntry("", "", "ENSP001", map);
310 transcript1.addDBRef(product);
313 * add a protein product as a DBRef on transcript2
315 SequenceI peptide2 = new Sequence("ENSP002", "VTLSPA");
316 mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 }, 3, 1);
317 map = new Mapping(peptide2, mapList);
318 product = new DBRefEntry("", "", "ENSP002", map);
319 transcript2.addDBRef(product);
322 * map gene3 to chromosome
324 SequenceI gene3 = alignment.findName("gene3");
325 to = new int[] { 45051610, 45051634 };
326 from = new int[] { gene3.getStart(), gene3.getEnd() };
327 gene3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(from, to,
331 * map 'transcript3' to chromosome
333 SequenceI transcript3 = alignment.findName("transcript3");
334 to = new int[] { 45051612, 45051619, 45051624, 45051633 };
335 from = new int[] { transcript3.getStart(), transcript3.getEnd() };
336 transcript3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
341 * map 'transcript4' to chromosome
343 SequenceI transcript4 = alignment.findName("transcript4");
344 to = new int[] { 45051615, 45051617, 45051619, 45051632, 45051634,
346 from = new int[] { transcript4.getStart(), transcript4.getEnd() };
347 transcript4.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
352 * add a protein product as a DBRef on transcript3
354 SequenceI peptide3 = new Sequence("ENSP003", "SWRECD");
355 mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 }, 3, 1);
356 map = new Mapping(peptide3, mapList);
357 product = new DBRefEntry("", "", "ENSP003", map);
358 transcript3.addDBRef(product);
364 * Test with 'gene' and 'transcript' mapped to the reverse strand of the
365 * chromosome. The VCF variant positions (in forward coordinates) should get
366 * correctly located on sequence positions.
368 * @throws IOException
370 @Test(groups = "Functional")
371 public void testDoLoad_reverseStrand() throws IOException
373 AlignmentI al = buildAlignment();
375 File f = makeVcfFile();
377 VCFLoader loader = new VCFLoader(f.getPath());
379 loader.doLoad(al.getSequencesArray(), null);
382 * verify variant feature(s) added to gene2
383 * gene2/1-25 maps to chromosome 45051634- reverse strand
385 List<SequenceFeature> geneFeatures = al.getSequenceAt(2)
386 .getSequenceFeatures();
387 SequenceFeatures.sortFeatures(geneFeatures, true);
388 assertEquals(geneFeatures.size(), 5);
392 * insertion G/GA at 45051613 maps to an insertion at
393 * the preceding position (21) on reverse strand gene
394 * reference: CAAGC -> GCTTG/21-25
395 * genomic variant: CAAGAC (G/GA)
396 * gene variant: GTCTTG (G/GT at 21)
398 sf = geneFeatures.get(1);
399 assertEquals(sf.getFeatureGroup(), "VCF");
400 assertEquals(sf.getBegin(), 21);
401 assertEquals(sf.getEnd(), 21);
402 assertEquals(sf.getType(), SEQUENCE_VARIANT);
403 assertEquals(sf.getScore(), 0f);
404 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
405 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
409 * variant G/C at 45051613 maps to C/G at gene position 22
411 sf = geneFeatures.get(2);
412 assertEquals(sf.getFeatureGroup(), "VCF");
413 assertEquals(sf.getBegin(), 22);
414 assertEquals(sf.getEnd(), 22);
415 assertEquals(sf.getType(), SEQUENCE_VARIANT);
416 assertEquals(sf.getScore(), 0f);
417 assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
418 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
422 * variant A/C at 45051611 maps to T/G at gene position 24
424 sf = geneFeatures.get(3);
425 assertEquals(sf.getFeatureGroup(), "VCF");
426 assertEquals(sf.getBegin(), 24);
427 assertEquals(sf.getEnd(), 24);
428 assertEquals(sf.getType(), SEQUENCE_VARIANT);
429 assertEquals(sf.getScore(), 0f);
430 assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,G");
431 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
435 * variant A/T at 45051611 maps to T/A at gene position 24
437 sf = geneFeatures.get(4);
438 assertEquals(sf.getFeatureGroup(), "VCF");
439 assertEquals(sf.getBegin(), 24);
440 assertEquals(sf.getEnd(), 24);
441 assertEquals(sf.getType(), SEQUENCE_VARIANT);
442 assertEquals(sf.getScore(), 0f);
443 assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,A");
444 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
448 * verify 3 variant features added to transcript2
450 List<SequenceFeature> transcriptFeatures = al.getSequenceAt(3)
451 .getSequenceFeatures();
452 assertEquals(transcriptFeatures.size(), 3);
455 * insertion G/GT at position 21 of gene maps to position 16 of transcript
457 sf = transcriptFeatures.get(1);
458 assertEquals(sf.getFeatureGroup(), "VCF");
459 assertEquals(sf.getBegin(), 16);
460 assertEquals(sf.getEnd(), 16);
461 assertEquals(sf.getType(), SEQUENCE_VARIANT);
462 assertEquals(sf.getScore(), 0f);
463 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
464 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
468 * SNP C/G at position 22 of gene maps to position 17 of transcript
470 sf = transcriptFeatures.get(2);
471 assertEquals(sf.getFeatureGroup(), "VCF");
472 assertEquals(sf.getBegin(), 17);
473 assertEquals(sf.getEnd(), 17);
474 assertEquals(sf.getType(), SEQUENCE_VARIANT);
475 assertEquals(sf.getScore(), 0f);
476 assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
477 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
481 * verify variant feature(s) computed and added to protein
482 * last codon GCT varies to GGT giving A/G in the last peptide position
484 DBRefEntry[] dbRefs = al.getSequenceAt(3).getDBRefs();
485 SequenceI peptide = null;
486 for (DBRefEntry dbref : dbRefs)
488 if (dbref.getMap().getMap().getFromRatio() == 3)
490 peptide = dbref.getMap().getTo();
493 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
496 * JAL-3187 don't precompute protein features, do dynamically instead
498 assertTrue(proteinFeatures.isEmpty());
502 * Tests that if VEP consequence (CSQ) data is present in the VCF data, then
503 * it is added to the variant feature, but restricted where possible to the
504 * consequences for a specific transcript
506 * @throws IOException
508 @Test(groups = "Functional")
509 public void testDoLoad_vepCsq() throws IOException
511 AlignmentI al = buildAlignment();
513 VCFLoader loader = new VCFLoader("test/jalview/io/vcf/testVcf.vcf");
516 * VCF data file with variants at gene3 positions
521 * 17 A/AC (insertion), A/G
523 loader.doLoad(al.getSequencesArray(), null);
526 * verify variant feature(s) added to gene3
528 List<SequenceFeature> geneFeatures = al.findName("gene3")
529 .getSequenceFeatures();
530 SequenceFeatures.sortFeatures(geneFeatures, true);
531 assertEquals(geneFeatures.size(), 7);
532 SequenceFeature sf = geneFeatures.get(0);
533 assertEquals(sf.getBegin(), 1);
534 assertEquals(sf.getEnd(), 1);
535 assertEquals(sf.getScore(), 0f);
536 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.1f, DELTA);
537 assertEquals(sf.getValue("alleles"), "C,A");
538 // gene features include Consequence for all transcripts
539 Map map = (Map) sf.getValue("CSQ");
540 assertEquals(map.size(), 9);
541 assertEquals(map.get("PolyPhen"), "Bad");
543 sf = geneFeatures.get(1);
544 assertEquals(sf.getBegin(), 5);
545 assertEquals(sf.getEnd(), 5);
546 assertEquals(sf.getScore(), 0f);
547 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
548 assertEquals(sf.getValue("alleles"), "C,T");
549 map = (Map) sf.getValue("CSQ");
550 assertEquals(map.size(), 9);
551 assertEquals(map.get("PolyPhen"), "Bad;;"); // %3B%3B decoded
553 sf = geneFeatures.get(2);
554 assertEquals(sf.getBegin(), 9);
555 assertEquals(sf.getEnd(), 11); // deletion over 3 positions
556 assertEquals(sf.getScore(), 0f);
557 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.3f, DELTA);
558 assertEquals(sf.getValue("alleles"), "CGG,C");
559 map = (Map) sf.getValue("CSQ");
560 assertEquals(map.size(), 9);
562 sf = geneFeatures.get(3);
563 assertEquals(sf.getBegin(), 13);
564 assertEquals(sf.getEnd(), 13);
565 assertEquals(sf.getScore(), 0f);
566 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
567 assertEquals(sf.getValue("alleles"), "C,T");
568 map = (Map) sf.getValue("CSQ");
569 assertEquals(map.size(), 9);
571 sf = geneFeatures.get(4);
572 assertEquals(sf.getBegin(), 13);
573 assertEquals(sf.getEnd(), 13);
574 assertEquals(sf.getScore(), 0f);
575 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
576 assertEquals(sf.getValue("alleles"), "C,G");
577 map = (Map) sf.getValue("CSQ");
578 assertEquals(map.size(), 9);
580 sf = geneFeatures.get(5);
581 assertEquals(sf.getBegin(), 17);
582 assertEquals(sf.getEnd(), 17);
583 assertEquals(sf.getScore(), 0f);
584 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
585 assertEquals(sf.getValue("alleles"), "A,G");
586 map = (Map) sf.getValue("CSQ");
587 assertEquals(map.size(), 9);
589 sf = geneFeatures.get(6);
590 assertEquals(sf.getBegin(), 17);
591 assertEquals(sf.getEnd(), 17); // insertion
592 assertEquals(sf.getScore(), 0f);
593 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
594 assertEquals(sf.getValue("alleles"), "A,AC");
595 map = (Map) sf.getValue("CSQ");
596 assertEquals(map.size(), 9);
599 * verify variant feature(s) added to transcript3
600 * at columns 5 (1), 17 (2), positions 3, 11
601 * note the deletion at columns 9-11 is not transferred since col 11
602 * has no mapping to transcript 3
604 List<SequenceFeature> transcriptFeatures = al.findName("transcript3")
605 .getSequenceFeatures();
606 SequenceFeatures.sortFeatures(transcriptFeatures, true);
607 assertEquals(transcriptFeatures.size(), 3);
608 sf = transcriptFeatures.get(0);
609 assertEquals(sf.getBegin(), 3);
610 assertEquals(sf.getEnd(), 3);
611 assertEquals(sf.getScore(), 0f);
612 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
613 assertEquals(sf.getValue("alleles"), "C,T");
614 // transcript features only have Consequence for that transcripts
615 map = (Map) sf.getValue("CSQ");
616 assertEquals(map.size(), 9);
617 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
619 sf = transcriptFeatures.get(1);
620 assertEquals(sf.getBegin(), 11);
621 assertEquals(sf.getEnd(), 11);
622 assertEquals(sf.getScore(), 0f);
623 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
624 assertEquals(sf.getValue("alleles"), "A,G");
625 assertEquals(map.size(), 9);
626 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
628 sf = transcriptFeatures.get(2);
629 assertEquals(sf.getBegin(), 11);
630 assertEquals(sf.getEnd(), 11);
631 assertEquals(sf.getScore(), 0f);
632 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
633 assertEquals(sf.getValue("alleles"), "A,AC");
634 assertEquals(map.size(), 9);
635 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
638 * verify variants computed on protein product for transcript3
640 * codon variants are AGC/AGT position 1 which is synonymous
641 * and GAG/GGG which is E/G in position 4
642 * the insertion variant is not transferred to the peptide
644 DBRefEntry[] dbRefs = al.findName("transcript3").getDBRefs();
645 SequenceI peptide = null;
646 for (DBRefEntry dbref : dbRefs)
648 if (dbref.getMap().getMap().getFromRatio() == 3)
650 peptide = dbref.getMap().getTo();
653 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
655 * JAL-3187 don't precompute protein features, do dynamically instead
657 assertTrue(proteinFeatures.isEmpty());
658 // SequenceFeatures.sortFeatures(proteinFeatures, true);
659 // assertEquals(proteinFeatures.size(), 2);
660 // sf = proteinFeatures.get(0);
661 // assertEquals(sf.getFeatureGroup(), "VCF");
662 // assertEquals(sf.getBegin(), 1);
663 // assertEquals(sf.getEnd(), 1);
664 // assertEquals(sf.getType(), SequenceOntologyI.SYNONYMOUS_VARIANT);
665 // assertEquals(sf.getDescription(), "agC/agT");
666 // sf = proteinFeatures.get(1);
667 // assertEquals(sf.getFeatureGroup(), "VCF");
668 // assertEquals(sf.getBegin(), 4);
669 // assertEquals(sf.getEnd(), 4);
670 // assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
671 // assertEquals(sf.getDescription(), "p.Glu4Gly");
674 * verify variant feature(s) added to transcript4
675 * at columns 13 (2) and 17 (2), positions 7 and 11
677 transcriptFeatures = al.findName("transcript4").getSequenceFeatures();
678 SequenceFeatures.sortFeatures(transcriptFeatures, true);
679 assertEquals(transcriptFeatures.size(), 4);
680 sf = transcriptFeatures.get(0);
681 assertEquals(sf.getBegin(), 7);
682 assertEquals(sf.getEnd(), 7);
683 assertEquals(sf.getScore(), 0f);
684 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
685 assertEquals(sf.getValue("alleles"), "C,T");
686 assertEquals(map.size(), 9);
687 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
689 sf = transcriptFeatures.get(1);
690 assertEquals(sf.getBegin(), 7);
691 assertEquals(sf.getEnd(), 7);
692 assertEquals(sf.getScore(), 0f);
693 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
694 assertEquals(sf.getValue("alleles"), "C,G");
695 assertEquals(map.size(), 9);
696 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
698 sf = transcriptFeatures.get(2);
699 assertEquals(sf.getBegin(), 11);
700 assertEquals(sf.getEnd(), 11);
701 assertEquals(sf.getScore(), 0f);
702 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
703 assertEquals(sf.getValue("alleles"), "A,G");
704 assertEquals(map.size(), 9);
705 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
707 sf = transcriptFeatures.get(3);
708 assertEquals(sf.getBegin(), 11);
709 assertEquals(sf.getEnd(), 11);
710 assertEquals(sf.getScore(), 0f);
711 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
712 assertEquals(sf.getValue("alleles"), "A,AC");
713 assertEquals(map.size(), 9);
714 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
718 * A test that demonstrates loading a contig sequence from an indexed sequence
719 * database which is the reference for a VCF file
721 * @throws IOException
723 @Test(groups = "Functional")
724 public void testLoadVCFContig() throws IOException
726 VCFLoader loader = new VCFLoader(
727 "test/jalview/io/vcf/testVcf2.vcf");
729 SequenceI seq = loader.loadVCFContig("contig123");
730 assertEquals(seq.getLength(), 15);
731 assertEquals(seq.getSequenceAsString(), "AAAAACCCCCGGGGG");
732 List<SequenceFeature> features = seq.getSequenceFeatures();
733 SequenceFeatures.sortFeatures(features, true);
734 assertEquals(features.size(), 2);
735 SequenceFeature sf = features.get(0);
736 assertEquals(sf.getBegin(), 8);
737 assertEquals(sf.getEnd(), 8);
738 assertEquals(sf.getDescription(), "C,A");
739 sf = features.get(1);
740 assertEquals(sf.getBegin(), 12);
741 assertEquals(sf.getEnd(), 12);
742 assertEquals(sf.getDescription(), "G,T");
744 seq = loader.loadVCFContig("contig789");
745 assertEquals(seq.getLength(), 25);
746 assertEquals(seq.getSequenceAsString(), "GGGGGTTTTTAAAAACCCCCGGGGG");
747 features = seq.getSequenceFeatures();
748 SequenceFeatures.sortFeatures(features, true);
749 assertEquals(features.size(), 2);
750 sf = features.get(0);
751 assertEquals(sf.getBegin(), 2);
752 assertEquals(sf.getEnd(), 2);
753 assertEquals(sf.getDescription(), "G,T");
754 sf = features.get(1);
755 assertEquals(sf.getBegin(), 21);
756 assertEquals(sf.getEnd(), 21);
757 assertEquals(sf.getDescription(), "G,A");
759 seq = loader.loadVCFContig("contig456");
760 assertEquals(seq.getLength(), 20);
761 assertEquals(seq.getSequenceAsString(), "CCCCCGGGGGTTTTTAAAAA");
762 features = seq.getSequenceFeatures();
763 SequenceFeatures.sortFeatures(features, true);
764 assertEquals(features.size(), 1);
765 sf = features.get(0);
766 assertEquals(sf.getBegin(), 15);
767 assertEquals(sf.getEnd(), 15);
768 assertEquals(sf.getDescription(), "T,C");