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

The following examples show how to use htsjdk.variant.variantcontext.VariantContext#getType() . 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: SelectVariants.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Initialize cache of allele anyploid indices
 *
 * Initialize the cache of PL index to a list of alleles for each ploidy.
 *
 * @param vc    Variant Context
 */
private void initalizeAlleleAnyploidIndicesCache(final VariantContext vc) {
    if (vc.getType() != VariantContext.Type.NO_VARIATION) { // Bypass if not a variant
        for (final Genotype g : vc.getGenotypes()) {
            // Make a new entry if the we have not yet cached a PL to allele indices map for this ploidy and allele count
            // skip if there are no PLs -- this avoids hanging on high-allelic somatic samples, for example, where
            // there's no need for the PL indices since they don't exist
            if (g.getPloidy() != 0 && (!ploidyToNumberOfAlleles.containsKey(g.getPloidy()) || ploidyToNumberOfAlleles.get(g.getPloidy()) < vc.getNAlleles())) {
                if (vc.getGenotypes().stream().anyMatch(Genotype::hasLikelihoods)) {
                    GenotypeLikelihoods.initializeAnyploidPLIndexToAlleleIndices(vc.getNAlleles() - 1, g.getPloidy());
                    ploidyToNumberOfAlleles.put(g.getPloidy(), vc.getNAlleles());
                }
            }
        }
    }

}
 
Example 2
Source File: VariantEval.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private EvalCompMatchType doEvalAndCompMatch(final VariantContext eval, final VariantContext comp, boolean requireStrictAlleleMatch) {
    if ( comp.getType() == VariantContext.Type.NO_VARIATION || eval.getType() == VariantContext.Type.NO_VARIATION )
        // if either of these are NO_VARIATION they are LENIENT matches
        return EvalCompMatchType.LENIENT;

    if ( comp.getType() != eval.getType() )
        return EvalCompMatchType.NO_MATCH;

    // find the comp which matches both the reference allele and alternate allele from eval
    final Allele altEval = eval.getAlternateAlleles().size() == 0 ? null : eval.getAlternateAllele(0);
    final Allele altComp = comp.getAlternateAlleles().size() == 0 ? null : comp.getAlternateAllele(0);
    if ((altEval == null && altComp == null) || (altEval != null && altEval.equals(altComp) && eval.getReference().equals(comp.getReference())))
        return EvalCompMatchType.STRICT;
    else
        return requireStrictAlleleMatch ? EvalCompMatchType.NO_MATCH : EvalCompMatchType.LENIENT;
}
 
Example 3
Source File: VariantSummary.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Type getType(VariantContext vc) {
    switch (vc.getType()) {
        case SNP:
            return Type.SNP;
        case INDEL:
            for ( int l : vc.getIndelLengths() )
                if ( Math.abs(l) > MAX_INDEL_LENGTH )
                    return Type.CNV;
            return Type.INDEL;
        case SYMBOLIC:
            return Type.CNV;
        default:
            //throw new UserException.BadInput("Unexpected variant context type: " + vc);
            return null;
    }
}
 
Example 4
Source File: SomaticVariantFactory.java    From hmftools with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
private static VariantType type(@NotNull VariantContext context) {
    switch (context.getType()) {
        case MNP:
            return VariantType.MNP;
        case SNP:
            return VariantType.SNP;
        case INDEL:
            return VariantType.INDEL;
    }
    return VariantType.UNDEFINED;
}
 
Example 5
Source File: VariantDataManager.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected static boolean checkVariationClass( final VariantContext evalVC, final VariantContext trainVC ) {
    switch( trainVC.getType() ) {
        case SNP:
        case MNP:
            return checkVariationClass( evalVC, VariantRecalibratorArgumentCollection.Mode.SNP );
        case INDEL:
        case MIXED:
        case SYMBOLIC:
            return checkVariationClass( evalVC, VariantRecalibratorArgumentCollection.Mode.INDEL );
        default:
            return false;
    }
}
 
