Java Code Examples for htsjdk.variant.variantcontext.VariantContext#getAttributeAsDouble()

The following examples show how to use htsjdk.variant.variantcontext.VariantContext#getAttributeAsDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnrichedStructuralVariantFactory.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
private static Double junctionCopyNumber(@NotNull final VariantContext startContext) {
    if (startContext.hasAttribute(StructuralVariantHeader.PURPLE_JUNCTION_COPY_NUMBER_INFO)) {
        return startContext.getAttributeAsDouble(StructuralVariantHeader.PURPLE_JUNCTION_COPY_NUMBER_INFO, 0);
    }

    if (startContext.hasAttribute(StructuralVariantHeader.PURPLE_PLOIDY_INFO)) {
        return startContext.getAttributeAsDouble(StructuralVariantHeader.PURPLE_PLOIDY_INFO, 0);
    }

    return null;
}
 
Example 2
Source File: CNNScoreVariantsIntegrationTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void assertInfoFieldsAreClose(File actualVcf, File expectedVcf, String infoKey){
    Iterator<VariantContext> expectedVi = VariantContextTestUtils.streamVcf(expectedVcf).collect(Collectors.toList()).iterator();
    Iterator<VariantContext> actualVi = VariantContextTestUtils.streamVcf(actualVcf).collect(Collectors.toList()).iterator();
    while (expectedVi.hasNext() && actualVi.hasNext()) {
        VariantContext expectedVc = expectedVi.next();
        VariantContext actualVc = actualVi.next();
        double expectedScore = expectedVc.getAttributeAsDouble(infoKey, 0.0); // Different defaults trigger failures on missing scores
        double actualScore = actualVc.getAttributeAsDouble(infoKey, EPSILON+1.0);
        double diff = Math.abs(expectedScore-actualScore);
        Assert.assertTrue(diff < EPSILON);
        VariantContextTestUtils.assertVariantContextsAreEqual(actualVc, expectedVc, Collections.singletonList(infoKey), Collections.emptyList());
    }
    Assert.assertTrue(!expectedVi.hasNext() && !actualVi.hasNext());
}
 
Example 3
Source File: VariantAFEvaluator.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void update1(VariantContext vc, final ReferenceContext referenceContext, final ReadsContext readsContext, final FeatureContext featureContext) {
    vc.getStart();

    if (vc == null || !vc.isSNP() || (getWalker().ignoreAC0Sites() && vc.isMonomorphicInSamples())) {
        return;
    }

    for (final Genotype genotype : vc.getGenotypes()) {
         // eval array
        if (!genotype.isNoCall()) {
            if (genotype.getPloidy() != PLOIDY) {

                throw new UserException.BadInput("This tool only works with ploidy 2");
            }
            // add AF at this site
            this.totalCalledSites += 1;
            int numReferenceAlleles= genotype.countAllele(vc.getReference());
            double varAFHere = (PLOIDY - numReferenceAlleles)/PLOIDY;
            this.sumVariantAFs += varAFHere;

            totalHetSites += numReferenceAlleles == 1 ? 1 : 0;
            totalHomVarSites += numReferenceAlleles == 0 ? 1 : 0;
            totalHomRefSites += numReferenceAlleles == 2 ? 1 : 0;

        }
    }

    if (!vc.hasGenotypes()) {
        // comp  ( sites only thousand genomes )
        this.totalCalledSites += 1;
        this.sumVariantAFs += vc.getAttributeAsDouble("AF", 0.0);
    }
}
 
Example 4
Source File: PileupSummary.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PileupSummary(final VariantContext vc, final ReadPileup pileup) {
    contig = vc.getContig();
    position = vc.getStart();
    alleleFrequency = vc.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, 0);
    final byte altBase = vc.getAlternateAllele(0).getBases()[0];
    final byte refBase = vc.getReference().getBases()[0];
    final int[] baseCounts = pileup.getBaseCounts();
    altCount = baseCounts[BaseUtils.simpleBaseToBaseIndex(altBase)];
    refCount = baseCounts[BaseUtils.simpleBaseToBaseIndex(refBase)];
    totalCount = (int) MathUtils.sum(baseCounts);
    otherAltsCount = totalCount - altCount - refCount;
}
 
