1 package jalview.io.vcf;
3 import static org.testng.Assert.assertEquals;
5 import jalview.bin.Cache;
6 import jalview.datamodel.AlignmentI;
7 import jalview.datamodel.DBRefEntry;
8 import jalview.datamodel.Mapping;
9 import jalview.datamodel.Sequence;
10 import jalview.datamodel.SequenceFeature;
11 import jalview.datamodel.SequenceI;
12 import jalview.datamodel.features.SequenceFeatures;
13 import jalview.gui.AlignFrame;
14 import jalview.io.DataSourceType;
15 import jalview.io.FileLoader;
16 import jalview.io.gff.Gff3Helper;
17 import jalview.io.gff.SequenceOntologyI;
18 import jalview.util.MapList;
21 import java.io.IOException;
22 import java.io.PrintWriter;
23 import java.util.List;
26 import org.testng.annotations.BeforeClass;
27 import org.testng.annotations.Test;
29 public class VCFLoaderTest
31 private static final float DELTA = 0.00001f;
33 // columns 9717- of gene P30419 from Ensembl (much modified)
34 private static final String FASTA = ""
37 * forward strand 'gene' and 'transcript' with two exons
39 ">gene1/1-25 chromosome:GRCh38:17:45051610:45051634:1\n"
40 + "CAAGCTGGCGGACGAGAGTGTGACA\n"
41 + ">transcript1/1-18\n--AGCTGGCG----AGAGTGTGAC-\n"
44 * reverse strand gene and transcript (reverse complement alleles!)
46 + ">gene2/1-25 chromosome:GRCh38:17:45051610:45051634:-1\n"
47 + "TGTCACACTCTCGTCCGCCAGCTTG\n"
48 + ">transcript2/1-18\n" + "-GTCACACTCT----CGCCAGCT--\n"
51 * 'gene' on chromosome 5 with two transcripts
53 + ">gene3/1-25 chromosome:GRCh38:5:45051610:45051634:1\n"
54 + "CAAGCTGGCGGACGAGAGTGTGACA\n"
55 + ">transcript3/1-18\n--AGCTGGCG----AGAGTGTGAC-\n"
56 + ">transcript4/1-18\n-----TGG-GGACGAGAGTGTGA-A\n";
58 private static final String[] VCF = { "##fileformat=VCFv4.2",
59 "##INFO=<ID=AF,Number=A,Type=Float,Description=\"Allele Frequency, for each ALT allele, in the same order as listed\">",
60 "##reference=Homo_sapiens/GRCh38",
61 "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO",
62 // A/T,C variants in position 2 of gene sequence (precedes transcript)
63 // should create 2 variant features with respective scores
64 "17\t45051611\t.\tA\tT,C\t1666.64\tRF\tAC=15;AF=5.0e-03,4.0e-03",
65 // SNP G/C in position 4 of gene sequence, position 2 of transcript
66 // insertion G/GA is transferred to nucleotide but not to peptide
67 "17\t45051613\t.\tG\tGA,C\t1666.64\tRF\tAC=15;AF=3.0e-03,2.0e-03" };
69 @BeforeClass(alwaysRun = true)
73 * configure to capture all available VCF and VEP (CSQ) fields
75 Cache.loadProperties("test/jalview/io/testProps.jvprops");
76 Cache.setProperty("VCF_FIELDS", ".*");
77 Cache.setProperty("VEP_FIELDS", ".*");
78 Cache.setProperty("VCF_ASSEMBLY", "GRCh38=GRCh38");
82 @Test(groups = "Functional")
83 public void testDoLoad() throws IOException
85 AlignmentI al = buildAlignment();
88 VCFLoader loader = new VCFLoader(f.getPath());
90 loader.doLoad(al.getSequencesArray(), null);
93 * verify variant feature(s) added to gene
94 * NB alleles at a locus may not be processed, and features added,
95 * in the order in which they appear in the VCF record as method
96 * VariantContext.getAlternateAlleles() does not guarantee order
97 * - order of assertions here matches what we find (is not important)
99 List<SequenceFeature> geneFeatures = al.getSequenceAt(0)
100 .getSequenceFeatures();
101 SequenceFeatures.sortFeatures(geneFeatures, true);
102 assertEquals(geneFeatures.size(), 4);
103 SequenceFeature sf = geneFeatures.get(0);
104 assertEquals(sf.getFeatureGroup(), "VCF");
105 assertEquals(sf.getBegin(), 2);
106 assertEquals(sf.getEnd(), 2);
107 assertEquals(sf.getScore(), 0f);
108 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
110 assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,C");
111 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
112 sf = geneFeatures.get(1);
113 assertEquals(sf.getFeatureGroup(), "VCF");
114 assertEquals(sf.getBegin(), 2);
115 assertEquals(sf.getEnd(), 2);
116 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
117 assertEquals(sf.getScore(), 0f);
118 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
120 assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,T");
122 sf = geneFeatures.get(2);
123 assertEquals(sf.getFeatureGroup(), "VCF");
124 assertEquals(sf.getBegin(), 4);
125 assertEquals(sf.getEnd(), 4);
126 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
127 assertEquals(sf.getScore(), 0f);
128 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
130 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
132 sf = geneFeatures.get(3);
133 assertEquals(sf.getFeatureGroup(), "VCF");
134 assertEquals(sf.getBegin(), 4);
135 assertEquals(sf.getEnd(), 4);
136 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
137 assertEquals(sf.getScore(), 0f);
138 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
140 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
143 * verify variant feature(s) added to transcript
145 List<SequenceFeature> transcriptFeatures = al.getSequenceAt(1)
146 .getSequenceFeatures();
147 assertEquals(transcriptFeatures.size(), 2);
148 sf = transcriptFeatures.get(0);
149 assertEquals(sf.getFeatureGroup(), "VCF");
150 assertEquals(sf.getBegin(), 2);
151 assertEquals(sf.getEnd(), 2);
152 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
153 assertEquals(sf.getScore(), 0f);
154 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
156 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
157 sf = transcriptFeatures.get(1);
158 assertEquals(sf.getFeatureGroup(), "VCF");
159 assertEquals(sf.getBegin(), 2);
160 assertEquals(sf.getEnd(), 2);
161 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
162 assertEquals(sf.getScore(), 0f);
163 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
165 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
168 * verify SNP variant feature(s) computed and added to protein
169 * first codon AGC varies to ACC giving S/T
171 DBRefEntry[] dbRefs = al.getSequenceAt(1).getDBRefs();
172 SequenceI peptide = null;
173 for (DBRefEntry dbref : dbRefs)
175 if (dbref.getMap().getMap().getFromRatio() == 3)
177 peptide = dbref.getMap().getTo();
180 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
181 assertEquals(proteinFeatures.size(), 1);
182 sf = proteinFeatures.get(0);
183 assertEquals(sf.getFeatureGroup(), "VCF");
184 assertEquals(sf.getBegin(), 1);
185 assertEquals(sf.getEnd(), 1);
186 assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
187 assertEquals(sf.getDescription(), "p.Ser1Thr");
190 private File makeVcf() throws IOException
192 File f = File.createTempFile("Test", ".vcf");
194 PrintWriter pw = new PrintWriter(f);
195 for (String vcfLine : VCF)
204 * Make a simple alignment with one 'gene' and one 'transcript'
208 private AlignmentI buildAlignment()
210 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
211 DataSourceType.PASTE);
214 * map gene1 sequence to chromosome (normally done when the sequence is fetched
215 * from Ensembl and transcripts computed)
217 AlignmentI alignment = af.getViewport().getAlignment();
218 SequenceI gene1 = alignment.findName("gene1");
219 int[] to = new int[] { 45051610, 45051634 };
220 int[] from = new int[] { gene1.getStart(), gene1.getEnd() };
221 gene1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
225 * map 'transcript1' to chromosome via 'gene1'
226 * transcript1/1-18 is gene1/3-10,15-24
227 * which is chromosome 45051612-45051619,45051624-45051633
229 to = new int[] { 45051612, 45051619, 45051624, 45051633 };
230 SequenceI transcript1 = alignment.findName("transcript1");
231 from = new int[] { transcript1.getStart(), transcript1.getEnd() };
232 transcript1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
237 * map gene2 to chromosome reverse strand
239 SequenceI gene2 = alignment.findName("gene2");
240 to = new int[] { 45051634, 45051610 };
241 from = new int[] { gene2.getStart(), gene2.getEnd() };
242 gene2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
246 * map 'transcript2' to chromosome via 'gene2'
247 * transcript2/1-18 is gene2/2-11,16-23
248 * which is chromosome 45051633-45051624,45051619-45051612
250 to = new int[] { 45051633, 45051624, 45051619, 45051612 };
251 SequenceI transcript2 = alignment.findName("transcript2");
252 from = new int[] { transcript2.getStart(), transcript2.getEnd() };
253 transcript2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
258 * add a protein product as a DBRef on transcript1
260 SequenceI peptide1 = new Sequence("ENSP001", "SWRECD");
261 MapList mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 },
263 Mapping map = new Mapping(peptide1, mapList);
264 DBRefEntry product = new DBRefEntry("", "", "ENSP001", map);
265 transcript1.addDBRef(product);
268 * add a protein product as a DBRef on transcript2
270 SequenceI peptide2 = new Sequence("ENSP002", "VTLSPA");
271 mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 }, 3, 1);
272 map = new Mapping(peptide2, mapList);
273 product = new DBRefEntry("", "", "ENSP002", map);
274 transcript2.addDBRef(product);
277 * map gene3 to chromosome
279 SequenceI gene3 = alignment.findName("gene3");
280 to = new int[] { 45051610, 45051634 };
281 from = new int[] { gene3.getStart(), gene3.getEnd() };
282 gene3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(from, to,
286 * map 'transcript3' to chromosome
288 SequenceI transcript3 = alignment.findName("transcript3");
289 to = new int[] { 45051612, 45051619, 45051624, 45051633 };
290 from = new int[] { transcript3.getStart(), transcript3.getEnd() };
291 transcript3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
296 * map 'transcript4' to chromosome
298 SequenceI transcript4 = alignment.findName("transcript4");
299 to = new int[] { 45051615, 45051617, 45051619, 45051632, 45051634,
301 from = new int[] { transcript4.getStart(), transcript4.getEnd() };
302 transcript4.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
307 * add a protein product as a DBRef on transcript3
309 SequenceI peptide3 = new Sequence("ENSP003", "SWRECD");
310 mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 }, 3, 1);
311 map = new Mapping(peptide3, mapList);
312 product = new DBRefEntry("", "", "ENSP003", map);
313 transcript3.addDBRef(product);
319 * Test with 'gene' and 'transcript' mapped to the reverse strand of the
320 * chromosome. The VCF variant positions (in forward coordinates) should get
321 * correctly located on sequence positions.
323 * @throws IOException
325 @Test(groups = "Functional")
326 public void testDoLoad_reverseStrand() throws IOException
328 AlignmentI al = buildAlignment();
332 VCFLoader loader = new VCFLoader(f.getPath());
334 loader.doLoad(al.getSequencesArray(), null);
337 * verify variant feature(s) added to gene2
338 * gene2/1-25 maps to chromosome 45051634- reverse strand
340 List<SequenceFeature> geneFeatures = al.getSequenceAt(2)
341 .getSequenceFeatures();
342 SequenceFeatures.sortFeatures(geneFeatures, true);
343 assertEquals(geneFeatures.size(), 4);
346 * variant A/T at 45051611 maps to T/A at gene position 24
348 SequenceFeature sf = geneFeatures.get(3);
349 assertEquals(sf.getFeatureGroup(), "VCF");
350 assertEquals(sf.getBegin(), 24);
351 assertEquals(sf.getEnd(), 24);
352 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
353 assertEquals(sf.getScore(), 0f);
354 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
356 assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,A");
359 * variant A/C at 45051611 maps to T/G at gene position 24
361 sf = geneFeatures.get(2);
362 assertEquals(sf.getFeatureGroup(), "VCF");
363 assertEquals(sf.getBegin(), 24);
364 assertEquals(sf.getEnd(), 24);
365 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
366 assertEquals(sf.getScore(), 0f);
367 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
369 assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,G");
372 * variant G/C at 45051613 maps to C/G at gene position 22
374 sf = geneFeatures.get(1);
375 assertEquals(sf.getFeatureGroup(), "VCF");
376 assertEquals(sf.getBegin(), 22);
377 assertEquals(sf.getEnd(), 22);
378 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
379 assertEquals(sf.getScore(), 0f);
380 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
382 assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
385 * insertion G/GA at 45051613 maps to an insertion at
386 * the preceding position (21) on reverse strand gene
387 * reference: CAAGC -> GCTTG/21-25
388 * genomic variant: CAAGAC (G/GA)
389 * gene variant: GTCTTG (G/GT at 21)
391 sf = geneFeatures.get(0);
392 assertEquals(sf.getFeatureGroup(), "VCF");
393 assertEquals(sf.getBegin(), 21);
394 assertEquals(sf.getEnd(), 21);
395 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
396 assertEquals(sf.getScore(), 0f);
397 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
399 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
402 * verify 2 variant features added to transcript2
404 List<SequenceFeature> transcriptFeatures = al.getSequenceAt(3)
405 .getSequenceFeatures();
406 assertEquals(transcriptFeatures.size(), 2);
409 * insertion G/GT at position 21 of gene maps to position 16 of transcript
411 sf = transcriptFeatures.get(0);
412 assertEquals(sf.getFeatureGroup(), "VCF");
413 assertEquals(sf.getBegin(), 16);
414 assertEquals(sf.getEnd(), 16);
415 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
416 assertEquals(sf.getScore(), 0f);
417 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
419 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
422 * SNP C/G at position 22 of gene maps to position 17 of transcript
424 sf = transcriptFeatures.get(1);
425 assertEquals(sf.getFeatureGroup(), "VCF");
426 assertEquals(sf.getBegin(), 17);
427 assertEquals(sf.getEnd(), 17);
428 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
429 assertEquals(sf.getScore(), 0f);
430 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
432 assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
435 * verify variant feature(s) computed and added to protein
436 * last codon GCT varies to GGT giving A/G in the last peptide position
438 DBRefEntry[] dbRefs = al.getSequenceAt(3).getDBRefs();
439 SequenceI peptide = null;
440 for (DBRefEntry dbref : dbRefs)
442 if (dbref.getMap().getMap().getFromRatio() == 3)
444 peptide = dbref.getMap().getTo();
447 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
448 assertEquals(proteinFeatures.size(), 1);
449 sf = proteinFeatures.get(0);
450 assertEquals(sf.getFeatureGroup(), "VCF");
451 assertEquals(sf.getBegin(), 6);
452 assertEquals(sf.getEnd(), 6);
453 assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
454 assertEquals(sf.getDescription(), "p.Ala6Gly");
458 * Tests that if VEP consequence (CSQ) data is present in the VCF data, then
459 * it is added to the variant feature, but restricted where possible to the
460 * consequences for a specific transcript
462 * @throws IOException
464 @Test(groups = "Functional")
465 public void testDoLoad_vepCsq() throws IOException
467 AlignmentI al = buildAlignment();
469 VCFLoader loader = new VCFLoader("test/jalview/io/vcf/testVcf.vcf");
472 * VCF data file with variants at gene3 positions
477 * 17 A/AC (insertion), A/G
479 loader.doLoad(al.getSequencesArray(), null);
482 * verify variant feature(s) added to gene3
484 List<SequenceFeature> geneFeatures = al.findName("gene3")
485 .getSequenceFeatures();
486 SequenceFeatures.sortFeatures(geneFeatures, true);
487 assertEquals(geneFeatures.size(), 7);
488 SequenceFeature sf = geneFeatures.get(0);
489 assertEquals(sf.getBegin(), 1);
490 assertEquals(sf.getEnd(), 1);
491 assertEquals(sf.getScore(), 0f);
492 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.1f, DELTA);
493 assertEquals(sf.getValue("alleles"), "C,A");
494 // gene features include Consequence for all transcripts
495 Map map = (Map) sf.getValue("CSQ");
496 assertEquals(map.size(), 9);
498 sf = geneFeatures.get(1);
499 assertEquals(sf.getBegin(), 5);
500 assertEquals(sf.getEnd(), 5);
501 assertEquals(sf.getScore(), 0f);
502 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
503 assertEquals(sf.getValue("alleles"), "C,T");
504 map = (Map) sf.getValue("CSQ");
505 assertEquals(map.size(), 9);
507 sf = geneFeatures.get(2);
508 assertEquals(sf.getBegin(), 9);
509 assertEquals(sf.getEnd(), 11); // deletion over 3 positions
510 assertEquals(sf.getScore(), 0f);
511 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.3f, DELTA);
512 assertEquals(sf.getValue("alleles"), "CGG,C");
513 map = (Map) sf.getValue("CSQ");
514 assertEquals(map.size(), 9);
516 sf = geneFeatures.get(3);
517 assertEquals(sf.getBegin(), 13);
518 assertEquals(sf.getEnd(), 13);
519 assertEquals(sf.getScore(), 0f);
520 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
521 assertEquals(sf.getValue("alleles"), "C,T");
522 map = (Map) sf.getValue("CSQ");
523 assertEquals(map.size(), 9);
525 sf = geneFeatures.get(4);
526 assertEquals(sf.getBegin(), 13);
527 assertEquals(sf.getEnd(), 13);
528 assertEquals(sf.getScore(), 0f);
529 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
530 assertEquals(sf.getValue("alleles"), "C,G");
531 map = (Map) sf.getValue("CSQ");
532 assertEquals(map.size(), 9);
534 sf = geneFeatures.get(5);
535 assertEquals(sf.getBegin(), 17);
536 assertEquals(sf.getEnd(), 17);
537 assertEquals(sf.getScore(), 0f);
538 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
539 assertEquals(sf.getValue("alleles"), "A,G");
540 map = (Map) sf.getValue("CSQ");
541 assertEquals(map.size(), 9);
543 sf = geneFeatures.get(6);
544 assertEquals(sf.getBegin(), 17);
545 assertEquals(sf.getEnd(), 17); // insertion
546 assertEquals(sf.getScore(), 0f);
547 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
548 assertEquals(sf.getValue("alleles"), "A,AC");
549 map = (Map) sf.getValue("CSQ");
550 assertEquals(map.size(), 9);
553 * verify variant feature(s) added to transcript3
554 * at columns 5 (1), 17 (2), positions 3, 11
555 * note the deletion at columns 9-11 is not transferred since col 11
556 * has no mapping to transcript 3
558 List<SequenceFeature> transcriptFeatures = al.findName("transcript3")
559 .getSequenceFeatures();
560 SequenceFeatures.sortFeatures(transcriptFeatures, true);
561 assertEquals(transcriptFeatures.size(), 3);
562 sf = transcriptFeatures.get(0);
563 assertEquals(sf.getBegin(), 3);
564 assertEquals(sf.getEnd(), 3);
565 assertEquals(sf.getScore(), 0f);
566 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
567 assertEquals(sf.getValue("alleles"), "C,T");
568 // transcript features only have Consequence for that transcripts
569 map = (Map) sf.getValue("CSQ");
570 assertEquals(map.size(), 9);
571 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
573 sf = transcriptFeatures.get(1);
574 assertEquals(sf.getBegin(), 11);
575 assertEquals(sf.getEnd(), 11);
576 assertEquals(sf.getScore(), 0f);
577 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
578 assertEquals(sf.getValue("alleles"), "A,G");
579 assertEquals(map.size(), 9);
580 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
582 sf = transcriptFeatures.get(2);
583 assertEquals(sf.getBegin(), 11);
584 assertEquals(sf.getEnd(), 11);
585 assertEquals(sf.getScore(), 0f);
586 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
587 assertEquals(sf.getValue("alleles"), "A,AC");
588 assertEquals(map.size(), 9);
589 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
592 * verify variants computed on protein product for transcript3
594 * codon variants are AGC/AGT position 1 which is synonymous
595 * and GAG/GGG which is E/G in position 4
596 * the insertion variant is not transferred to the peptide
598 DBRefEntry[] dbRefs = al.findName("transcript3").getDBRefs();
599 SequenceI peptide = null;
600 for (DBRefEntry dbref : dbRefs)
602 if (dbref.getMap().getMap().getFromRatio() == 3)
604 peptide = dbref.getMap().getTo();
607 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
608 SequenceFeatures.sortFeatures(proteinFeatures, true);
609 assertEquals(proteinFeatures.size(), 2);
610 sf = proteinFeatures.get(0);
611 assertEquals(sf.getFeatureGroup(), "VCF");
612 assertEquals(sf.getBegin(), 1);
613 assertEquals(sf.getEnd(), 1);
614 assertEquals(sf.getType(), SequenceOntologyI.SYNONYMOUS_VARIANT);
615 assertEquals(sf.getDescription(), "agC/agT");
616 sf = proteinFeatures.get(1);
617 assertEquals(sf.getFeatureGroup(), "VCF");
618 assertEquals(sf.getBegin(), 4);
619 assertEquals(sf.getEnd(), 4);
620 assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
621 assertEquals(sf.getDescription(), "p.Glu4Gly");
624 * verify variant feature(s) added to transcript4
625 * at columns 13 (2) and 17 (2), positions 7 and 11
627 transcriptFeatures = al.findName("transcript4").getSequenceFeatures();
628 SequenceFeatures.sortFeatures(transcriptFeatures, true);
629 assertEquals(transcriptFeatures.size(), 4);
630 sf = transcriptFeatures.get(0);
631 assertEquals(sf.getBegin(), 7);
632 assertEquals(sf.getEnd(), 7);
633 assertEquals(sf.getScore(), 0f);
634 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
635 assertEquals(sf.getValue("alleles"), "C,T");
636 assertEquals(map.size(), 9);
637 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
639 sf = transcriptFeatures.get(1);
640 assertEquals(sf.getBegin(), 7);
641 assertEquals(sf.getEnd(), 7);
642 assertEquals(sf.getScore(), 0f);
643 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
644 assertEquals(sf.getValue("alleles"), "C,G");
645 assertEquals(map.size(), 9);
646 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
648 sf = transcriptFeatures.get(2);
649 assertEquals(sf.getBegin(), 11);
650 assertEquals(sf.getEnd(), 11);
651 assertEquals(sf.getScore(), 0f);
652 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
653 assertEquals(sf.getValue("alleles"), "A,G");
654 assertEquals(map.size(), 9);
655 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
657 sf = transcriptFeatures.get(3);
658 assertEquals(sf.getBegin(), 11);
659 assertEquals(sf.getEnd(), 11);
660 assertEquals(sf.getScore(), 0f);
661 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
662 assertEquals(sf.getValue("alleles"), "A,AC");
663 assertEquals(map.size(), 9);
664 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
668 * A test that demonstrates loading a contig sequence from an indexed sequence
669 * database which is the reference for a VCF file
671 * @throws IOException
673 @Test(groups = "Functional")
674 public void testLoadVCFContig() throws IOException
676 VCFLoader loader = new VCFLoader(
677 "test/jalview/io/vcf/testVcf2.vcf");
679 SequenceI seq = loader.loadVCFContig("contig123");
680 assertEquals(seq.getLength(), 15);
681 assertEquals(seq.getSequenceAsString(), "AAAAACCCCCGGGGG");
682 List<SequenceFeature> features = seq.getSequenceFeatures();
683 SequenceFeatures.sortFeatures(features, true);
684 assertEquals(features.size(), 2);
685 SequenceFeature sf = features.get(0);
686 assertEquals(sf.getBegin(), 8);
687 assertEquals(sf.getEnd(), 8);
688 assertEquals(sf.getDescription(), "C,A");
689 sf = features.get(1);
690 assertEquals(sf.getBegin(), 12);
691 assertEquals(sf.getEnd(), 12);
692 assertEquals(sf.getDescription(), "G,T");
694 seq = loader.loadVCFContig("contig789");
695 assertEquals(seq.getLength(), 25);
696 assertEquals(seq.getSequenceAsString(), "GGGGGTTTTTAAAAACCCCCGGGGG");
697 features = seq.getSequenceFeatures();
698 SequenceFeatures.sortFeatures(features, true);
699 assertEquals(features.size(), 2);
700 sf = features.get(0);
701 assertEquals(sf.getBegin(), 2);
702 assertEquals(sf.getEnd(), 2);
703 assertEquals(sf.getDescription(), "G,T");
704 sf = features.get(1);
705 assertEquals(sf.getBegin(), 21);
706 assertEquals(sf.getEnd(), 21);
707 assertEquals(sf.getDescription(), "G,A");
709 seq = loader.loadVCFContig("contig456");
710 assertEquals(seq.getLength(), 20);
711 assertEquals(seq.getSequenceAsString(), "CCCCCGGGGGTTTTTAAAAA");
712 features = seq.getSequenceFeatures();
713 SequenceFeatures.sortFeatures(features, true);
714 assertEquals(features.size(), 1);
715 sf = features.get(0);
716 assertEquals(sf.getBegin(), 15);
717 assertEquals(sf.getEnd(), 15);
718 assertEquals(sf.getDescription(), "T,C");