Example 6
Source File: Novelty.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public List<Object> getRelevantStates(ReferenceContext referenceContext, ReadsContext readsContext, FeatureContext featureContext, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName, String FamilyName) {
    if (eval != null) {
        //NOTE: this is limiting to matching start position, comparable to GATK3.  Unsure if we shoud carry behavior that forward
        final Collection<VariantContext> knownComps = featureContext.getValues(knowns, eval.getStart());
        for ( final VariantContext c : knownComps ) {
            // loop over sites, looking for something that matches the type eval
            if ( eval.getType() == c.getType() || eval.getType() == VariantContext.Type.NO_VARIATION ) {
                return KNOWN_STATES;
            }
        }
    } 
    
    return NOVEL_STATES;
}
 
Example 7
Source File: MultiallelicSummary.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void update2(VariantContext eval, VariantContext comp, final ReferenceContext referenceContext, final ReadsContext readsContext, final FeatureContext featureContext) {
    if ( eval == null || (getWalker().ignoreAC0Sites() && eval.isMonomorphicInSamples()) )
        return;

    // update counts
    switch ( eval.getType() ) {
        case SNP:
            nSNPs++;
            if ( !eval.isBiallelic() ) {
                nMultiSNPs++;
                calculatePairwiseTiTv(eval);
                calculateSNPPairwiseNovelty(eval, comp);
            }
            break;
        case INDEL:
            nIndels++;
            if ( !eval.isBiallelic() ) {
                nMultiIndels++;
                calculateIndelPairwiseNovelty(eval, comp);
            }
            break;
        default:
            //throw new UserException.BadInput("Unexpected variant context type: " + eval);
            break;
    }

    return;
}
 
Example 8
Source File: SageHotspotAnnotation.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
@NotNull
private static String simpleString(@NotNull final VariantContext context) {
    return "[" + context.getContig() + ":" + context.getStart() + " Type:" + context.getType() + " Alleles:" + ParsingUtils.sortList(
            context.getAlleles()) + "]";
}
 
Example 9
Source File: ReferenceConfidenceModelUnitTest.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void checkReferenceModelResult(final RefConfData data, final List<VariantContext> contexts, final List<Integer> expectedDPs, final List<VariantContext> calls) {
    Assert.assertNotNull(contexts);

    final SimpleInterval loc = data.getActiveRegion().getExtendedSpan();
    final List<Boolean> seenBP = new ArrayList<>(Collections.nCopies(data.getActiveRegion().getSpan().size(), false));

    for ( int i = 0; i < loc.size(); i++ ) {
        final GenomeLoc curPos = parser.createGenomeLoc(loc.getContig(), loc.getStart() + i);
        final VariantContext call = model.getOverlappingVariantContext(curPos, calls);
        final VariantContext refModel = model.getOverlappingVariantContext(curPos, contexts);

        if ( ! data.getActiveRegion().getSpan().contains(curPos) ) {
            // part of the extended interval, but not the full interval
            Assert.assertNull(refModel);
            continue;
        }

        if ( call != null ) {
            if (call.isVariant() && refModel.getType() ==  VariantContext.Type.SYMBOLIC ) {
                //Assert.assertEquals(refModel, call, "Should have found call " + call + " but found " + refModel + " instead");
                Assert.assertTrue(call.getReference().length() > 1); // must be a deletion.
                Assert.assertTrue(call.getStart() < refModel.getStart()); // the deletion must not start at the same position
                Assert.assertEquals(call.getReference().getBaseString().substring(refModel.getStart() - call.getStart(),
                            refModel.getStart() - call.getStart() + 1), refModel.getReference().getBaseString(), "" + data.getRefHap()); // the reference must be the same.
                Assert.assertTrue(refModel.getGenotype(0).getGQ() <= 0); // No confidence in the reference hom-ref call across the deletion
                Assert.assertEquals(refModel.getAlleles().size(),2); // the reference and the lonelly <NON_REF>
                Assert.assertEquals(refModel.getAlleles().get(1), GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE);
            } else {
                Assert.assertEquals(refModel, call, "Should have found call " + call + " but found " + refModel + " instead");
            }

        } else {
            final int expectedDP = expectedDPs.get(curPos.getStart() - data.getActiveRegion().getSpan().getStart());
            Assert.assertEquals(refModel.getStart(), loc.getStart() + i);
            Assert.assertEquals(refModel.getEnd(), loc.getStart() + i);
            Assert.assertFalse(refModel.hasLog10PError());
            Assert.assertEquals(refModel.getAlternateAlleles().size(), 1);
            Assert.assertEquals(refModel.getAlternateAllele(0), GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE);
            Assert.assertTrue(refModel.hasGenotype(sample));

            final Genotype g = refModel.getGenotype(sample);
            Assert.assertTrue(g.hasAD());
            Assert.assertTrue(g.hasDP());
            Assert.assertEquals(g.getDP(), expectedDP);
            Assert.assertTrue(g.hasGQ());
            Assert.assertTrue(g.hasPL());
        }

        final VariantContext vc = call == null ? refModel : call;
        if ( curPos.getStart() == vc.getStart() ) {
            for ( int pos = vc.getStart(); pos <= vc.getEnd(); pos++ ) {
                final int j = pos - data.getActiveRegion().getSpan().getStart();
                Assert.assertFalse(seenBP.get(j));
                seenBP.set(j, true);
            }
        }
    }

    for ( int i = 0; i < seenBP.size(); i++ ) {
        Assert.assertEquals((boolean)seenBP.get(i), true);
    }
}
 