Example 5
Source File: GetPileupSummaries.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean alleleFrequencyInRange(final VariantContext vc) {
    if (!vc.hasAttribute(VCFConstants.ALLELE_FREQUENCY_KEY)) {
        if (!sawVariantsWithoutAlleleFrequency) {
            logger.warn(String.format("Variant context at %s:%d lacks allele frequency (AF) field.", vc.getContig(), vc.getStart()));
            sawVariantsWithoutAlleleFrequency = true;
        }
        return false;
    } else {
        sawVariantsWithAlleleFrequency = true;
        final double alleleFrequency = vc.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, -1.0);
        return minPopulationAlleleFrequency < alleleFrequency && alleleFrequency < maxPopulationAlleleFrequency;
    }
}
 
Example 6
Source File: LiftoverVcfTest.java    From picard with MIT License 5 votes vote down vote up
@Test
public void testChangingInfoFields() {
    final String filename = "testLiftoverFailingVariants.vcf";
    final File liftOutputFile = new File(OUTPUT_DATA_PATH, "lift-delete-me.vcf");
    final File rejectOutputFile = new File(OUTPUT_DATA_PATH, "reject-delete-me.vcf");
    final File input = new File(TEST_DATA_PATH, filename);

    liftOutputFile.deleteOnExit();
    rejectOutputFile.deleteOnExit();

    final String[] args = new String[]{
            "INPUT=" + input.getAbsolutePath(),
            "OUTPUT=" + liftOutputFile.getAbsolutePath(),
            "REJECT=" + rejectOutputFile.getAbsolutePath(),
            "CHAIN=" + CHAIN_FILE,
            "REFERENCE_SEQUENCE=" + REFERENCE_FILE,
            "RECOVER_SWAPPED_REF_ALT=true",
            "CREATE_INDEX=false"
    };
    Assert.assertEquals(runPicardCommandLine(args), 0);

    final VCFFileReader liftReader = new VCFFileReader(liftOutputFile, false);
    for (final VariantContext vc : liftReader) {
        Assert.assertTrue(vc.hasAttribute("AF"));

        Assert.assertEquals(vc.hasAttribute(LiftoverUtils.SWAPPED_ALLELES), vc.hasAttribute("FLIPPED_AF"), vc.toString());
        Assert.assertEquals(!vc.hasAttribute(LiftoverUtils.SWAPPED_ALLELES), vc.hasAttribute("MAX_AF") && vc.getAttribute("MAX_AF") != null, vc.toString());

        if (vc.hasAttribute(LiftoverUtils.SWAPPED_ALLELES)) {
            final double af = vc.getAttributeAsDouble("AF", -1.0);
            final double flippedAf = vc.getAttributeAsDouble("FLIPPED_AF", -2.0);

            Assert.assertTrue(TestNGUtil.compareDoubleWithAccuracy(af, flippedAf, 0.01),
                    "Error while comparing AF. expected " + flippedAf + " but found " + af);
        }
    }
}
 
Example 7
Source File: QdFilter.java    From picard with MIT License 5 votes vote down vote up
@Override public String filter(final VariantContext ctx) {
    final double qd = ctx.getAttributeAsDouble("QD", -1d); // If QD is missing, return -1

    // QD should always be positive so a value < 0 indicates a missing value
    if (qd >= 0 && qd < minimumQd) {
        return FILTER_NAME;
    }
    else {
        return null;
    }
}
 
Example 8
Source File: PileupSummary.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PileupSummary(final VariantContext vc, final ReadPileup pileup) {
    contig = vc.getContig();
    position = vc.getStart();
    alleleFrequency = vc.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, 0);
    final byte altBase = vc.getAlternateAllele(0).getBases()[0];
    final byte refBase = vc.getReference().getBases()[0];
    final int[] baseCounts = pileup.getBaseCounts();
    altCount = baseCounts[BaseUtils.simpleBaseToBaseIndex(altBase)];
    refCount = baseCounts[BaseUtils.simpleBaseToBaseIndex(refBase)];
    totalCount = (int) MathUtils.sum(baseCounts);
    otherAltsCount = totalCount - altCount - refCount;
}
 
Example 9
Source File: GetPileupSummaries.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean alleleFrequencyInRange(final VariantContext vc) {
    if (!vc.hasAttribute(VCFConstants.ALLELE_FREQUENCY_KEY)) {
        return false;
    } else {
        final double alleleFrequency = vc.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, -1.0);
        return minPopulationAlleleFrequency < alleleFrequency && alleleFrequency < maxPopulationAlleleFrequency;
    }
}
 
