Fix for Kiran: -1 is a valid value for genotype qualities in VCF, so VariantContext shouldn't die. Cleaned up the relevant VCF code while I was in there.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3015 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
849bd1f451
commit
1fd909cdaf
|
|
@ -193,11 +193,12 @@ public class VariantContextAdaptors {
|
||||||
if ( vcfG.isFiltered() ) // setup the FL genotype filter fields
|
if ( vcfG.isFiltered() ) // setup the FL genotype filter fields
|
||||||
genotypeFilters.addAll(Arrays.asList(vcfG.getFields().get(VCFGenotypeRecord.GENOTYPE_FILTER_KEY).split(";")));
|
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);
|
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);
|
VariantContext vc = new VariantContext(name, vcf.getLocation(), alleles, genotypes, qual, filters, attributes);
|
||||||
vc.validate();
|
vc.validate();
|
||||||
return vc;
|
return vc;
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,20 @@ public class VCFGenotypeRecord {
|
||||||
return mFields;
|
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() {
|
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() {
|
public int getReadCount() {
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public class VCFRecord {
|
||||||
public static final String EMPTY_ID_FIELD = ".";
|
public static final String EMPTY_ID_FIELD = ".";
|
||||||
public static final String EMPTY_ALLELE_FIELD = ".";
|
public static final String EMPTY_ALLELE_FIELD = ".";
|
||||||
public static final String DOUBLE_PRECISION_FORMAT_STRING = "%.2f";
|
public static final String DOUBLE_PRECISION_FORMAT_STRING = "%.2f";
|
||||||
|
public static final int MISSING_GENOTYPE_QUALITY = -1;
|
||||||
|
|
||||||
// the reference base
|
// the reference base
|
||||||
private String mReferenceBases;
|
private String mReferenceBases;
|
||||||
|
|
@ -350,6 +351,10 @@ public class VCFRecord {
|
||||||
return mQual;
|
return mQual;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMissingQual() {
|
||||||
|
return (int)mQual == MISSING_GENOTYPE_QUALITY;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the -log10PError
|
* @return the -log10PError
|
||||||
*/
|
*/
|
||||||
|
|
@ -448,8 +453,8 @@ public class VCFRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQual(double qual) {
|
public void setQual(double qual) {
|
||||||
if ( qual < 0 && MathUtils.compareDoubles(qual, -1.0) != 0 )
|
if ( qual < 0 && (int)qual != MISSING_GENOTYPE_QUALITY )
|
||||||
throw new IllegalArgumentException("Qual values cannot be negative unless they are -1 ('unknown')");
|
throw new IllegalArgumentException("Qual values cannot be negative unless they are " + MISSING_GENOTYPE_QUALITY + " ('unknown')");
|
||||||
mQual = qual;
|
mQual = qual;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -555,8 +560,8 @@ public class VCFRecord {
|
||||||
builder.append(EMPTY_ALLELE_FIELD);
|
builder.append(EMPTY_ALLELE_FIELD);
|
||||||
}
|
}
|
||||||
builder.append(FIELD_SEPERATOR);
|
builder.append(FIELD_SEPERATOR);
|
||||||
if ( MathUtils.compareDoubles(mQual, -1.0) == 0 )
|
if ( (int)mQual == MISSING_GENOTYPE_QUALITY )
|
||||||
builder.append("-1");
|
builder.append(MISSING_GENOTYPE_QUALITY);
|
||||||
else
|
else
|
||||||
builder.append(String.format(DOUBLE_PRECISION_FORMAT_STRING, mQual));
|
builder.append(String.format(DOUBLE_PRECISION_FORMAT_STRING, mQual));
|
||||||
builder.append(FIELD_SEPERATOR);
|
builder.append(FIELD_SEPERATOR);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue