X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fio%2Fvcf%2FVCFLoaderTest.java;h=2b418de990b35bdd70eecca833f8823d879b95ef;hb=181fd0fa4064654d94f76c3f4ff9333f0ea1834b;hp=5607b4ba1afc60474edf9ac9598af9d2635ece8a;hpb=0e1130c3857c4cb86acec5fed9b4a7aa779e621b;p=jalview.git
diff --git a/test/jalview/io/vcf/VCFLoaderTest.java b/test/jalview/io/vcf/VCFLoaderTest.java
index 5607b4b..2b418de 100644
--- a/test/jalview/io/vcf/VCFLoaderTest.java
+++ b/test/jalview/io/vcf/VCFLoaderTest.java
@@ -1,27 +1,54 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.io.vcf;
+import static jalview.io.gff.SequenceOntologyI.SEQUENCE_VARIANT;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
+import jalview.bin.Cache;
+import jalview.bin.Console;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.Mapping;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureAttributes;
import jalview.datamodel.features.SequenceFeatures;
import jalview.gui.AlignFrame;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
import jalview.io.gff.Gff3Helper;
-import jalview.io.gff.SequenceOntologyI;
import jalview.util.MapList;
import java.io.File;
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.BeforeTest;
import org.testng.annotations.Test;
public class VCFLoaderTest
@@ -29,11 +56,10 @@ public class VCFLoaderTest
private static final float DELTA = 0.00001f;
// columns 9717- of gene P30419 from Ensembl (much modified)
- private static final String FASTA = ""
- +
- /*
- * forward strand 'gene' and 'transcript' with two exons
- */
+ private static final String FASTA = "" +
+ /*
+ * forward strand 'gene' and 'transcript' with two exons
+ */
">gene1/1-25 chromosome:GRCh38:17:45051610:45051634:1\n"
+ "CAAGCTGGCGGACGAGAGTGTGACA\n"
+ ">transcript1/1-18\n--AGCTGGCG----AGAGTGTGAC-\n"
@@ -42,8 +68,8 @@ public class VCFLoaderTest
* reverse strand gene and transcript (reverse complement alleles!)
*/
+ ">gene2/1-25 chromosome:GRCh38:17:45051610:45051634:-1\n"
- + "TGTCACACTCTCGTCCGCCAGCTTG\n"
- + ">transcript2/1-18\n" + "-GTCACACTCT----CGCCAGCT--\n"
+ + "TGTCACACTCTCGTCCGCCAGCTTG\n" + ">transcript2/1-18\n"
+ + "-GTCACACTCT----CGCCAGCT--\n"
/*
* 'gene' on chromosome 5 with two transcripts
@@ -54,25 +80,54 @@ public class VCFLoaderTest
+ ">transcript4/1-18\n-----TGG-GGACGAGAGTGTGA-A\n";
private static final String[] VCF = { "##fileformat=VCFv4.2",
+ // fields other than AF are ignored when parsing as they have no INFO
+ // definition
"##INFO=",
+ "##INFO= geneFeatures = al.getSequenceAt(0)
.getSequenceFeatures();
SequenceFeatures.sortFeatures(geneFeatures, true);
- assertEquals(geneFeatures.size(), 4);
+ assertEquals(geneFeatures.size(), 5);
SequenceFeature sf = geneFeatures.get(0);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 2);
assertEquals(sf.getEnd(), 2);
- assertEquals(sf.getScore(), 4.0e-03, DELTA);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(sf.getValue("AF"), "4.0e-03");
+ assertEquals(sf.getValue("AF_AFR"), "2.3e-4");
assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,C");
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getValue("POS"), "45051611");
+ assertEquals(sf.getValue("ID"), "rs384765");
+ assertEquals(sf.getValue("QUAL"), "1666.64");
+ assertEquals(sf.getValue("FILTER"), "RF;XYZ");
+ // malformed integer for AC_Female is ignored (JAL-3375)
+ assertNull(sf.getValue("AC_Female"));
+
sf = geneFeatures.get(1);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 2);
assertEquals(sf.getEnd(), 2);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 5.0e-03, DELTA);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
+ DELTA);
+ assertEquals(sf.getValue("AC_Female"), "12");
+ // malformed float for AF_AFR is ignored (JAL-3375)
+ assertNull(sf.getValue("AC_AFR"));
assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,T");
sf = geneFeatures.get(2);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 4);
assertEquals(sf.getEnd(), 4);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 2.0e-03, DELTA);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
+ DELTA);
assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
sf = geneFeatures.get(3);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 4);
assertEquals(sf.getEnd(), 4);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 3.0e-03, DELTA);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
+ DELTA);
assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
+ assertNull(sf.getValue("ID")); // '.' is ignored
+ assertNull(sf.getValue("FILTER")); // '.' is ignored
+
+ sf = geneFeatures.get(4);
+ assertEquals(sf.getFeatureGroup(), "VCF");
+ assertEquals(sf.getBegin(), 6);
+ assertEquals(sf.getEnd(), 6);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ // AF=. should not have been captured
+ assertNull(sf.getValue("AF"));
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
/*
* verify variant feature(s) added to transcript
*/
List transcriptFeatures = al.getSequenceAt(1)
.getSequenceFeatures();
- assertEquals(transcriptFeatures.size(), 2);
+ assertEquals(transcriptFeatures.size(), 3);
sf = transcriptFeatures.get(0);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 2);
assertEquals(sf.getEnd(), 2);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 2.0e-03, DELTA);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
+ DELTA);
assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,C");
sf = transcriptFeatures.get(1);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 2);
assertEquals(sf.getEnd(), 2);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 3.0e-03, DELTA);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
+ DELTA);
assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
/*
* verify SNP variant feature(s) computed and added to protein
* first codon AGC varies to ACC giving S/T
*/
- DBRefEntry[] dbRefs = al.getSequenceAt(1).getDBRefs();
+ List dbRefs = al.getSequenceAt(1).getDBRefs();
SequenceI peptide = null;
for (DBRefEntry dbref : dbRefs)
{
@@ -151,16 +240,14 @@ public class VCFLoaderTest
}
}
List proteinFeatures = peptide.getSequenceFeatures();
- assertEquals(proteinFeatures.size(), 1);
- sf = proteinFeatures.get(0);
- assertEquals(sf.getFeatureGroup(), "VCF");
- assertEquals(sf.getBegin(), 1);
- assertEquals(sf.getEnd(), 1);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getDescription(), "p.Ser1Thr");
+
+ /*
+ * JAL-3187 don't precompute protein features, do dynamically instead
+ */
+ assertTrue(proteinFeatures.isEmpty());
}
- private File makeVcf() throws IOException
+ private File makeVcfFile() throws IOException
{
File f = File.createTempFile("Test", ".vcf");
f.deleteOnExit();
@@ -191,8 +278,8 @@ public class VCFLoaderTest
SequenceI gene1 = alignment.findName("gene1");
int[] to = new int[] { 45051610, 45051634 };
int[] from = new int[] { gene1.getStart(), gene1.getEnd() };
- gene1.setGeneLoci("homo_sapiens", "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'
@@ -202,9 +289,8 @@ public class VCFLoaderTest
to = new int[] { 45051612, 45051619, 45051624, 45051633 };
SequenceI transcript1 = alignment.findName("transcript1");
from = new int[] { transcript1.getStart(), transcript1.getEnd() };
- transcript1.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
- from, to,
- 1, 1));
+ transcript1.setGeneLoci("homo_sapiens", "GRCh38", "17",
+ new MapList(from, to, 1, 1));
/*
* map gene2 to chromosome reverse strand
@@ -212,8 +298,8 @@ public class VCFLoaderTest
SequenceI gene2 = alignment.findName("gene2");
to = new int[] { 45051634, 45051610 };
from = new int[] { gene2.getStart(), gene2.getEnd() };
- gene2.setGeneLoci("homo_sapiens", "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'
@@ -223,9 +309,8 @@ public class VCFLoaderTest
to = new int[] { 45051633, 45051624, 45051619, 45051612 };
SequenceI transcript2 = alignment.findName("transcript2");
from = new int[] { transcript2.getStart(), transcript2.getEnd() };
- transcript2.setGeneLoci("homo_sapiens", "GRCh38", "17", new MapList(
- from, to,
- 1, 1));
+ transcript2.setGeneLoci("homo_sapiens", "GRCh38", "17",
+ new MapList(from, to, 1, 1));
/*
* add a protein product as a DBRef on transcript1
@@ -252,8 +337,8 @@ public class VCFLoaderTest
SequenceI gene3 = alignment.findName("gene3");
to = new int[] { 45051610, 45051634 };
from = new int[] { gene3.getStart(), gene3.getEnd() };
- gene3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(from, to,
- 1, 1));
+ gene3.setGeneLoci("homo_sapiens", "GRCh38", "5",
+ new MapList(from, to, 1, 1));
/*
* map 'transcript3' to chromosome
@@ -261,9 +346,8 @@ public class VCFLoaderTest
SequenceI transcript3 = alignment.findName("transcript3");
to = new int[] { 45051612, 45051619, 45051624, 45051633 };
from = new int[] { transcript3.getStart(), transcript3.getEnd() };
- transcript3.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
- from, to,
- 1, 1));
+ transcript3.setGeneLoci("homo_sapiens", "GRCh38", "5",
+ new MapList(from, to, 1, 1));
/*
* map 'transcript4' to chromosome
@@ -272,9 +356,8 @@ public class VCFLoaderTest
to = new int[] { 45051615, 45051617, 45051619, 45051632, 45051634,
45051634 };
from = new int[] { transcript4.getStart(), transcript4.getEnd() };
- transcript4.setGeneLoci("homo_sapiens", "GRCh38", "5", new MapList(
- from, to,
- 1, 1));
+ transcript4.setGeneLoci("homo_sapiens", "GRCh38", "5",
+ new MapList(from, to, 1, 1));
/*
* add a protein product as a DBRef on transcript3
@@ -300,83 +383,116 @@ public class VCFLoaderTest
{
AlignmentI al = buildAlignment();
- VCFLoader loader = new VCFLoader(al);
+ File f = makeVcfFile();
- 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 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 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));
+ assertEquals(geneFeatures.size(), 5);
+ SequenceFeature sf;
+ /*
+ * 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(1);
assertEquals(sf.getFeatureGroup(), "VCF");
+ assertEquals(sf.getBegin(), 21);
+ assertEquals(sf.getEnd(), 21);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
+ DELTA);
+
+ /*
+ * variant G/C at 45051613 maps to C/G at gene position 22
+ */
+ sf = geneFeatures.get(2);
+ assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 22);
assertEquals(sf.getEnd(), 22);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 3.0e-03, DELTA);
- assertEquals("C,TC", sf.getValue(Gff3Helper.ALLELES));
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
+ DELTA);
- sf = geneFeatures.get(2);
+ /*
+ * variant A/C at 45051611 maps to T/G at gene position 24
+ */
+ sf = geneFeatures.get(3);
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.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,G");
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03,
+ DELTA);
- sf = geneFeatures.get(3);
+ /*
+ * variant A/T at 45051611 maps to T/A at gene position 24
+ */
+ sf = geneFeatures.get(4);
assertEquals(sf.getFeatureGroup(), "VCF");
assertEquals(sf.getBegin(), 24);
assertEquals(sf.getEnd(), 24);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 5.0e-03, DELTA);
- assertEquals("T,A", sf.getValue(Gff3Helper.ALLELES));
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,A");
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03,
+ DELTA);
/*
- * 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
+ * verify 3 variant features added to transcript2
*/
List transcriptFeatures = al.getSequenceAt(3)
.getSequenceFeatures();
- assertEquals(transcriptFeatures.size(), 2);
- sf = transcriptFeatures.get(0);
- assertEquals(sf.getFeatureGroup(), "VCF");
- assertEquals(sf.getBegin(), 17);
- assertEquals(sf.getEnd(), 17);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getScore(), 2.0e-03, DELTA);
- assertEquals("C,G", sf.getValue(Gff3Helper.ALLELES));
+ assertEquals(transcriptFeatures.size(), 3);
+ /*
+ * insertion G/GT at position 21 of gene maps to position 16 of transcript
+ */
sf = transcriptFeatures.get(1);
assertEquals(sf.getFeatureGroup(), "VCF");
+ assertEquals(sf.getBegin(), 16);
+ assertEquals(sf.getEnd(), 16);
+ assertEquals(sf.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT");
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
+ DELTA);
+
+ /*
+ * SNP C/G at position 22 of gene maps to position 17 of transcript
+ */
+ sf = transcriptFeatures.get(2);
+ 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.getType(), SEQUENCE_VARIANT);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G");
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03,
+ DELTA);
/*
* verify variant feature(s) computed and added to protein
* last codon GCT varies to GGT giving A/G in the last peptide position
*/
- DBRefEntry[] dbRefs = al.getSequenceAt(3).getDBRefs();
+ List dbRefs = al.getSequenceAt(3).getDBRefs();
SequenceI peptide = null;
for (DBRefEntry dbref : dbRefs)
{
@@ -386,13 +502,11 @@ public class VCFLoaderTest
}
}
List proteinFeatures = peptide.getSequenceFeatures();
- assertEquals(proteinFeatures.size(), 1);
- sf = proteinFeatures.get(0);
- assertEquals(sf.getFeatureGroup(), "VCF");
- assertEquals(sf.getBegin(), 6);
- assertEquals(sf.getEnd(), 6);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getDescription(), "p.Ala6Gly");
+
+ /*
+ * JAL-3187 don't precompute protein features, do dynamically instead
+ */
+ assertTrue(proteinFeatures.isEmpty());
}
/**
@@ -407,7 +521,7 @@ public class VCFLoaderTest
{
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
@@ -417,7 +531,7 @@ public class VCFLoaderTest
* 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
@@ -429,52 +543,68 @@ public class VCFLoaderTest
SequenceFeature sf = geneFeatures.get(0);
assertEquals(sf.getBegin(), 1);
assertEquals(sf.getEnd(), 1);
- assertEquals(sf.getScore(), 0.1f, DELTA);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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);
+ assertEquals(map.get("PolyPhen"), "Bad");
sf = geneFeatures.get(1);
assertEquals(sf.getBegin(), 5);
assertEquals(sf.getEnd(), 5);
- assertEquals(sf.getScore(), 0.2f, DELTA);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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);
+ assertEquals(map.get("PolyPhen"), "Bad;;"); // %3B%3B decoded
sf = geneFeatures.get(2);
assertEquals(sf.getBegin(), 9);
assertEquals(sf.getEnd(), 11); // deletion over 3 positions
- assertEquals(sf.getScore(), 0.3f, DELTA);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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
@@ -489,27 +619,31 @@ public class VCFLoaderTest
sf = transcriptFeatures.get(0);
assertEquals(sf.getBegin(), 3);
assertEquals(sf.getEnd(), 3);
- assertEquals(sf.getScore(), 0.2f, DELTA);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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
@@ -518,7 +652,7 @@ public class VCFLoaderTest
* 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();
+ List dbRefs = al.findName("transcript3").getDBRefs();
SequenceI peptide = null;
for (DBRefEntry dbref : dbRefs)
{
@@ -528,13 +662,24 @@ public class VCFLoaderTest
}
}
List proteinFeatures = peptide.getSequenceFeatures();
- assertEquals(proteinFeatures.size(), 1);
- sf = proteinFeatures.get(0);
- assertEquals(sf.getFeatureGroup(), "VCF");
- assertEquals(sf.getBegin(), 4);
- assertEquals(sf.getEnd(), 4);
- assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT);
- assertEquals(sf.getDescription(), "p.Glu4Gly");
+ /*
+ * JAL-3187 don't precompute protein features, do dynamically instead
+ */
+ assertTrue(proteinFeatures.isEmpty());
+ // 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
@@ -546,33 +691,90 @@ public class VCFLoaderTest
sf = transcriptFeatures.get(0);
assertEquals(sf.getBegin(), 7);
assertEquals(sf.getEnd(), 7);
- assertEquals(sf.getScore(), 0.5f, DELTA);
+ assertEquals(sf.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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.getScore(), 0f);
+ assertEquals(Float.parseFloat((String) sf.getValue("AF")), 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 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