Example 10
Source File: SubclonalLikelihoodEnrichment.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void accept(@NotNull final VariantContext context) {
    final double variantCopyNumber = context.getAttributeAsDouble(SomaticVariantHeader.PURPLE_VARIANT_CN_INFO, maxPloidy);
    double subclonalLikelihood = Math.round(likelihoodFactory.subclonalLikelihood(variantCopyNumber) * 1000d) / 1000d;

    if (!Doubles.isZero(subclonalLikelihood)) {
        context.getCommonInfo().putAttribute(SUBCLONAL_LIKELIHOOD_FLAG, subclonalLikelihood);
    }
    consumer.accept(context);
}
 
Example 11
Source File: FisherStrandFilter.java    From picard with MIT License 4 votes vote down vote up
@Override
public String filter(final VariantContext ctx) {
    final double fs = ctx.getAttributeAsDouble("FS", 0);
    return (fs > maxPhredScalePValue) ? "StrandBias" : null;
}
 
Example 12
Source File: HaplotypeMap.java    From picard with MIT License 4 votes vote down vote up
/**
 * Constructs a HaplotypeMap from the provided file.
 */

private void fromVcf(final File file) {
    try ( final VCFFileReader reader = new VCFFileReader(file, false)) {

        final SAMSequenceDictionary dict = reader.getFileHeader().getSequenceDictionary();

        if (dict == null || dict.getSequences().isEmpty()) {
            throw new IllegalStateException("Haplotype map VCF file must contain header: " + file.getAbsolutePath());
        }

        initialize(new SAMFileHeader(dict));

        final Map<String, HaplotypeBlock> anchorToHaplotype = new HashMap<>();

        for (final VariantContext vc : reader) {

            if (vc.getNSamples() > 1) {
                throw new IllegalStateException("Haplotype map VCF file must contain at most one sample: " + file.getAbsolutePath());
            }

            final Genotype gc = vc.getGenotype(0); // may be null
            final boolean hasGc = gc != null;

            if (vc.getAlternateAlleles().size() != 1) {
                throw new IllegalStateException("Haplotype map VCF file must contain exactly one alternate allele per site: " + vc.toString());
            }

            if (!vc.isSNP()) {
                throw new IllegalStateException("Haplotype map VCF file must contain only SNPs: " + vc.toString());
            }

            if (!vc.hasAttribute(VCFConstants.ALLELE_FREQUENCY_KEY)) {
                throw new IllegalStateException("Haplotype map VCF Variants must have an '"+ VCFConstants.ALLELE_FREQUENCY_KEY + "' INFO field: " + vc.toString());
            }


            if (hasGc && gc.isPhased() && !gc.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) {
                throw new IllegalStateException("Haplotype map VCF Variants' genotypes that are phased must have a PhaseSet (" + VCFConstants.PHASE_SET_KEY+")" + vc.toString());
            }

            if (hasGc && gc.isPhased() && !gc.isHet()) {
                throw new IllegalStateException("Haplotype map VCF Variants' genotypes that are phased must be HET" + vc.toString());
            }

            // Then parse them out
            final String chrom = vc.getContig();
            final int pos = vc.getStart();
            final String name = vc.getID();

            final byte ref = vc.getReference().getBases()[0];
            final byte var = vc.getAlternateAllele(0).getBases()[0];

            final double temp_maf = vc.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, 0D);
            final boolean swapped = hasGc && !gc.getAllele(0).equals(vc.getReference());

            final byte major, minor;
            final double maf;

            if (swapped) {
                major = var;
                minor = ref;
                maf = 1 - temp_maf;
            } else {
                major = ref;
                minor = var;
                maf = temp_maf;
            }

            final String anchor = anchorFromVc(vc);

            // If it's the anchor snp, start the haplotype
            if (!anchorToHaplotype.containsKey(anchor)) {
                final HaplotypeBlock newBlock = new HaplotypeBlock(maf);
                anchorToHaplotype.put(anchor, newBlock);
            }
            final HaplotypeBlock block = anchorToHaplotype.get(anchor);
            block.addSnp(new Snp(name, chrom, pos, major, minor, maf, null));
        }

        // And add them all now that they are all ready.
        fromHaplotypes(anchorToHaplotype.values());
    }
}
 
