From 352ce69c8b9372aeaa0e87e9df29b90680a4ad59 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 22 Feb 2019 10:04:02 +0000 Subject: [PATCH] JAL-2738 don't set AF as feature score --- src/jalview/io/vcf/VCFLoader.java | 31 +---------- test/jalview/io/vcf/VCFLoaderTest.java | 90 +++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 56 deletions(-) diff --git a/src/jalview/io/vcf/VCFLoader.java b/src/jalview/io/vcf/VCFLoader.java index de2f18a..5ba5d93 100644 --- a/src/jalview/io/vcf/VCFLoader.java +++ b/src/jalview/io/vcf/VCFLoader.java @@ -835,33 +835,6 @@ public class VCFLoader } /** - * A convenience method to get the AF value for the given alternate allele - * index - * - * @param variant - * @param alleleIndex - * @return - */ - protected float getAlleleFrequency(VariantContext variant, int alleleIndex) - { - float score = 0f; - String attributeValue = getAttributeValue(variant, - ALLELE_FREQUENCY_KEY, alleleIndex); - if (attributeValue != null) - { - try - { - score = Float.parseFloat(attributeValue); - } catch (NumberFormatException e) - { - // leave as 0 - } - } - - return score; - } - - /** * A convenience method to get an attribute value for an alternate allele * * @param variant @@ -981,10 +954,8 @@ public class VCFLoader type = getOntologyTerm(consequence); } - float score = getAlleleFrequency(variant, altAlleleIndex); - SequenceFeature sf = new SequenceFeature(type, alleles, featureStart, - featureEnd, score, FEATURE_GROUP_VCF); + featureEnd, FEATURE_GROUP_VCF); sf.setSource(sourceId); sf.setValue(Gff3Helper.ALLELES, alleles); diff --git a/test/jalview/io/vcf/VCFLoaderTest.java b/test/jalview/io/vcf/VCFLoaderTest.java index 7e3c0b4..58c73dd 100644 --- a/test/jalview/io/vcf/VCFLoaderTest.java +++ b/test/jalview/io/vcf/VCFLoaderTest.java @@ -103,7 +103,9 @@ public class VCFLoaderTest assertEquals(sf.getFeatureGroup(), "VCF"); assertEquals(sf.getBegin(), 2); assertEquals(sf.getEnd(), 2); - assertEquals(sf.getScore(), 4.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,C"); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); sf = geneFeatures.get(1); @@ -111,7 +113,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 2); assertEquals(sf.getEnd(), 2); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 5.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,T"); sf = geneFeatures.get(2); @@ -119,7 +123,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 4); assertEquals(sf.getEnd(), 4); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 2.0e-03, DELTA); + 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); @@ -127,7 +133,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 4); assertEquals(sf.getEnd(), 4); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 3.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA"); /* @@ -141,14 +149,18 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 2); assertEquals(sf.getEnd(), 2); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 2.0e-03, DELTA); + 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.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA"); /* @@ -337,7 +349,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 24); assertEquals(sf.getEnd(), 24); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 5.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 5.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,A"); /* @@ -348,7 +362,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 24); assertEquals(sf.getEnd(), 24); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 4.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 4.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "T,G"); /* @@ -359,7 +375,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 22); assertEquals(sf.getEnd(), 22); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 2.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G"); /* @@ -374,7 +392,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 21); assertEquals(sf.getEnd(), 21); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 3.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT"); /* @@ -392,7 +412,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 16); assertEquals(sf.getEnd(), 16); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 3.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GT"); /* @@ -403,7 +425,9 @@ public class VCFLoaderTest assertEquals(sf.getBegin(), 17); assertEquals(sf.getEnd(), 17); assertEquals(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT); - assertEquals(sf.getScore(), 2.0e-03, DELTA); + assertEquals(sf.getScore(), 0f); + assertEquals(Float.parseFloat((String) sf.getValue("AF")), 2.0e-03, + DELTA); assertEquals(sf.getValue(Gff3Helper.ALLELES), "C,G"); /* @@ -463,7 +487,8 @@ 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 Map map = (Map) sf.getValue("CSQ"); @@ -472,7 +497,8 @@ public class VCFLoaderTest 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"); map = (Map) sf.getValue("CSQ"); assertEquals(map.size(), 9); @@ -480,7 +506,8 @@ public class VCFLoaderTest 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"); map = (Map) sf.getValue("CSQ"); assertEquals(map.size(), 9); @@ -488,7 +515,8 @@ public class VCFLoaderTest 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"); map = (Map) sf.getValue("CSQ"); assertEquals(map.size(), 9); @@ -496,7 +524,8 @@ public class VCFLoaderTest 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"); map = (Map) sf.getValue("CSQ"); assertEquals(map.size(), 9); @@ -504,7 +533,8 @@ public class VCFLoaderTest 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"); map = (Map) sf.getValue("CSQ"); assertEquals(map.size(), 9); @@ -512,7 +542,8 @@ public class VCFLoaderTest 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"); map = (Map) sf.getValue("CSQ"); assertEquals(map.size(), 9); @@ -530,7 +561,8 @@ 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 map = (Map) sf.getValue("CSQ"); @@ -540,7 +572,8 @@ public class VCFLoaderTest 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(map.size(), 9); assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3"); @@ -548,7 +581,8 @@ public class VCFLoaderTest 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(map.size(), 9); assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript3"); @@ -595,7 +629,8 @@ 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(map.size(), 9); assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4"); @@ -603,7 +638,8 @@ public class VCFLoaderTest 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(map.size(), 9); assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4"); @@ -611,7 +647,8 @@ public class VCFLoaderTest 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(map.size(), 9); assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4"); @@ -619,7 +656,8 @@ public class VCFLoaderTest 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(map.size(), 9); assertEquals(sf.getValueAsString("CSQ", "Feature"), "transcript4"); -- 1.7.10.2