diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/VariantContextAdaptors.java b/java/src/org/broadinstitute/sting/gatk/refdata/VariantContextAdaptors.java index 3cc058e92..a417a6b62 100755 --- a/java/src/org/broadinstitute/sting/gatk/refdata/VariantContextAdaptors.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/VariantContextAdaptors.java @@ -193,11 +193,12 @@ public class VariantContextAdaptors { if ( vcfG.isFiltered() ) // setup the FL genotype filter fields genotypeFilters.addAll(Arrays.asList(vcfG.getFields().get(VCFGenotypeRecord.GENOTYPE_FILTER_KEY).split(";"))); - Genotype g = new Genotype(vcfG.getSampleName(), genotypeAlleles, vcfG.getNegLog10PError(), genotypeFilters, fields, vcfG.getPhaseType() == VCFGenotypeRecord.PHASE.PHASED); + double qual = vcfG.isMissingQual() ? VariantContext.NO_NEG_LOG_10PERROR : vcfG.getNegLog10PError(); + Genotype g = new Genotype(vcfG.getSampleName(), genotypeAlleles, qual, genotypeFilters, fields, vcfG.getPhaseType() == VCFGenotypeRecord.PHASE.PHASED); genotypes.put(g.getSampleName(), g); } - double qual = vcf.getQual() == -1 ? VariantContext.NO_NEG_LOG_10PERROR : vcf.getNegLog10PError(); + double qual = vcf.isMissingQual() ? VariantContext.NO_NEG_LOG_10PERROR : vcf.getNegLog10PError(); VariantContext vc = new VariantContext(name, vcf.getLocation(), alleles, genotypes, qual, filters, attributes); vc.validate(); return vc; diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeRecord.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeRecord.java index 2a9050f4d..d9ad01a0f 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeRecord.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFGenotypeRecord.java @@ -127,8 +127,20 @@ public class VCFGenotypeRecord { return mFields; } + /** + * @return the phred-scaled quality score + */ + public double getQual() { + return ( mFields.containsKey(GENOTYPE_QUALITY_KEY) ? Double.valueOf(mFields.get(GENOTYPE_QUALITY_KEY)) : MISSING_GENOTYPE_QUALITY); + } + + public boolean isMissingQual() { + return (int)getQual() == MISSING_GENOTYPE_QUALITY; + } + public double getNegLog10PError() { - return ( mFields.containsKey(GENOTYPE_QUALITY_KEY) ? Double.valueOf(mFields.get(GENOTYPE_QUALITY_KEY)) / 10.0 : MISSING_GENOTYPE_QUALITY); + double qual = getQual(); + return (qual == MISSING_GENOTYPE_QUALITY ? MISSING_GENOTYPE_QUALITY : qual / 10.0); } public int getReadCount() { diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFRecord.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFRecord.java index e71202cd3..11c24847e 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFRecord.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFRecord.java @@ -39,6 +39,7 @@ public class VCFRecord { public static final String EMPTY_ID_FIELD = "."; public static final String EMPTY_ALLELE_FIELD = "."; public static final String DOUBLE_PRECISION_FORMAT_STRING = "%.2f"; + public static final int MISSING_GENOTYPE_QUALITY = -1; // the reference base private String mReferenceBases; @@ -350,6 +351,10 @@ public class VCFRecord { return mQual; } + public boolean isMissingQual() { + return (int)mQual == MISSING_GENOTYPE_QUALITY; + } + /** * @return the -log10PError */ @@ -448,8 +453,8 @@ public class VCFRecord { } public void setQual(double qual) { - if ( qual < 0 && MathUtils.compareDoubles(qual, -1.0) != 0 ) - throw new IllegalArgumentException("Qual values cannot be negative unless they are -1 ('unknown')"); + if ( qual < 0 && (int)qual != MISSING_GENOTYPE_QUALITY ) + throw new IllegalArgumentException("Qual values cannot be negative unless they are " + MISSING_GENOTYPE_QUALITY + " ('unknown')"); mQual = qual; } @@ -555,8 +560,8 @@ public class VCFRecord { builder.append(EMPTY_ALLELE_FIELD); } builder.append(FIELD_SEPERATOR); - if ( MathUtils.compareDoubles(mQual, -1.0) == 0 ) - builder.append("-1"); + if ( (int)mQual == MISSING_GENOTYPE_QUALITY ) + builder.append(MISSING_GENOTYPE_QUALITY); else builder.append(String.format(DOUBLE_PRECISION_FORMAT_STRING, mQual)); builder.append(FIELD_SEPERATOR);