Example 13
Source File: LiftoverUtils.java    From picard with MIT License 4 votes vote down vote up
/**
 * method to swap the reference and alt alleles of a bi-allelic, SNP
 *
 * @param vc                   the {@link VariantContext} (bi-allelic SNP) that needs to have it's REF and ALT alleles swapped.
 * @param annotationsToReverse INFO field annotations (of double value) that will be reversed (x->1-x)
 * @param annotationsToDrop    INFO field annotations that will be dropped from the result since they are invalid when REF and ALT are swapped
 * @return a new {@link VariantContext} with alleles swapped, INFO fields modified and in the genotypes, GT, AD and PL corrected appropriately
 */
public static VariantContext swapRefAlt(final VariantContext vc, final Collection<String> annotationsToReverse, final Collection<String> annotationsToDrop) {

    if (!vc.isBiallelic() || !vc.isSNP()) {
        throw new IllegalArgumentException("swapRefAlt can only process biallelic, SNPS, found " + vc.toString());
    }

    final VariantContextBuilder swappedBuilder = new VariantContextBuilder(vc);

    swappedBuilder.attribute(SWAPPED_ALLELES, true);

    // Use getBaseString() (rather than the Allele itself) in order to create new Alleles with swapped
    // reference and non-variant attributes
    swappedBuilder.alleles(Arrays.asList(vc.getAlleles().get(1).getBaseString(), vc.getAlleles().get(0).getBaseString()));

    final Map<Allele, Allele> alleleMap = new HashMap<>();

    // A mapping from the old allele to the new allele, to be used when fixing the genotypes
    alleleMap.put(vc.getAlleles().get(0), swappedBuilder.getAlleles().get(1));
    alleleMap.put(vc.getAlleles().get(1), swappedBuilder.getAlleles().get(0));

    final GenotypesContext swappedGenotypes = GenotypesContext.create(vc.getGenotypes().size());
    for (final Genotype genotype : vc.getGenotypes()) {
        final List<Allele> swappedAlleles = new ArrayList<>();
        for (final Allele allele : genotype.getAlleles()) {
            if (allele.isNoCall()) {
                swappedAlleles.add(allele);
            } else {
                swappedAlleles.add(alleleMap.get(allele));
            }
        }
        // Flip AD
        final GenotypeBuilder builder = new GenotypeBuilder(genotype).alleles(swappedAlleles);
        if (genotype.hasAD() && genotype.getAD().length == 2) {
            final int[] ad = ArrayUtils.clone(genotype.getAD());
            ArrayUtils.reverse(ad);
            builder.AD(ad);
        } else {
            builder.noAD();
        }

        //Flip PL
        if (genotype.hasPL() && genotype.getPL().length == 3) {
            final int[] pl = ArrayUtils.clone(genotype.getPL());
            ArrayUtils.reverse(pl);
            builder.PL(pl);
        } else {
            builder.noPL();
        }
        swappedGenotypes.add(builder.make());
    }
    swappedBuilder.genotypes(swappedGenotypes);

    for (final String key : vc.getAttributes().keySet()) {
        if (annotationsToDrop.contains(key)) {
            swappedBuilder.rmAttribute(key);
        } else if (annotationsToReverse.contains(key) && !vc.getAttributeAsString(key, "").equals(VCFConstants.MISSING_VALUE_v4)) {
            final double attributeToReverse = vc.getAttributeAsDouble(key, -1);

            if (attributeToReverse < 0 || attributeToReverse > 1) {
                log.warn("Trying to reverse attribute " + key +
                        " but found value that isn't between 0 and 1: (" + attributeToReverse + ") in variant " + vc + ". Results might be wrong.");
            }
            swappedBuilder.attribute(key, 1 - attributeToReverse);
        }
    }

    return swappedBuilder.make();
}
 
Example 14
Source File: ApplyVQSR.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Calculate the allele-specific filter status of vc
 * @param vc
 * @param recals
 * @param builder   is modified by adding attributes
 * @return a String with the filter status for this site
 */
