use of htsjdk.variant.variantcontext.GenotypeBuilder in project gatk-protected by broadinstitute.
the class EvaluateCopyNumberTriStateCalls method composeNonTruthOverlappingGenotype.
private Genotype composeNonTruthOverlappingGenotype(final VariantContext enclosingContext, final Genotype genotype) {
final GenotypeBuilder builder = new GenotypeBuilder(genotype.getSampleName());
if (genotype.isCalled()) {
GATKProtectedVariantContextUtils.setGenotypeQualityFromPLs(builder, genotype);
final int[] PL = genotype.getPL();
final int callAlleleIndex = GATKProtectedMathUtils.minIndex(PL);
final double quality = callQuality(genotype);
builder.alleles(Collections.singletonList(enclosingContext.getAlleles().get(callAlleleIndex)));
builder.attribute(VariantEvaluationContext.CALL_QUALITY_KEY, quality);
final boolean discovered = XHMMSegmentGenotyper.DISCOVERY_TRUE.equals(GATKProtectedVariantContextUtils.getAttributeAsString(genotype, XHMMSegmentGenotyper.DISCOVERY_KEY, XHMMSegmentGenotyper.DISCOVERY_FALSE));
if (callAlleleIndex != 0 && discovered) {
builder.attribute(VariantEvaluationContext.EVALUATION_CLASS_KEY, EvaluationClass.UNKNOWN_POSITIVE.acronym);
}
if (quality < filterArguments.minimumCalledSegmentQuality) {
builder.filter(EvaluationFilter.LowQuality.acronym);
} else {
builder.filter(EvaluationFilter.PASS);
}
} else {
/* assume it is REF */
/* TODO this is a hack to make Andrey's CODEX vcf work; and in general, VCFs that only include discovered
* variants and NO_CALL (".") on other samples. The idea is to force the evaluation tool to take it call
* as REF on all other samples. Otherwise, the effective allele frequency of the variant will be erroneously
* high and will be filtered. */
builder.alleles(Collections.singletonList(CopyNumberTriStateAllele.REF));
builder.attribute(VariantEvaluationContext.CALL_QUALITY_KEY, 100000);
builder.filter(EvaluationFilter.PASS);
}
return builder.make();
}
use of htsjdk.variant.variantcontext.GenotypeBuilder in project gatk by broadinstitute.
the class SelectVariants method subsetRecord.
/**
* Helper method to subset a VC record, modifying some metadata stored in the INFO field (i.e. AN, AC, AF).
*
* @param vc the VariantContext record to subset
* @param preserveAlleles should we trim constant sequence from the beginning and/or end of all alleles, or preserve it?
* @param removeUnusedAlternates removes alternate alleles with AC=0
* @return the subsetted VariantContext
*/
private VariantContext subsetRecord(final VariantContext vc, final boolean preserveAlleles, final boolean removeUnusedAlternates) {
//subContextFromSamples() always decodes the vc, which is a fairly expensive operation. Avoid if possible
if (noSamplesSpecified && !removeUnusedAlternates) {
return vc;
}
// strip out the alternate alleles that aren't being used
final VariantContext sub = vc.subContextFromSamples(samples, removeUnusedAlternates);
// If no subsetting happened, exit now
if (sub.getNSamples() == vc.getNSamples() && sub.getNAlleles() == vc.getNAlleles()) {
return vc;
}
// fix the PL and AD values if sub has fewer alleles than original vc and remove a fraction of the genotypes if needed
final GenotypesContext oldGs = sub.getGenotypes();
GenotypesContext newGC = sub.getNAlleles() == vc.getNAlleles() ? oldGs : AlleleSubsettingUtils.subsetAlleles(oldGs, 0, vc.getAlleles(), sub.getAlleles(), GenotypeAssignmentMethod.DO_NOT_ASSIGN_GENOTYPES, vc.getAttributeAsInt(VCFConstants.DEPTH_KEY, 0));
if (fractionGenotypes > 0) {
final List<Genotype> genotypes = newGC.stream().map(genotype -> randomGenotypes.nextDouble() > fractionGenotypes ? genotype : new GenotypeBuilder(genotype).alleles(getNoCallAlleles(genotype.getPloidy())).noGQ().make()).collect(Collectors.toList());
newGC = GenotypesContext.create(new ArrayList<>(genotypes));
}
// since the VC has been subset (either by sample or allele), we need to strip out the MLE tags
final VariantContextBuilder builder = new VariantContextBuilder(sub);
builder.rmAttributes(Arrays.asList(GATKVCFConstants.MLE_ALLELE_COUNT_KEY, GATKVCFConstants.MLE_ALLELE_FREQUENCY_KEY));
builder.genotypes(newGC);
addAnnotations(builder, vc, sub.getSampleNames());
final VariantContext subset = builder.make();
return preserveAlleles ? subset : GATKVariantContextUtils.trimAlleles(subset, true, true);
}
use of htsjdk.variant.variantcontext.GenotypeBuilder in project gatk by broadinstitute.
the class GenotypingEngineUnitTest method testCalculateGenotypes.
// Want to run testCoveredByDeletion first to ensure clean list or recorded deletions
@Test(dependsOnMethods = { "testCoveredByDeletion" })
public void testCalculateGenotypes() {
genotypingEngine.clearUpstreamDeletionsLoc();
// Remove deletion
final List<Genotype> genotypes = Arrays.asList(// first alt
new GenotypeBuilder("sample1").alleles(gtAlleles).PL(new double[] { 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }).make(), // second alt
new GenotypeBuilder("sample2").alleles(gtAlleles).PL(new double[] { 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0 }).make());
final VariantContext vc = new VariantContextBuilder("test", "1", 1, refAllele.length(), allelesDel).genotypes(genotypes).make();
final VariantContext vcOut = genotypingEngine.calculateGenotypes(vc, GenotypeLikelihoodsCalculationModel.INDEL, null);
Assert.assertFalse(vcOut.getAlleles().contains(altT));
// Make sure the spanning deletion is removed since the deletion was removed
final Allele refAlleleSpanDel = Allele.create("C", true);
final List<Allele> vcAllelesSpanDel = new ArrayList<>(Arrays.asList(refAlleleSpanDel, Allele.SPAN_DEL, GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE));
final List<Genotype> genotypesSpanDel = Arrays.asList(// first alt
new GenotypeBuilder("sample1").alleles(gtAlleles).PL(new double[] { 0, 0, 100, 0, 0, 0 }).make(), new GenotypeBuilder("sample2").alleles(gtAlleles).PL(new double[] { 0, 0, 0, 0, 0, 0 }).make());
final VariantContext vcSpanDel = new VariantContextBuilder("test1", "1", 2, 2 + refAlleleSpanDel.length() - 1, vcAllelesSpanDel).genotypes(genotypesSpanDel).make();
final VariantContext vcOut1 = genotypingEngine.calculateGenotypes(vcSpanDel, GenotypeLikelihoodsCalculationModel.INDEL, null);
Assert.assertFalse(vcOut1.getAlleles().contains(Allele.SPAN_DEL));
}
use of htsjdk.variant.variantcontext.GenotypeBuilder in project gatk by broadinstitute.
the class HomRefBlockUnitTest method testAddGQGreaterThanMaxGenotypeQual.
@Test
public void testAddGQGreaterThanMaxGenotypeQual() {
final VariantContext vc = getVariantContext();
final HomRefBlock block90_100 = new HomRefBlock(vc, 90, 100, HomoSapiensConstants.DEFAULT_PLOIDY);
// Test that adding a Genotype with GQ > 99 succeeds (ie., doesn't throw).
// Internally, HomRefBlock should treat this GQ as 99.
block90_100.add(vc.getStart(), new GenotypeBuilder(SAMPLE_NAME, vc.getAlleles()).GQ(150).DP(10).PL(new int[] { 0, 10, 100 }).make());
}
use of htsjdk.variant.variantcontext.GenotypeBuilder in project gatk by broadinstitute.
the class GenotypeConcordanceTest method testGenotypeConcordanceDetermineStateDp.
@Test
public void testGenotypeConcordanceDetermineStateDp() throws Exception {
final List<Allele> allelesNormal = makeUniqueListOfAlleles(Aref, C);
final Genotype gtNormal = GenotypeBuilder.create(TRUTH_SAMPLE_NAME, Arrays.asList(Aref, C));
final VariantContext vcNormal = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, allelesNormal).genotypes(gtNormal).make();
final List<Allele> allelesLowDp = makeUniqueListOfAlleles(Aref, C);
final Genotype gtLowDp = new GenotypeBuilder(TRUTH_SAMPLE_NAME, Arrays.asList(Aref, C)).DP(4).make();
final VariantContext vcLowDp = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, allelesLowDp).genotypes(gtLowDp).make();
testGenotypeConcordanceDetermineState(vcLowDp, TruthState.LOW_DP, vcNormal, CallState.HET_REF_VAR1, 0, 20);
testGenotypeConcordanceDetermineState(vcLowDp, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2);
testGenotypeConcordanceDetermineState(vcNormal, TruthState.HET_REF_VAR1, vcLowDp, CallState.LOW_DP, 0, 20);
testGenotypeConcordanceDetermineState(vcNormal, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2);
testGenotypeConcordanceDetermineState(vcLowDp, TruthState.LOW_DP, vcLowDp, CallState.LOW_DP, 0, 20);
testGenotypeConcordanceDetermineState(vcLowDp, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2);
}
Aggregations