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", ".*");
81 @Test(groups = "Functional")
82 public void testDoLoad() throws IOException
84 AlignmentI al = buildAlignment();
87 VCFLoader loader = new VCFLoader(f.getPath());
89 loader.doLoad(al.getSequencesArray(), null);
92 * verify variant feature(s) added to gene
93 * NB alleles at a locus may not be processed, and features added,
94 * in the order in which they appear in the VCF record as method
95 * VariantContext.getAlternateAlleles() does not guarantee order
96 * - order of assertions here matches what we find (is not important)
98 List<SequenceFeature> geneFeatures = al.getSequenceAt(0)
99 .getSequenceFeatures();
100 SequenceFeatures.sortFeatures(geneFeatures, true);
101 assertEquals(geneFeatures.size(), 4);
102 SequenceFeature sf = geneFeatures.get(0);
103 assertEquals(sf.getFeatureGroup(), "VCF");
104 assertEquals(sf.getBegin(), 2);
105 assertEquals(sf.getEnd(), 2);
106 assertEquals(sf.getScore(), 0f);
107 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
109 assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,C");
110 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
111 sf = geneFeatures.get(1);
112 assertEquals(sf.getFeatureGroup(), "VCF");
113 assertEquals(sf.getBegin(), 2);
114 assertEquals(sf.getEnd(), 2);
115 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
116 assertEquals(sf.getScore(), 0f);
117 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
119 assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,T");
121 sf = geneFeatures.get(2);
122 assertEquals(sf.getFeatureGroup(), "VCF");
123 assertEquals(sf.getBegin(), 4);
124 assertEquals(sf.getEnd(), 4);
125 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
126 assertEquals(sf.getScore(), 0f);
127 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
129 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
131 sf = geneFeatures.get(3);
132 assertEquals(sf.getFeatureGroup(), "VCF");
133 assertEquals(sf.getBegin(), 4);
134 assertEquals(sf.getEnd(), 4);
135 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
136 assertEquals(sf.getScore(), 0f);
137 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
139 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
142 * verify variant feature(s) added to transcript
144 List<SequenceFeature> transcriptFeatures = al.getSequenceAt(1)
145 .getSequenceFeatures();
146 assertEquals(transcriptFeatures.size(), 2);
147 sf = transcriptFeatures.get(0);
148 assertEquals(sf.getFeatureGroup(), "VCF");
149 assertEquals(sf.getBegin(), 2);
150 assertEquals(sf.getEnd(), 2);
151 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
152 assertEquals(sf.getScore(), 0f);
153 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
155 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
156 sf = transcriptFeatures.get(1);
157 assertEquals(sf.getFeatureGroup(), "VCF");
158 assertEquals(sf.getBegin(), 2);
159 assertEquals(sf.getEnd(), 2);
160 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
161 assertEquals(sf.getScore(), 0f);
162 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
164 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
167 * verify SNP variant feature(s) computed and added to protein
168 * first codon AGC varies to ACC giving S/T
170 DBRefEntry[] dbRefs = al.getSequenceAt(1).getDBRefs();
171 SequenceI peptide = null;
172 for (DBRefEntry dbref : dbRefs)
174 if (dbref.getMap().getMap().getFromRatio() == 3)
176 peptide = dbref.getMap().getTo();
179 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
180 assertEquals(proteinFeatures.size(), 1);
181 sf = proteinFeatures.get(0);
182 assertEquals(sf.getFeatureGroup(), "VCF");
183 assertEquals(sf.getBegin(), 1);
184 assertEquals(sf.getEnd(), 1);
185 assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
186 assertEquals(sf.getDescription(), "p.Ser1Thr");
189 private File makeVcf() throws IOException
191 File f = File.createTempFile("Test", ".vcf");
193 PrintWriter pw = new PrintWriter(f);
194 for (String vcfLine : VCF)
203 * Make a simple alignment with one 'gene' and one 'transcript'
207 private AlignmentI buildAlignment()
209 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
210 DataSourceType.PASTE);
213 * map gene1 sequence to chromosome (normally done when the sequence is fetched
214 * from Ensembl and transcripts computed)
216 AlignmentI alignment = af.getViewport().getAlignment();
217 SequenceI gene1 = alignment.findName("gene1");
218 int[] to = new int[] { 45051610, 45051634 };
219 int[] from = new int[] { gene1.getStart(), gene1.getEnd() };
220 gene1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
224 * map 'transcript1' to chromosome via 'gene1'
225 * transcript1/1-18 is gene1/3-10,15-24
226 * which is chromosome 45051612-45051619,45051624-45051633
228 to = new int[] { 45051612, 45051619, 45051624, 45051633 };
229 SequenceI transcript1 = alignment.findName("transcript1");
230 from = new int[] { transcript1.getStart(), transcript1.getEnd() };
231 transcript1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
236 * map gene2 to chromosome reverse strand
238 SequenceI gene2 = alignment.findName("gene2");
239 to = new int[] { 45051634, 45051610 };
240 from = new int[] { gene2.getStart(), gene2.getEnd() };
241 gene2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
245 * map 'transcript2' to chromosome via 'gene2'
246 * transcript2/1-18 is gene2/2-11,16-23
247 * which is chromosome 45051633-45051624,45051619-45051612
249 to = new int[] { 45051633, 45051624, 45051619, 45051612 };
250 SequenceI transcript2 = alignment.findName("transcript2");
251 from = new int[] { transcript2.getStart(), transcript2.getEnd() };
252 transcript2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
257 * add a protein product as a DBRef on transcript1
259 SequenceI peptide1 = new Sequence("ENSP001", "SWRECD");
260 MapList mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 },
262 Mapping map = new Mapping(peptide1, mapList);
263 DBRefEntry product = new DBRefEntry("", "", "ENSP001", map);
264 transcript1.addDBRef(product);
267 * add a protein product as a DBRef on transcript2
269 SequenceI peptide2 = new Sequence("ENSP002", "VTLSPA");
270 mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 }, 3, 1);
271 map = new Mapping(peptide2, mapList);
272 product = new DBRefEntry("", "", "ENSP002", map);
273 transcript2.addDBRef(product);
276 * map gene3 to chromosome
278 SequenceI gene3 = alignment.findName("gene3");
279 to = new int[] { 45051610, 45051634 };
280 from = new int[] { gene3.getStart(), gene3.getEnd() };
281 gene3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(from, to,
285 * map 'transcript3' to chromosome
287 SequenceI transcript3 = alignment.findName("transcript3");
288 to = new int[] { 45051612, 45051619, 45051624, 45051633 };
289 from = new int[] { transcript3.getStart(), transcript3.getEnd() };
290 transcript3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
295 * map 'transcript4' to chromosome
297 SequenceI transcript4 = alignment.findName("transcript4");
298 to = new int[] { 45051615, 45051617, 45051619, 45051632, 45051634,
300 from = new int[] { transcript4.getStart(), transcript4.getEnd() };
301 transcript4.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
306 * add a protein product as a DBRef on transcript3
308 SequenceI peptide3 = new Sequence("ENSP003", "SWRECD");
309 mapList = new MapList(new int[] { 1, 18 }, new int[] { 1, 6 }, 3, 1);
310 map = new Mapping(peptide3, mapList);
311 product = new DBRefEntry("", "", "ENSP003", map);
312 transcript3.addDBRef(product);
318 * Test with 'gene' and 'transcript' mapped to the reverse strand of the
319 * chromosome. The VCF variant positions (in forward coordinates) should get
320 * correctly located on sequence positions.
322 * @throws IOException
324 @Test(groups = "Functional")
325 public void testDoLoad_reverseStrand() throws IOException
327 AlignmentI al = buildAlignment();
331 VCFLoader loader = new VCFLoader(f.getPath());
333 loader.doLoad(al.getSequencesArray(), null);
336 * verify variant feature(s) added to gene2
337 * gene2/1-25 maps to chromosome 45051634- reverse strand
339 List<SequenceFeature> geneFeatures = al.getSequenceAt(2)
340 .getSequenceFeatures();
341 SequenceFeatures.sortFeatures(geneFeatures, true);
342 assertEquals(geneFeatures.size(), 4);
345 * variant A/T at 45051611 maps to T/A at gene position 24
347 SequenceFeature sf = geneFeatures.get(3);
348 assertEquals(sf.getFeatureGroup(), "VCF");
349 assertEquals(sf.getBegin(), 24);
350 assertEquals(sf.getEnd(), 24);
351 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
352 assertEquals(sf.getScore(), 0f);
353 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
355 assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,A");
358 * variant A/C at 45051611 maps to T/G at gene position 24
360 sf = geneFeatures.get(2);
361 assertEquals(sf.getFeatureGroup(), "VCF");
362 assertEquals(sf.getBegin(), 24);
363 assertEquals(sf.getEnd(), 24);
364 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
365 assertEquals(sf.getScore(), 0f);
366 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
368 assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,G");
371 * variant G/C at 45051613 maps to C/G at gene position 22
373 sf = geneFeatures.get(1);
374 assertEquals(sf.getFeatureGroup(), "VCF");
375 assertEquals(sf.getBegin(), 22);
376 assertEquals(sf.getEnd(), 22);
377 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
378 assertEquals(sf.getScore(), 0f);
379 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
381 assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
384 * insertion G/GA at 45051613 maps to an insertion at
385 * the preceding position (21) on reverse strand gene
386 * reference: CAAGC -> GCTTG/21-25
387 * genomic variant: CAAGAC (G/GA)
388 * gene variant: GTCTTG (G/GT at 21)
390 sf = geneFeatures.get(0);
391 assertEquals(sf.getFeatureGroup(), "VCF");
392 assertEquals(sf.getBegin(), 21);
393 assertEquals(sf.getEnd(), 21);
394 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
395 assertEquals(sf.getScore(), 0f);
396 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
398 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
401 * verify 2 variant features added to transcript2
403 List<SequenceFeature> transcriptFeatures = al.getSequenceAt(3)
404 .getSequenceFeatures();
405 assertEquals(transcriptFeatures.size(), 2);
408 * insertion G/GT at position 21 of gene maps to position 16 of transcript
410 sf = transcriptFeatures.get(0);
411 assertEquals(sf.getFeatureGroup(), "VCF");
412 assertEquals(sf.getBegin(), 16);
413 assertEquals(sf.getEnd(), 16);
414 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
415 assertEquals(sf.getScore(), 0f);
416 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
418 assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
421 * SNP C/G at position 22 of gene maps to position 17 of transcript
423 sf = transcriptFeatures.get(1);
424 assertEquals(sf.getFeatureGroup(), "VCF");
425 assertEquals(sf.getBegin(), 17);
426 assertEquals(sf.getEnd(), 17);
427 assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
428 assertEquals(sf.getScore(), 0f);
429 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
431 assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
434 * verify variant feature(s) computed and added to protein
435 * last codon GCT varies to GGT giving A/G in the last peptide position
437 DBRefEntry[] dbRefs = al.getSequenceAt(3).getDBRefs();
438 SequenceI peptide = null;
439 for (DBRefEntry dbref : dbRefs)
441 if (dbref.getMap().getMap().getFromRatio() == 3)
443 peptide = dbref.getMap().getTo();
446 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
447 assertEquals(proteinFeatures.size(), 1);
448 sf = proteinFeatures.get(0);
449 assertEquals(sf.getFeatureGroup(), "VCF");
450 assertEquals(sf.getBegin(), 6);
451 assertEquals(sf.getEnd(), 6);
452 assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
453 assertEquals(sf.getDescription(), "p.Ala6Gly");
457 * Tests that if VEP consequence (CSQ) data is present in the VCF data, then
458 * it is added to the variant feature, but restricted where possible to the
459 * consequences for a specific transcript
461 * @throws IOException
463 @Test(groups = "Functional")
464 public void testDoLoad_vepCsq() throws IOException
466 AlignmentI al = buildAlignment();
468 VCFLoader loader = new VCFLoader("test/jalview/io/vcf/testVcf.vcf");
471 * VCF data file with variants at gene3 positions
476 * 17 A/AC (insertion), A/G
478 loader.doLoad(al.getSequencesArray(), null);
481 * verify variant feature(s) added to gene3
483 List<SequenceFeature> geneFeatures = al.findName("gene3")
484 .getSequenceFeatures();
485 SequenceFeatures.sortFeatures(geneFeatures, true);
486 assertEquals(geneFeatures.size(), 7);
487 SequenceFeature sf = geneFeatures.get(0);
488 assertEquals(sf.getBegin(), 1);
489 assertEquals(sf.getEnd(), 1);
490 assertEquals(sf.getScore(), 0f);
491 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.1f, DELTA);
492 assertEquals(sf.getValue("alleles"), "C,A");
493 // gene features include Consequence for all transcripts
494 Map map = (Map) sf.getValue("CSQ");
495 assertEquals(map.size(), 9);
497 sf = geneFeatures.get(1);
498 assertEquals(sf.getBegin(), 5);
499 assertEquals(sf.getEnd(), 5);
500 assertEquals(sf.getScore(), 0f);
501 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
502 assertEquals(sf.getValue("alleles"), "C,T");
503 map = (Map) sf.getValue("CSQ");
504 assertEquals(map.size(), 9);
506 sf = geneFeatures.get(2);
507 assertEquals(sf.getBegin(), 9);
508 assertEquals(sf.getEnd(), 11); // deletion over 3 positions
509 assertEquals(sf.getScore(), 0f);
510 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.3f, DELTA);
511 assertEquals(sf.getValue("alleles"), "CGG,C");
512 map = (Map) sf.getValue("CSQ");
513 assertEquals(map.size(), 9);
515 sf = geneFeatures.get(3);
516 assertEquals(sf.getBegin(), 13);
517 assertEquals(sf.getEnd(), 13);
518 assertEquals(sf.getScore(), 0f);
519 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
520 assertEquals(sf.getValue("alleles"), "C,T");
521 map = (Map) sf.getValue("CSQ");
522 assertEquals(map.size(), 9);
524 sf = geneFeatures.get(4);
525 assertEquals(sf.getBegin(), 13);
526 assertEquals(sf.getEnd(), 13);
527 assertEquals(sf.getScore(), 0f);
528 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
529 assertEquals(sf.getValue("alleles"), "C,G");
530 map = (Map) sf.getValue("CSQ");
531 assertEquals(map.size(), 9);
533 sf = geneFeatures.get(5);
534 assertEquals(sf.getBegin(), 17);
535 assertEquals(sf.getEnd(), 17);
536 assertEquals(sf.getScore(), 0f);
537 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
538 assertEquals(sf.getValue("alleles"), "A,G");
539 map = (Map) sf.getValue("CSQ");
540 assertEquals(map.size(), 9);
542 sf = geneFeatures.get(6);
543 assertEquals(sf.getBegin(), 17);
544 assertEquals(sf.getEnd(), 17); // insertion
545 assertEquals(sf.getScore(), 0f);
546 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
547 assertEquals(sf.getValue("alleles"), "A,AC");
548 map = (Map) sf.getValue("CSQ");
549 assertEquals(map.size(), 9);
552 * verify variant feature(s) added to transcript3
553 * at columns 5 (1), 17 (2), positions 3, 11
554 * note the deletion at columns 9-11 is not transferred since col 11
555 * has no mapping to transcript 3
557 List<SequenceFeature> transcriptFeatures = al.findName("transcript3")
558 .getSequenceFeatures();
559 SequenceFeatures.sortFeatures(transcriptFeatures, true);
560 assertEquals(transcriptFeatures.size(), 3);
561 sf = transcriptFeatures.get(0);
562 assertEquals(sf.getBegin(), 3);
563 assertEquals(sf.getEnd(), 3);
564 assertEquals(sf.getScore(), 0f);
565 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.2f, DELTA);
566 assertEquals(sf.getValue("alleles"), "C,T");
567 // transcript features only have Consequence for that transcripts
568 map = (Map) sf.getValue("CSQ");
569 assertEquals(map.size(), 9);
570 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
572 sf = transcriptFeatures.get(1);
573 assertEquals(sf.getBegin(), 11);
574 assertEquals(sf.getEnd(), 11);
575 assertEquals(sf.getScore(), 0f);
576 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
577 assertEquals(sf.getValue("alleles"), "A,G");
578 assertEquals(map.size(), 9);
579 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
581 sf = transcriptFeatures.get(2);
582 assertEquals(sf.getBegin(), 11);
583 assertEquals(sf.getEnd(), 11);
584 assertEquals(sf.getScore(), 0f);
585 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
586 assertEquals(sf.getValue("alleles"), "A,AC");
587 assertEquals(map.size(), 9);
588 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
591 * verify variants computed on protein product for transcript3
593 * codon variants are AGC/AGT position 1 which is synonymous
594 * and GAG/GGG which is E/G in position 4
595 * the insertion variant is not transferred to the peptide
597 DBRefEntry[] dbRefs = al.findName("transcript3").getDBRefs();
598 SequenceI peptide = null;
599 for (DBRefEntry dbref : dbRefs)
601 if (dbref.getMap().getMap().getFromRatio() == 3)
603 peptide = dbref.getMap().getTo();
606 List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
607 SequenceFeatures.sortFeatures(proteinFeatures, true);
608 assertEquals(proteinFeatures.size(), 2);
609 sf = proteinFeatures.get(0);
610 assertEquals(sf.getFeatureGroup(), "VCF");
611 assertEquals(sf.getBegin(), 1);
612 assertEquals(sf.getEnd(), 1);
613 assertEquals(sf.getType(), SequenceOntologyI.SYNONYMOUS_VARIANT);
614 assertEquals(sf.getDescription(), "agC/agT");
615 sf = proteinFeatures.get(1);
616 assertEquals(sf.getFeatureGroup(), "VCF");
617 assertEquals(sf.getBegin(), 4);
618 assertEquals(sf.getEnd(), 4);
619 assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
620 assertEquals(sf.getDescription(), "p.Glu4Gly");
623 * verify variant feature(s) added to transcript4
624 * at columns 13 (2) and 17 (2), positions 7 and 11
626 transcriptFeatures = al.findName("transcript4").getSequenceFeatures();
627 SequenceFeatures.sortFeatures(transcriptFeatures, true);
628 assertEquals(transcriptFeatures.size(), 4);
629 sf = transcriptFeatures.get(0);
630 assertEquals(sf.getBegin(), 7);
631 assertEquals(sf.getEnd(), 7);
632 assertEquals(sf.getScore(), 0f);
633 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.5f, DELTA);
634 assertEquals(sf.getValue("alleles"), "C,T");
635 assertEquals(map.size(), 9);
636 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
638 sf = transcriptFeatures.get(1);
639 assertEquals(sf.getBegin(), 7);
640 assertEquals(sf.getEnd(), 7);
641 assertEquals(sf.getScore(), 0f);
642 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.4f, DELTA);
643 assertEquals(sf.getValue("alleles"), "C,G");
644 assertEquals(map.size(), 9);
645 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
647 sf = transcriptFeatures.get(2);
648 assertEquals(sf.getBegin(), 11);
649 assertEquals(sf.getEnd(), 11);
650 assertEquals(sf.getScore(), 0f);
651 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.7f, DELTA);
652 assertEquals(sf.getValue("alleles"), "A,G");
653 assertEquals(map.size(), 9);
654 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
656 sf = transcriptFeatures.get(3);
657 assertEquals(sf.getBegin(), 11);
658 assertEquals(sf.getEnd(), 11);
659 assertEquals(sf.getScore(), 0f);
660 assertEquals(Float.parseFloat((String) sf.getValue("AF")), 0.6f, DELTA);
661 assertEquals(sf.getValue("alleles"), "A,AC");
662 assertEquals(map.size(), 9);
663 assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
667 * A test that demonstrates loading a contig sequence from an indexed sequence
668 * database which is the reference for a VCF file
670 * @throws IOException
672 @Test(groups = "Functional")
673 public void testLoadVCFContig() throws IOException
675 VCFLoader loader = new VCFLoader(
676 "test/jalview/io/vcf/testVcf2.vcf");
678 SequenceI seq = loader.loadVCFContig("contig123");
679 assertEquals(seq.getLength(), 15);
680 assertEquals(seq.getSequenceAsString(), "AAAAACCCCCGGGGG");
681 List<SequenceFeature> features = seq.getSequenceFeatures();
682 SequenceFeatures.sortFeatures(features, true);
683 assertEquals(features.size(), 2);
684 SequenceFeature sf = features.get(0);
685 assertEquals(sf.getBegin(), 8);
686 assertEquals(sf.getEnd(), 8);
687 assertEquals(sf.getDescription(), "C,A");
688 sf = features.get(1);
689 assertEquals(sf.getBegin(), 12);
690 assertEquals(sf.getEnd(), 12);
691 assertEquals(sf.getDescription(), "G,T");
693 seq = loader.loadVCFContig("contig789");
694 assertEquals(seq.getLength(), 25);
695 assertEquals(seq.getSequenceAsString(), "GGGGGTTTTTAAAAACCCCCGGGGG");
696 features = seq.getSequenceFeatures();
697 SequenceFeatures.sortFeatures(features, true);
698 assertEquals(features.size(), 2);
699 sf = features.get(0);
700 assertEquals(sf.getBegin(), 2);
701 assertEquals(sf.getEnd(), 2);
702 assertEquals(sf.getDescription(), "G,T");
703 sf = features.get(1);
704 assertEquals(sf.getBegin(), 21);
705 assertEquals(sf.getEnd(), 21);
706 assertEquals(sf.getDescription(), "G,A");
708 seq = loader.loadVCFContig("contig456");
709 assertEquals(seq.getLength(), 20);
710 assertEquals(seq.getSequenceAsString(), "CCCCCGGGGGTTTTTAAAAA");
711 features = seq.getSequenceFeatures();
712 SequenceFeatures.sortFeatures(features, true);
713 assertEquals(features.size(), 1);
714 sf = features.get(0);
715 assertEquals(sf.getBegin(), 15);
716 assertEquals(sf.getEnd(), 15);
717 assertEquals(sf.getDescription(), "T,C");