private String doAlleleSpecificFiltering(final VariantContext vc, final List<VariantContext> recals, final VariantContextBuilder builder) {
    double bestLod = VariantRecalibratorEngine.MIN_ACCEPTABLE_LOD_SCORE;
    final List<String> culpritStrings = new ArrayList<>();
    final List<String> lodStrings = new ArrayList<>();
    final List<String> AS_filterStrings = new ArrayList<>();

    String[] prevCulpritList = null;
    String[] prevLodList = null;
    String[] prevASfiltersList = null;

    //get VQSR annotations from previous run of ApplyRecalibration, if applicable
    if(foundINDELTranches || foundSNPTranches) {
        final String prevCulprits = vc.getAttributeAsString(GATKVCFConstants.AS_CULPRIT_KEY,"");
        prevCulpritList = prevCulprits.isEmpty()? new String[0] : prevCulprits.split(listPrintSeparator);
        final String prevLodString = vc.getAttributeAsString(GATKVCFConstants.AS_VQS_LOD_KEY,"");
        prevLodList = prevLodString.isEmpty()? new String[0] : prevLodString.split(listPrintSeparator);
        final String prevASfilters = vc.getAttributeAsString(GATKVCFConstants.AS_FILTER_STATUS_KEY,"");
        prevASfiltersList = prevASfilters.isEmpty()? new String[0] : prevASfilters.split(listPrintSeparator);
    }

    //for each allele in the current VariantContext
    for (int altIndex = 0; altIndex < vc.getNAlleles()-1; altIndex++) {
        final Allele allele = vc.getAlternateAllele(altIndex);

        //if the current allele is not part of this recalibration mode, add its annotations to the list and go to the next allele
        if (!VariantDataManager.checkVariationClass(vc, allele, MODE)) {
            updateAnnotationsWithoutRecalibrating(altIndex, prevCulpritList, prevLodList, prevASfiltersList, culpritStrings, lodStrings, AS_filterStrings);
            continue;
        }

        //if the current allele does need to have recalibration applied...

        //initialize allele-specific VQSR annotation data with values for spanning deletion
        String alleleLodString = emptyFloatValue;
        String alleleFilterString = emptyStringValue;
        String alleleCulpritString = emptyStringValue;

        //if it's not a spanning deletion, replace those allele strings with the real values
        if (!GATKVCFConstants.isSpanningDeletion(allele)) {
            VariantContext recalDatum = getMatchingRecalVC(vc, recals, allele);
            if (recalDatum == null) {
                throw new UserException("Encountered input allele which isn't found in the input recal file. Please make sure VariantRecalibrator and ApplyRecalibration were run on the same set of input variants with flag -AS. First seen at: " + vc);
            }

            //compare VQSLODs for all alleles in the current mode for filtering later
            final double lod = recalDatum.getAttributeAsDouble(GATKVCFConstants.VQS_LOD_KEY, VariantRecalibratorEngine.MIN_ACCEPTABLE_LOD_SCORE);
            if (lod > bestLod)
                bestLod = lod;

            alleleLodString = String.format("%.4f", lod);
            alleleFilterString = generateFilterString(lod);
            alleleCulpritString = recalDatum.getAttributeAsString(GATKVCFConstants.CULPRIT_KEY, ".");

            if(recalDatum != null) {
                if (recalDatum.hasAttribute(GATKVCFConstants.POSITIVE_LABEL_KEY))
                    builder.attribute(GATKVCFConstants.POSITIVE_LABEL_KEY, true);
                if (recalDatum.hasAttribute(GATKVCFConstants.NEGATIVE_LABEL_KEY))
                    builder.attribute(GATKVCFConstants.NEGATIVE_LABEL_KEY, true);
            }
        }

        //append per-allele VQSR annotations
        lodStrings.add(alleleLodString);
        AS_filterStrings.add(alleleFilterString);
        culpritStrings.add(alleleCulpritString);
    }

    // Annotate the new record with its VQSLOD, AS_FilterStatus, and the worst performing annotation
    if(!AS_filterStrings.isEmpty() )
        builder.attribute(GATKVCFConstants.AS_FILTER_STATUS_KEY, AnnotationUtils.encodeStringList(AS_filterStrings));
    if(!lodStrings.isEmpty())
        builder.attribute(GATKVCFConstants.AS_VQS_LOD_KEY, AnnotationUtils.encodeStringList(lodStrings));
    if(!culpritStrings.isEmpty())
        builder.attribute(GATKVCFConstants.AS_CULPRIT_KEY, AnnotationUtils.encodeStringList(culpritStrings));

    return generateFilterStringFromAlleles(vc, bestLod);
}
 
