package jalview.io.vcf;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+import jalview.bin.Cache;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.Mapping;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
+import java.util.Map;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class VCFLoaderTest
private static final String[] VCF = { "##fileformat=VCFv4.2",
"##INFO=<ID=AF,Number=A,Type=Float,Description=\"Allele Frequency, for each ALT allele, in the same order as listed\">",
- "##reference=GRCh38",
+ "##reference=Homo_sapiens/GRCh38",
"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO",
// A/T,C variants in position 2 of gene sequence (precedes transcript)
// should create 2 variant features with respective scores
// insertion G/GA is transferred to nucleotide but not to peptide
"17\t45051613\t.\tG\tGA,C\t1666.64\tRF\tAC=15;AF=3.0e-03,2.0e-03" };
+ @BeforeClass
+ public void setUp()
+ {
+ /*
+ * configure to capture all available VCF and VEP (CSQ) fields
+ */
+ Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ Cache.setProperty("VCF_FIELDS", ".*");
+ Cache.setProperty("VEP_FIELDS", ".*");
+ Cache.initLogger();
+ }
+
@Test(groups = "Functional")
public void testDoLoad() throws IOException
{
AlignmentI al = buildAlignment();
- VCFLoader loader = new VCFLoader(al);
File f = makeVcf();
+ VCFLoader loader = new VCFLoader(f.getPath());
- loader.doLoad(f.getPath(), null);
+ loader.doLoad(al.getSequencesArray(), null);
/*
* verify variant feature(s) added to gene
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 1);
assertEquals(sf.getEnd(), 1);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
+ assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
assertEquals(sf.getDescription(), "p.Ser1Thr");
}
SequenceI gene1 = alignment.findName("gene1");
int[] to = new int[] { 45051610, 45051634 };
int[] from = new int[] { gene1.getStart(), gene1.getEnd() };
- gene1.setGeneLoci("human", "GRCh38", "17", new MapList(from, to, 1, 1));
+ gene1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
+ 1, 1));
/*
* map 'transcript1' to chromosome via 'gene1'
to = new int[] { 45051612, 45051619, 45051624, 45051633 };
SequenceI transcript1 = alignment.findName("transcript1");
from = new int[] { transcript1.getStart(), transcript1.getEnd() };
- transcript1.setGeneLoci("human", "GRCh38", "17", new MapList(from, to,
+ transcript1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
+ from, to,
1, 1));
/*
SequenceI gene2 = alignment.findName("gene2");
to = new int[] { 45051634, 45051610 };
from = new int[] { gene2.getStart(), gene2.getEnd() };
- gene2.setGeneLoci("human", "GRCh38", "17", new MapList(from, to, 1, 1));
+ gene2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(from, to,
+ 1, 1));
/*
* map 'transcript2' to chromosome via 'gene2'
to = new int[] { 45051633, 45051624, 45051619, 45051612 };
SequenceI transcript2 = alignment.findName("transcript2");
from = new int[] { transcript2.getStart(), transcript2.getEnd() };
- transcript2.setGeneLoci("human", "GRCh38", "17", new MapList(from, to,
+ transcript2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
+ from, to,
1, 1));
/*
SequenceI gene3 = alignment.findName("gene3");
to = new int[] { 45051610, 45051634 };
from = new int[] { gene3.getStart(), gene3.getEnd() };
- gene3.setGeneLoci("human", "GRCh38", "5", new MapList(from, to, 1, 1));
+ gene3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(from, to,
+ 1, 1));
/*
* map 'transcript3' to chromosome
SequenceI transcript3 = alignment.findName("transcript3");
to = new int[] { 45051612, 45051619, 45051624, 45051633 };
from = new int[] { transcript3.getStart(), transcript3.getEnd() };
- transcript3.setGeneLoci("human", "GRCh38", "5", new MapList(from, to,
+ transcript3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
+ from, to,
1, 1));
/*
to = new int[] { 45051615, 45051617, 45051619, 45051632, 45051634,
45051634 };
from = new int[] { transcript4.getStart(), transcript4.getEnd() };
- transcript4.setGeneLoci("human", "GRCh38", "5", new MapList(from, to,
+ transcript4.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
+ from, to,
1, 1));
/*
{
AlignmentI al = buildAlignment();
- VCFLoader loader = new VCFLoader(al);
-
File f = makeVcf();
- loader.doLoad(f.getPath(), null);
+ VCFLoader loader = new VCFLoader(f.getPath());
+
+ loader.doLoad(al.getSequencesArray(), null);
/*
* verify variant feature(s) added to gene2
- * gene/1-25 maps to chromosome 45051634- reverse strand
- * variants A/T, A/C at 45051611 and G/GA,G/C at 45051613 map to
- * T/A, T/G and C/TC,C/G at gene positions 24 and 22 respectively
+ * gene2/1-25 maps to chromosome 45051634- reverse strand
*/
List<SequenceFeature> geneFeatures = al.getSequenceAt(2)
.getSequenceFeatures();
SequenceFeatures.sortFeatures(geneFeatures, true);
assertEquals(geneFeatures.size(), 4);
- SequenceFeature sf = geneFeatures.get(0);
- assertEquals(sf.getFeatureGroup(), "VCF");
- assertEquals(sf.getBegin(), 22);
- assertEquals(sf.getEnd(), 22);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 2.0e-03, DELTA);
- assertEquals("C,G", sf.getValue(Gff3Helper.ALLELES));
- sf = geneFeatures.get(1);
+ /*
+ * variant A/T at 45051611 maps to T/A at gene position 24
+ */
+ SequenceFeature sf = geneFeatures.get(3);
assertEquals(sf.getFeatureGroup(), "VCF");
- assertEquals(sf.getBegin(), 22);
- assertEquals(sf.getEnd(), 22);
+ assertEquals(sf.getBegin(), 24);
+ assertEquals(sf.getEnd(), 24);
assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 3.0e-03, DELTA);
- assertEquals("C,TC", sf.getValue(Gff3Helper.ALLELES));
+ assertEquals(sf.getScore(), 5.0e-03, DELTA);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,A");
+ /*
+ * variant A/C at 45051611 maps to T/G at gene position 24
+ */
sf = geneFeatures.get(2);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 24);
assertEquals(sf.getEnd(), 24);
assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
assertEquals(sf.getScore(), 4.0e-03, DELTA);
- assertEquals("T,G", sf.getValue(Gff3Helper.ALLELES));
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,G");
- sf = geneFeatures.get(3);
+ /*
+ * variant G/C at 45051613 maps to C/G at gene position 22
+ */
+ sf = geneFeatures.get(1);
assertEquals(sf.getFeatureGroup(), "VCF");
- assertEquals(sf.getBegin(), 24);
- assertEquals(sf.getEnd(), 24);
+ assertEquals(sf.getBegin(), 22);
+ assertEquals(sf.getEnd(), 22);
assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 5.0e-03, DELTA);
- assertEquals("T,A", sf.getValue(Gff3Helper.ALLELES));
+ assertEquals(sf.getScore(), 2.0e-03, DELTA);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
/*
- * verify variant feature(s) added to transcript2
- * variants G/GA,G/C at position 22 of gene overlap and map to
- * C/TC,C/G at position 17 of transcript
+ * insertion G/GA at 45051613 maps to an insertion at
+ * the preceding position (21) on reverse strand gene
+ * reference: CAAGC -> GCTTG/21-25
+ * genomic variant: CAAGAC (G/GA)
+ * gene variant: GTCTTG (G/GT at 21)
+ */
+ sf = geneFeatures.get(0);
+ assertEquals(sf.getFeatureGroup(), "VCF");
+ assertEquals(sf.getBegin(), 21);
+ assertEquals(sf.getEnd(), 21);
+ assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 3.0e-03, DELTA);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
+
+ /*
+ * verify 2 variant features added to transcript2
*/
List<SequenceFeature> transcriptFeatures = al.getSequenceAt(3)
.getSequenceFeatures();
assertEquals(transcriptFeatures.size(), 2);
+
+ /*
+ * insertion G/GT at position 21 of gene maps to position 16 of transcript
+ */
sf = transcriptFeatures.get(0);
assertEquals(sf.getFeatureGroup(), "VCF");
- assertEquals(sf.getBegin(), 17);
- assertEquals(sf.getEnd(), 17);
+ assertEquals(sf.getBegin(), 16);
+ assertEquals(sf.getEnd(), 16);
assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 2.0e-03, DELTA);
- assertEquals("C,G", sf.getValue(Gff3Helper.ALLELES));
+ assertEquals(sf.getScore(), 3.0e-03, DELTA);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
+ /*
+ * SNP C/G at position 22 of gene maps to position 17 of transcript
+ */
sf = transcriptFeatures.get(1);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 17);
assertEquals(sf.getEnd(), 17);
assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 3.0e-03, DELTA);
- assertEquals("C,TC", sf.getValue(Gff3Helper.ALLELES));
+ assertEquals(sf.getScore(), 2.0e-03, DELTA);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
/*
* verify variant feature(s) computed and added to protein
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 6);
assertEquals(sf.getEnd(), 6);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
+ assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
assertEquals(sf.getDescription(), "p.Ala6Gly");
}
{
AlignmentI al = buildAlignment();
- VCFLoader loader = new VCFLoader(al);
+ VCFLoader loader = new VCFLoader("test/jalview/io/vcf/testVcf.vcf");
/*
* VCF data file with variants at gene3 positions
* 13 C/G, C/T
* 17 A/AC (insertion), A/G
*/
- loader.doLoad("test/jalview/io/vcf/testVcf.dat", null);
+ loader.doLoad(al.getSequencesArray(), null);
/*
* verify variant feature(s) added to gene3
assertEquals(sf.getScore(), 0.1f, DELTA);
assertEquals(sf.getValue("alleles"), "C,A");
// gene features include Consequence for all transcripts
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 2);
+ Map map = (Map) sf.getValue("CSQ");
+ assertEquals(map.size(), 9);
sf = geneFeatures.get(1);
assertEquals(sf.getBegin(), 5);
assertEquals(sf.getEnd(), 5);
assertEquals(sf.getScore(), 0.2f, DELTA);
assertEquals(sf.getValue("alleles"), "C,T");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 2);
+ map = (Map) sf.getValue("CSQ");
+ assertEquals(map.size(), 9);
sf = geneFeatures.get(2);
assertEquals(sf.getBegin(), 9);
assertEquals(sf.getEnd(), 11); // deletion over 3 positions
assertEquals(sf.getScore(), 0.3f, DELTA);
assertEquals(sf.getValue("alleles"), "CGG,C");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 2);
+ map = (Map) sf.getValue("CSQ");
+ assertEquals(map.size(), 9);
sf = geneFeatures.get(3);
assertEquals(sf.getBegin(), 13);
assertEquals(sf.getEnd(), 13);
assertEquals(sf.getScore(), 0.5f, DELTA);
assertEquals(sf.getValue("alleles"), "C,T");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 2);
+ map = (Map) sf.getValue("CSQ");
+ assertEquals(map.size(), 9);
sf = geneFeatures.get(4);
assertEquals(sf.getBegin(), 13);
assertEquals(sf.getEnd(), 13);
assertEquals(sf.getScore(), 0.4f, DELTA);
assertEquals(sf.getValue("alleles"), "C,G");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 2);
+ map = (Map) sf.getValue("CSQ");
+ assertEquals(map.size(), 9);
sf = geneFeatures.get(5);
assertEquals(sf.getBegin(), 17);
assertEquals(sf.getEnd(), 17);
assertEquals(sf.getScore(), 0.7f, DELTA);
assertEquals(sf.getValue("alleles"), "A,G");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 2);
+ map = (Map) sf.getValue("CSQ");
+ assertEquals(map.size(), 9);
sf = geneFeatures.get(6);
assertEquals(sf.getBegin(), 17);
assertEquals(sf.getEnd(), 17); // insertion
assertEquals(sf.getScore(), 0.6f, DELTA);
assertEquals(sf.getValue("alleles"), "A,AC");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 2);
+ map = (Map) sf.getValue("CSQ");
+ assertEquals(map.size(), 9);
/*
* verify variant feature(s) added to transcript3
assertEquals(sf.getScore(), 0.2f, DELTA);
assertEquals(sf.getValue("alleles"), "C,T");
// transcript features only have Consequence for that transcripts
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 1);
- assertTrue(sf.getValue("CSQ").toString().contains("transcript3"));
+ map = (Map) sf.getValue("CSQ");
+ assertEquals(map.size(), 9);
+ assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
sf = transcriptFeatures.get(1);
assertEquals(sf.getBegin(), 11);
assertEquals(sf.getEnd(), 11);
assertEquals(sf.getScore(), 0.7f, DELTA);
assertEquals(sf.getValue("alleles"), "A,G");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 1);
- assertTrue(sf.getValue("CSQ").toString().contains("transcript3"));
+ assertEquals(map.size(), 9);
+ assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
sf = transcriptFeatures.get(2);
assertEquals(sf.getBegin(), 11);
assertEquals(sf.getEnd(), 11);
assertEquals(sf.getScore(), 0.6f, DELTA);
assertEquals(sf.getValue("alleles"), "A,AC");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 1);
- assertTrue(sf.getValue("CSQ").toString().contains("transcript3"));
+ assertEquals(map.size(), 9);
+ assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3");
+
+ /*
+ * verify variants computed on protein product for transcript3
+ * peptide is SWRECD
+ * codon variants are AGC/AGT position 1 which is synonymous
+ * and GAG/GGG which is E/G in position 4
+ * the insertion variant is not transferred to the peptide
+ */
+ DBRefEntry[] dbRefs = al.findName("transcript3").getDBRefs();
+ SequenceI peptide = null;
+ for (DBRefEntry dbref : dbRefs)
+ {
+ if (dbref.getMap().getMap().getFromRatio() == 3)
+ {
+ peptide = dbref.getMap().getTo();
+ }
+ }
+ List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
+ SequenceFeatures.sortFeatures(proteinFeatures, true);
+ assertEquals(proteinFeatures.size(), 2);
+ sf = proteinFeatures.get(0);
+ assertEquals(sf.getFeatureGroup(), "VCF");
+ assertEquals(sf.getBegin(), 1);
+ assertEquals(sf.getEnd(), 1);
+ assertEquals(sf.getType(), SequenceOntologyI.SYNONYMOUS_VARIANT);
+ assertEquals(sf.getDescription(), "agC/agT");
+ sf = proteinFeatures.get(1);
+ assertEquals(sf.getFeatureGroup(), "VCF");
+ assertEquals(sf.getBegin(), 4);
+ assertEquals(sf.getEnd(), 4);
+ assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
+ assertEquals(sf.getDescription(), "p.Glu4Gly");
/*
* verify variant feature(s) added to transcript4
assertEquals(sf.getEnd(), 7);
assertEquals(sf.getScore(), 0.5f, DELTA);
assertEquals(sf.getValue("alleles"), "C,T");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 1);
- assertTrue(sf.getValue("CSQ").toString().contains("transcript4"));
+ assertEquals(map.size(), 9);
+ assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
sf = transcriptFeatures.get(1);
assertEquals(sf.getBegin(), 7);
assertEquals(sf.getEnd(), 7);
assertEquals(sf.getScore(), 0.4f, DELTA);
assertEquals(sf.getValue("alleles"), "C,G");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 1);
- assertTrue(sf.getValue("CSQ").toString().contains("transcript4"));
+ assertEquals(map.size(), 9);
+ assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
sf = transcriptFeatures.get(2);
assertEquals(sf.getBegin(), 11);
assertEquals(sf.getEnd(), 11);
assertEquals(sf.getScore(), 0.7f, DELTA);
assertEquals(sf.getValue("alleles"), "A,G");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 1);
- assertTrue(sf.getValue("CSQ").toString().contains("transcript4"));
+ assertEquals(map.size(), 9);
+ assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
sf = transcriptFeatures.get(3);
assertEquals(sf.getBegin(), 11);
assertEquals(sf.getEnd(), 11);
assertEquals(sf.getScore(), 0.6f, DELTA);
assertEquals(sf.getValue("alleles"), "A,AC");
- assertEquals(((String) sf.getValue("CSQ")).split(",").length, 1);
- assertTrue(sf.getValue("CSQ").toString().contains("transcript4"));
+ assertEquals(map.size(), 9);
+ assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4");
+ }
+
+ /**
+ * A test that demonstrates loading a contig sequence from an indexed sequence
+ * database which is the reference for a VCF file
+ *
+ * @throws IOException
+ */
+ @Test(groups = "Functional")
+ public void testLoadVCFContig() throws IOException
+ {
+ VCFLoader loader = new VCFLoader(
+ "test/jalview/io/vcf/testVcf2.vcf");
+
+ SequenceI seq = loader.loadVCFContig("contig123");
+ assertEquals(seq.getLength(), 15);
+ assertEquals(seq.getSequenceAsString(), "AAAAACCCCCGGGGG");
+ List<SequenceFeature> features = seq.getSequenceFeatures();
+ SequenceFeatures.sortFeatures(features, true);
+ assertEquals(features.size(), 2);
+ SequenceFeature sf = features.get(0);
+ assertEquals(sf.getBegin(), 8);
+ assertEquals(sf.getEnd(), 8);
+ assertEquals(sf.getDescription(), "C,A");
+ sf = features.get(1);
+ assertEquals(sf.getBegin(), 12);
+ assertEquals(sf.getEnd(), 12);
+ assertEquals(sf.getDescription(), "G,T");
+
+ seq = loader.loadVCFContig("contig789");
+ assertEquals(seq.getLength(), 25);
+ assertEquals(seq.getSequenceAsString(), "GGGGGTTTTTAAAAACCCCCGGGGG");
+ features = seq.getSequenceFeatures();
+ SequenceFeatures.sortFeatures(features, true);
+ assertEquals(features.size(), 2);
+ sf = features.get(0);
+ assertEquals(sf.getBegin(), 2);
+ assertEquals(sf.getEnd(), 2);
+ assertEquals(sf.getDescription(), "G,T");
+ sf = features.get(1);
+ assertEquals(sf.getBegin(), 21);
+ assertEquals(sf.getEnd(), 21);
+ assertEquals(sf.getDescription(), "G,A");
+
+ seq = loader.loadVCFContig("contig456");
+ assertEquals(seq.getLength(), 20);
+ assertEquals(seq.getSequenceAsString(), "CCCCCGGGGGTTTTTAAAAA");
+ features = seq.getSequenceFeatures();
+ SequenceFeatures.sortFeatures(features, true);
+ assertEquals(features.size(), 1);
+ sf = features.get(0);
+ assertEquals(sf.getBegin(), 15);
+ assertEquals(sf.getEnd(), 15);
+ assertEquals(sf.getDescription(), "T,C");
}
-}
+}
\ No newline at end of file