Example 10
Source File: VariantTypesVariantFilter.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean test(final VariantContext vc) {
    final VariantContext.Type vcSampleType = vc.getType();
    return sampleTypes.contains(vcSampleType);
}
 
Example 11
Source File: GencodeFuncotationFactory.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@VisibleForTesting
static String getTranscriptEndPaddingBases(final VariantContext variant,
                                           final Allele altAllele,
                                           final List<? extends htsjdk.samtools.util.Locatable> exonPositionList,
                                           final ReferenceContext reference) {

    // We pad the end of the transcript to allow for the case where an indel runs off the end of a transcript
    // and needs to be annotated.
    // One variant where this happens is:
    //   <B37 Ref>:  1:178514560 A->AT
    //
    // We need only do this when the variant is close to the end of the transcript.
    //
    // Unfortunately we need to pad the end by the number of bases beyond the boundary, rounded up to the
    // next codon end position.
    // This corresponds to (with an extra codon for safety):
    //        (Math.ceil(<number of inserted bases>/AminoAcid.CODON_LENGTH)+1)*AminoAcid.CODON_LENGTH
    // This is a problem because transcriptFastaReferenceDataSource has only the bases in a given transcript.
    // Because of this we need to go to the real reference sequence and grab additional bases to pad onto the
    // end of the transcript coding sequence.

    final int transcriptEndGenomicPosition = exonPositionList.get(exonPositionList.size()-1).getEnd();
    // Add one because of inclusive positions:
    final int basesToTranscriptEnd = transcriptEndGenomicPosition - variant.getStart() + 1;

    final byte[] transcriptTailPaddingBases;
    if ( (variant.getType() == VariantContext.Type.INDEL) &&
            (basesToTranscriptEnd < TRANSCRIPT_END_WINDOW_PADDING_THRESHOLD) ) {
        final int numIndelBases = Math.abs(variant.getReference().length() - altAllele.length());
        final int numPaddingBases = (int)((Math.ceil(numIndelBases/((double)AminoAcid.CODON_LENGTH))+1)*AminoAcid.CODON_LENGTH);

        // Get extra bases from the reference:
        transcriptTailPaddingBases = reference.getBases(new SimpleInterval(reference.getWindow().getContig(), transcriptEndGenomicPosition+1, transcriptEndGenomicPosition + numPaddingBases));
    }
    else {
        // No bases needed:
        transcriptTailPaddingBases = new byte[]{};
    }

    return new String(transcriptTailPaddingBases);
}