Example 15
Source File: VariantDataManager.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static double decodeAnnotation( final String annotationKey, final VariantContext vc, final boolean jitter, final VariantRecalibratorArgumentCollection vrac, final VariantDatum datum ) {
    double value;

    final double LOG_OF_TWO = 0.6931472;

    try {
        //if we're in allele-specific mode and an allele-specific annotation has been requested, parse the appropriate value from the list
        if(vrac.useASannotations && annotationKey.startsWith(GATKVCFConstants.ALLELE_SPECIFIC_PREFIX)) {
            final List<Object> valueList = vc.getAttributeAsList(annotationKey);
            //FIXME: we need to look at the ref allele here too
            if (vc.hasAllele(datum.alternateAllele)) {
                final int altIndex = vc.getAlleleIndex(datum.alternateAllele)-1; //-1 is to convert the index from all alleles (including reference) to just alternate alleles
                value = Double.parseDouble((String)valueList.get(altIndex));
            }
            //if somehow our alleles got mixed up
            else
                throw new IllegalStateException("VariantDatum allele " + datum.alternateAllele + " is not contained in the input VariantContext.");
        }
        else
            value = vc.getAttributeAsDouble( annotationKey, Double.NaN );
        if( Double.isInfinite(value) ) { value = Double.NaN; }
        if( jitter && annotationKey.equalsIgnoreCase(GATKVCFConstants.HAPLOTYPE_SCORE_KEY) && MathUtils.compareDoubles(value, 0.0, PRECISION) == 0 ) { value += 0.01 * Utils.getRandomGenerator().nextGaussian(); }
        if( jitter && (annotationKey.equalsIgnoreCase(GATKVCFConstants.FISHER_STRAND_KEY) || annotationKey.equalsIgnoreCase(GATKVCFConstants.AS_FILTER_STATUS_KEY)) && MathUtils.compareDoubles(value, 0.0, PRECISION) == 0 ) { value += 0.01 * Utils.getRandomGenerator().nextGaussian(); }
        if( jitter && annotationKey.equalsIgnoreCase(GATKVCFConstants.INBREEDING_COEFFICIENT_KEY) && MathUtils.compareDoubles(value, 0.0, PRECISION) == 0 ) { value += 0.01 * Utils.getRandomGenerator().nextGaussian(); }
        if( jitter && (annotationKey.equalsIgnoreCase(GATKVCFConstants.STRAND_ODDS_RATIO_KEY) || annotationKey.equalsIgnoreCase(GATKVCFConstants.AS_STRAND_ODDS_RATIO_KEY)) && MathUtils.compareDoubles(value, LOG_OF_TWO, PRECISION) == 0 ) { value += 0.01 * Utils.getRandomGenerator().nextGaussian(); }   //min SOR is 2.0, then we take ln
        if( jitter && (annotationKey.equalsIgnoreCase(VCFConstants.RMS_MAPPING_QUALITY_KEY))) {
            if( vrac.MQ_CAP > 0) {
                value = logitTransform(value, -SAFETY_OFFSET, vrac.MQ_CAP + SAFETY_OFFSET);
                if (MathUtils.compareDoubles(value, logitTransform(vrac.MQ_CAP, -SAFETY_OFFSET, vrac.MQ_CAP + SAFETY_OFFSET), PRECISION) == 0 ) {
                    value += vrac.MQ_JITTER * Utils.getRandomGenerator().nextGaussian();
                }
            } else if( MathUtils.compareDoubles(value, vrac.MQ_CAP, PRECISION) == 0 ) {
                value += vrac.MQ_JITTER * Utils.getRandomGenerator().nextGaussian();
            }
        }
        if( jitter && (annotationKey.equalsIgnoreCase(GATKVCFConstants.AS_RMS_MAPPING_QUALITY_KEY))){
            value += vrac.MQ_JITTER * Utils.getRandomGenerator().nextGaussian();
        }
    } catch( NumberFormatException e ) {
        value = Double.NaN; // VQSR works with missing data by marginalizing over the missing dimension when evaluating the Gaussian mixture model
    }

    return value;
}
 
Example 16
Source File: SomaticVariantFactory.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
private static double variantCopyNumber(@NotNull final VariantContext context) {
    return context.getAttributeAsDouble(PURPLE_VARIANT_CN_INFO, context.getAttributeAsDouble(PURPLE_VARIANT_PLOIDY_INFO, 0));
}
 
Example 17
Source File: SomaticVariantFactory.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
private static double minorAlleleCopyNumber(@NotNull final VariantContext context) {
    return context.getAttributeAsDouble(PURPLE_MINOR_ALLELE_CN_INFO, context.getAttributeAsDouble(PURPLE_MINOR_ALLELE_PLOIDY_INFO, 0));
}