htsjdk.variant.variantcontext.Allele Java Examples

The following examples show how to use htsjdk.variant.variantcontext.Allele. 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: GencodeFuncotationFactory.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Checks the given variant alt allele for whether it's a special case.
 * If so, will create the appropriate funcotation for that case.
 * @param variant {@link VariantContext} for the given {@code altAllele}.
 * @param altAllele The alternate {@link Allele} to be checked for special cases.
 * @param reference {@link ReferenceContext} supporting the given {@code variant}.
 * @param transcript {@link GencodeGtfTranscriptFeature} containing the given {@code variant}.
 * @return A {@link GencodeFuncotation} for the given special case alt allele, or {@code null} if the allele is not a special case.
 */
private GencodeFuncotation checkForAndCreateSpecialAlleleFuncotation(final VariantContext variant,
                                                                     final Allele altAllele,
                                                                     final ReferenceContext reference,
                                                                     final GencodeGtfTranscriptFeature transcript) {
    // If the alt allele is a spanning deletion or a symbolic allele, create an unknown funcotation:
    if (altAllele.isSymbolic() || altAllele.equals(Allele.SPAN_DEL) ) {
        return createFuncotationForSymbolicAltAllele(variant, altAllele, transcript, reference);
    }

    // If the reference allele or alternate allele contains any masked bases:
    if ( variant.getReference().getBaseString().contains(FuncotatorConstants.MASKED_ANY_BASE_STRING) || altAllele.getBaseString().contains(FuncotatorConstants.MASKED_ANY_BASE_STRING) ) {
        return createFuncotationForMaskedBases(variant, altAllele, transcript, reference);
    }

    return null;
}
 
Example #2
Source File: HaplotypeProbabilitiesTest.java    From picard with MIT License 6 votes vote down vote up
@Test(dataProvider = "symmetricLODdata")
public void testSymmetricLOD(final double[] llikelihoods1, final double[] llikelihoods2) {
    final HaplotypeBlock haplotypeBlock = new HaplotypeBlock(0.1);
    final Snp testSnp = new Snp("test", "chrTest", 1, (byte) 'A', (byte) 'C', .1, Collections.emptyList());
    haplotypeBlock.addSnp(testSnp);

    final HaplotypeProbabilitiesFromGenotypeLikelihoods hp1 = new HaplotypeProbabilitiesFromGenotypeLikelihoods(haplotypeBlock);
    final HaplotypeProbabilitiesFromGenotypeLikelihoods hp2 = new HaplotypeProbabilitiesFromGenotypeLikelihoods(haplotypeBlock);

    hp1.addToLogLikelihoods(testSnp, CollectionUtil.makeList(Allele.ALT_A, Allele.REF_C), llikelihoods1);
    hp2.addToLogLikelihoods(testSnp, CollectionUtil.makeList(Allele.ALT_A, Allele.REF_C), llikelihoods2);

    TestNGUtil.assertEqualDoubleArrays(MathUtil.pNormalizeVector(hp1.getPosteriorProbabilities()),
            MathUtil.pNormalizeVector(MathUtil.multiply(MathUtil.pNormalizeLogProbability(llikelihoods1), haplotypeBlock.getHaplotypeFrequencies())), .00001);

    TestNGUtil.assertEqualDoubleArrays(MathUtil.pNormalizeVector(hp2.getPosteriorProbabilities()),
            MathUtil.pNormalizeVector(MathUtil.multiply(MathUtil.pNormalizeLogProbability(llikelihoods2), haplotypeBlock.getHaplotypeFrequencies())), .00001);

    final double ll21 = hp1.scaledEvidenceProbabilityUsingGenotypeFrequencies(hp2.getPosteriorLikelihoods());
    final double ll12 = hp2.scaledEvidenceProbabilityUsingGenotypeFrequencies(hp1.getPosteriorLikelihoods());

    Assert.assertTrue(TestNGUtil.compareDoubleWithAccuracy(ll12, ll21, 0.001), "found : " + ll12 + " and " + ll21);
}
 
Example #3
Source File: AlleleLikelihoodsUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test(dataProvider = "marginalizationDataSets")
public void testMarginalization(final String[] samples, final Allele[] alleles, final Map<String,List<GATKRead>> reads, final Map<Allele,List<Allele>> newToOldAlleleMapping) {
    final AlleleLikelihoods<GATKRead, Allele> original = new AlleleLikelihoods<>(new IndexedSampleList(samples), new IndexedAlleleList<>(alleles), reads);
    fillWithRandomLikelihoods(samples, alleles, original);
    final AlleleLikelihoods<GATKRead, Allele> marginalized = original.marginalize(newToOldAlleleMapping);
    Assert.assertNotNull(marginalized);
    Assert.assertEquals(newToOldAlleleMapping.size(), marginalized.numberOfAlleles());
    for (int a = 0; a < marginalized.numberOfAlleles(); a++) {
        final List<Allele> oldAlleles = newToOldAlleleMapping.get(marginalized.getAllele(a));
        Assert.assertNotNull(oldAlleles);
        for (int s = 0; s < samples.length; s++) {
            final LikelihoodMatrix<GATKRead, Allele> oldSmapleLikelihoods = original.sampleMatrix(s);
            final LikelihoodMatrix<GATKRead, Allele> sampleLikelihoods = marginalized.sampleMatrix(s);
            final int sampleReadCount = sampleLikelihoods.evidenceCount();
            final int oldSampleReadCount = oldSmapleLikelihoods.evidenceCount();
            Assert.assertEquals(oldSampleReadCount, sampleReadCount);
            for (int r = 0; r < sampleReadCount; r++) {
                double oldBestLk = Double.NEGATIVE_INFINITY;
                for (final Allele oldAllele : oldAlleles) {
                    oldBestLk = Math.max(oldSmapleLikelihoods.get(original.indexOfAllele(oldAllele), r), oldBestLk);
                }
                Assert.assertEquals(sampleLikelihoods.get(a, r), oldBestLk);
            }
        }
    }
}
 
Example #4
Source File: CoverageUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testLikelihoods(){
    final Allele REF = Allele.create("T", true);
    final Allele ALT = Allele.create("A");

    final int refDepth= 5;
    final int altDepth= 3;
    final List<GATKRead>  refReads = IntStream.range(0, refDepth).mapToObj(n -> makeRead()).collect(Collectors.toList());
    final List<GATKRead>  altReads = IntStream.range(0, altDepth).mapToObj(n -> makeRead()).collect(Collectors.toList());
    final AlleleLikelihoods<GATKRead, Allele> likelihoods =
            ArtificialAnnotationUtils.makeLikelihoods("sample1", refReads, altReads, -100.0, -100.0, REF, ALT);

    final VariantContext vc= makeVC();
    final ReferenceContext referenceContext= null;
    final Map<String, Object> annotate = new Coverage().annotate(referenceContext, vc, likelihoods);
    Assert.assertEquals(annotate.size(), 1, "size");
    Assert.assertEquals(annotate.keySet(), Collections.singleton(VCFConstants.DEPTH_KEY), "annots");
    final int m = altDepth + refDepth;
    Assert.assertEquals(annotate.get(VCFConstants.DEPTH_KEY), String.valueOf(m));
}
 
Example #5
Source File: RankSumTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void fillQualsFromLikelihood(VariantContext vc, AlleleLikelihoods<GATKRead, Allele> likelihoods, List<Double> refQuals, List<Double> altQuals) {
    for (final AlleleLikelihoods<GATKRead, Allele>.BestAllele bestAllele : likelihoods.bestAllelesBreakingTies()) {
        final GATKRead read = bestAllele.evidence;
        final Allele allele = bestAllele.allele;
        if (bestAllele.isInformative() && isUsableRead(read, vc)) {
            final OptionalDouble value = getElementForRead(read, vc, bestAllele);
            // Bypass read if the clipping goal is not reached or the refloc is inside a spanning deletion
            if (value.isPresent() && value.getAsDouble() != INVALID_ELEMENT_FROM_READ) {
                if (allele.isReference()) {
                    refQuals.add(value.getAsDouble());
                } else if (vc.hasAllele(allele)) {
                    altQuals.add(value.getAsDouble());
                }
            }
        }
    }
}
 
Example #6
Source File: LocatableFuncotationCreatorUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testCreate() {
    final SimpleInterval locatable = new SimpleInterval("1", 1000, 2000);
    final Funcotation guess = LocatableFuncotationCreator.create(locatable,
            Allele.create("C"), "TEST_NAME");
    Assert.assertEquals(guess.getFieldNames(), new LinkedHashSet<>(
            Arrays.asList(LocatableFuncotationCreator.CONTIG_FIELD_NAME,
                    LocatableFuncotationCreator.START_FIELD_NAME,
                    LocatableFuncotationCreator.END_FIELD_NAME
            )));
    Assert.assertEquals(guess.getField(LocatableFuncotationCreator.CONTIG_FIELD_NAME), locatable.getContig());
    Assert.assertEquals(guess.getField(LocatableFuncotationCreator.START_FIELD_NAME), String.valueOf(locatable.getStart()));
    Assert.assertEquals(guess.getField(LocatableFuncotationCreator.END_FIELD_NAME), String.valueOf(locatable.getEnd()));

    Assert.assertEquals(guess.getMetadata(), LocatableFuncotationCreator.METADATA);

}
 
Example #7
Source File: FuncotatorUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Use the given metadata to create funcotations from variant context attributes (and alt alleles)
 * @param vc Never {@code null}
 * @param metadata Fields that should be present in the funcotations.  Can be a superset of the fields in the
 *                 funcotations.  Never {@code null}
 * @param datasourceName Name to appear in all funcotations.  Never {@code null}
 * @return Instances of {@link Funcotation} for each field in the metadata x alternate allele in the variant context.
 * If a field is not present in the variant context attributes, the field will ave value empty string ("") in all output
 * funcotations.  Fields will be the same names and values for each alternate allele in the funcotations.
 */
static List<Funcotation> createFuncotationsFromMetadata(final VariantContext vc, final FuncotationMetadata metadata, final String datasourceName) {

    Utils.nonNull(vc);
    Utils.nonNull(metadata);
    Utils.nonNull(datasourceName);

    final List<String> fields = metadata.retrieveAllHeaderInfo().stream().map(VCFInfoHeaderLine::getID).collect(Collectors.toList());
    final List<Funcotation> result = new ArrayList<>();
    for (final Allele allele: vc.getAlternateAlleles()) {

        // We must have fields for everything in the metadata.
        final List<String> funcotationFieldValues = new ArrayList<>();
        for (final String funcotationFieldName : fields) {
            funcotationFieldValues.add(vc.getAttributeAsString(funcotationFieldName, ""));
        }

        result.add(TableFuncotation.create(fields, funcotationFieldValues, allele, datasourceName, metadata));
    }

    return result;
}
 
Example #8
Source File: AFCalculationResultUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test(dataProvider = "AFCalculationResults")
private void test(final int[] mleCounts, final List<Allele> alleles, final double probabilityOfNoVariant, final double[] probabilityOfNoVariantByAllele) {
    final Map<Allele, Double> log10pRefByAllele = new HashMap<>();
    for (int n = 1; n < alleles.size(); n++) {
        log10pRefByAllele.put(alleles.get(n), Math.log10(probabilityOfNoVariantByAllele[n-1]));
    }
    final AFCalculationResult result = new AFCalculationResult(mleCounts, alleles, Math.log10(probabilityOfNoVariant), log10pRefByAllele);

    ArrayAsserts.assertArrayEquals(result.getAlleleCountsOfMLE(), mleCounts);
    Assert.assertEquals(result.getAllelesUsedInGenotyping(), alleles);

    for (int n = 1; n < alleles.size(); n++) {
        Assert.assertEquals(result.getAlleleCountAtMLE(alleles.get(n)), mleCounts[n-1]);
    }

    Assert.assertEquals(result.log10ProbVariantPresent(), Math.log10(1 - probabilityOfNoVariant), 1.0e-10);
}
 
Example #9
Source File: DepthPerAlleleBySample.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void annotate(final ReferenceContext ref,
                     final VariantContext vc,
                     final Genotype g,
                     final GenotypeBuilder gb,
                     final AlleleLikelihoods<GATKRead, Allele> likelihoods) {
    Utils.nonNull(gb, "gb is null");
    Utils.nonNull(vc, "vc is null");

    if ( g == null || !g.isCalled() || likelihoods == null) {
        return;
    }
    final Set<Allele> alleles = new LinkedHashSet<>(vc.getAlleles());

    // make sure that there's a meaningful relationship between the alleles in the likelihoods and our VariantContext
    Utils.validateArg(likelihoods.alleles().containsAll(alleles), () -> "VC alleles " + alleles + " not a  subset of AlleleLikelihoods alleles " + likelihoods.alleles());

    gb.AD(annotateWithLikelihoods(vc, g, alleles, likelihoods));
}
 
Example #10
Source File: LeftAlignAndTrimVariantsUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testLeftAlignWithVaryingMaxDistances() {

    final byte[] refSequence = new byte[200];
    Arrays.fill(refSequence, 0, 100, (byte) 'C');
    Arrays.fill(refSequence, 100, 200, (byte) 'A');

    final String contig = "1";
    final SAMFileHeader header = ArtificialReadUtils.createArtificialSamHeader(1, 1, refSequence.length);
    final SimpleInterval interval = new SimpleInterval(contig, 1, refSequence.length);


    final ReferenceBases refBases = new ReferenceBases(refSequence, interval);
    final ReferenceDataSource referenceDataSource = new ReferenceMemorySource(refBases, header.getSequenceDictionary());
    final ReferenceContext referenceContext = new ReferenceContext(referenceDataSource, interval);

    final List<Allele> alleles = Arrays.asList(Allele.create("AA", true), Allele.create("A", false));
    for (int maxShift : new int[] {0, 1, 5, 10, 30}) {
        for (int start : new int[]{101, 105, 109, 110, 111, 115, 120, 130, 141}) {
            final VariantContext vc = new VariantContextBuilder("source", contig, start, start + 1, alleles).make();
            final VariantContext realignedV = LeftAlignAndTrimVariants.leftAlignAndTrim(vc, referenceContext, maxShift, true);

            Assert.assertEquals(realignedV.getStart(), Math.max(start - maxShift, 100));
        }
    }
}
 
Example #11
Source File: AlleleLikelihoodsUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void testSampleQueries(String[] samples, Map<String, List<GATKRead>> reads, AlleleLikelihoods<GATKRead, Allele> result) {
    final Set<Integer> sampleIds = new LinkedHashSet<>(samples.length);
    for (final String sample : samples) {
        final int indexOfSample = result.indexOfSample(sample);
        Assert.assertTrue(indexOfSample >= 0);
        Assert.assertFalse(sampleIds.contains(indexOfSample));
        sampleIds.add(indexOfSample);

        final List<GATKRead> sampleReads = result.sampleEvidence(indexOfSample);
        final Set<GATKRead> sampleReadsSet = new LinkedHashSet<>(sampleReads);
        final List<GATKRead> expectedSampleReadArray = reads.get(sample);
        final Set<GATKRead> expectedSampleReadsSet = new LinkedHashSet<>(expectedSampleReadArray);
        Assert.assertEquals(sampleReadsSet, expectedSampleReadsSet);

        final int sampleReadCount = sampleReads.size();
        for (int r = 0; r < sampleReadCount; r++) {
            Assert.assertSame(sampleReads.get(r), expectedSampleReadArray.get(r));
            final int readIndex = result.evidenceIndex(indexOfSample, sampleReads.get(r));
            Assert.assertEquals(readIndex,r);
        }
    }
}
 
Example #12
Source File: AS_RankSumTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String makeReducedAnnotationString(final VariantContext vc, final Map<Allele,Double> perAltRankSumResults) {
    final StringBuilder annotationString = new StringBuilder();
    for (final Allele a : vc.getAlternateAlleles()) {
        if (annotationString.length() != 0) {
            annotationString.append(AnnotationUtils.ALLELE_SPECIFIC_REDUCED_DELIM);
        }
        if (!perAltRankSumResults.containsKey(a)) {
            logger.warn("VC allele not found in annotation alleles -- maybe there was trimming?  Allele " + a.getDisplayString() + " will be marked as missing.");
            annotationString.append(VCFConstants.MISSING_VALUE_v4); //add the missing value or the array size and indexes won't check out
        } else {
            final Double numericAlleleValue = perAltRankSumResults.get(a);
            final String perAlleleValue = numericAlleleValue != null ? String.format("%.3f", numericAlleleValue) : VCFConstants.MISSING_VALUE_v4;
            annotationString.append(perAlleleValue);
        }
    }
    return annotationString.toString();
}
 
Example #13
Source File: FuncotatorUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the start position of the difference between the reference and alternate alleles in the given {@link VariantContext}.
 * @param variant {@link VariantContext} in which to determine the start of the different bases.
 * @param altAllele The alternate {@link Allele} against which to check the reference allele in {@code variant}.
 * @return The start position of the difference between the reference and alternate alleles in the given {@link VariantContext}.
 */
public static int getIndelAdjustedAlleleChangeStartPosition(final VariantContext variant, final Allele altAllele) {

    // If the variant is an indel, we need to check only the bases that are added/deleted for overlap.
    // The convention for alleles in Funcotator is to preserve a leading base for an indel, so we just need
    // to create a new variant that has its start position shifted by the leading base.
    // NOTE: because there could be degenerate VCF files that have more than one leading base overlapping, we need
    //       to detect how many leading bases there are that overlap, rather than assuming there is only one.
    final int varStart;
    if ( GATKVariantContextUtils.typeOfVariant(variant.getReference(), altAllele).equals(VariantContext.Type.INDEL) &&
         !GATKVariantContextUtils.isComplexIndel(variant.getReference(), altAllele) ) {
        int startOffset = 0;
        while ( (startOffset < variant.getReference().length()) && (startOffset < altAllele.length()) && (variant.getReference().getBases()[ startOffset ] == altAllele.getBases()[ startOffset ]) ) {
            ++startOffset;
        }
        varStart = variant.getStart() + startOffset;
    }
    else {
        // Not an indel?  Then we should have no overlapping bases:
        varStart = variant.getStart();
    }

    return varStart;
}
 
Example #14
Source File: VcfFuncotationFactory.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private List<Funcotation> createDefaultFuncotationsOnVariantHelper( final VariantContext variant, final ReferenceContext referenceContext, final Set<Allele> annotatedAltAlleles  ) {

        final List<Funcotation> funcotationList = new ArrayList<>();

        if ( supportedFieldNames.size() != 0 ) {

            final List<Allele> alternateAlleles = variant.getAlternateAlleles();

            for ( final Allele altAllele : alternateAlleles ) {
                if ( !annotatedAltAlleles.contains(altAllele) ) {
                    funcotationList.add(createDefaultFuncotation(altAllele));
                }
            }
        }

        return funcotationList;
    }
 
Example #15
Source File: GenotypeConcordanceTest.java    From picard with MIT License 6 votes vote down vote up
@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);
}
 
Example #16
Source File: GencodeFuncotationFactoryUnitTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testFivePrimeFlankSorting() {
    // This variant context would get a sorting that was different than the ground truth in FuncotatorIntegrationTest#nonTrivialLargeDataValidationTest
    final VariantContext variantContext = new VariantContextBuilder("", "1", 871276, 871276,
            Arrays.asList(Allele.create("G", true), Allele.create("A"))).make();
    final String transcriptGtfFile = GENCODE_HG19_BIG_GTF_FILE;
    final String transcriptFastaFile = GENCODE_HG19_BIG_FASTA_FILE;
    final SimpleInterval variantInterval = new SimpleInterval(variantContext);
    final ReferenceContext referenceContext = new ReferenceContext(ReferenceDataSource.of(Paths.get(b37Reference)), variantInterval);
    final VariantContext vcHg19 = new VariantContextBuilder(variantContext).chr(FuncotatorUtils.convertB37ContigToHg19Contig(variantContext.getContig())).make();
    final SimpleInterval vcHg19Interval = new SimpleInterval(vcHg19.getContig(), vcHg19.getStart(), vcHg19.getEnd());

    final FeatureInput<GencodeGtfFeature> gencodeFeatureInput = new FeatureInput<>(transcriptGtfFile, GencodeFuncotationFactory.DEFAULT_NAME, Collections.emptyMap());
    final Map<FeatureInput<? extends Feature>, Class<? extends Feature>> featureInputMap = new HashMap<>();
    featureInputMap.put(gencodeFeatureInput, GencodeGtfFeature.class);
    final FeatureContext featureContext = FeatureContext.createFeatureContextForTesting(featureInputMap, "dummyName", vcHg19Interval, VariantWalker.DEFAULT_DRIVING_VARIANTS_LOOKAHEAD_BASES, 0, 0, null);

    // Sorts canonically
    try (final GencodeFuncotationFactory funcotationFactory = new GencodeFuncotationFactory(
            IOUtils.getPath(transcriptFastaFile),
            "VERSION",
            GencodeFuncotationFactory.DEFAULT_NAME,
            FuncotatorArgumentDefinitions.TRANSCRIPT_SELECTION_MODE_DEFAULT_VALUE,
            Collections.emptySet(),
            new LinkedHashMap<>(),
            gencodeFeatureInput,
            new FlankSettings(5000, 0),
            "TEST")) {

        final List<Funcotation> gencodeFuncotationList = funcotationFactory.createFuncotations(vcHg19, referenceContext, featureContext);

        System.out.println(gencodeFuncotationList.size());
    }
}
 
Example #17
Source File: HaplotypeCallerIntegrationTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Helper method for testMaxAlternateAlleles
 *
 * @param vc VariantContext to check
 * @return number of alt alleles in vc, excluding NON_REF (if present)
 */
private int getNumAltAllelesExcludingNonRef( final VariantContext vc ) {
    final List<Allele> altAlleles = vc.getAlternateAlleles();
    int numAltAllelesExcludingNonRef = 0;

    for ( final Allele altAllele : altAlleles ) {
        if ( ! altAllele.equals(Allele.NON_REF_ALLELE) ) {
            ++numAltAllelesExcludingNonRef;
        }
    }

    return numAltAllelesExcludingNonRef;
}
 
Example #18
Source File: PerAlleleCollection.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setRef(Allele allele, X value){
    Utils.nonNull(allele, "ref allele is null");
    Utils.nonNull(value, "value is null");
    Utils.validateArg(allele.isReference(), "setting non-reference allele as reference");
    Utils.validateArg(!refAllele.isPresent(), "Resetting the reference allele not permitted");
    refAllele = Optional.of(allele);
    refValue = Optional.of(value);
}
 
Example #19
Source File: ValidateVariants.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void validateGVCFVariant(final VariantContext vc) {
    if (!vc.hasAllele(Allele.NON_REF_ALLELE)) {
        final UserException e = new UserException(String.format("In a GVCF all records must contain a %s allele. Offending record: %s",
                Allele.NON_REF_STRING, vc.toStringWithoutGenotypes()));
        throwOrWarn(e);
    }
}
 
Example #20
Source File: PerAlleleCollection.java    From gatk-protected with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Take an allele, REF or ALT, and update its value appropriately
 *
 * @param allele : REF or ALT allele
 * @param value :
 */
public void set(Allele allele, X value){
    Utils.nonNull(allele, "allele is null");
    Utils.nonNull(value, "value is null");
    Utils.validateArg(type == Type.REF_AND_ALT || allele.isNonReference(), "Collection stores values for alternate alleles only");
    if (allele.isReference()){
        setRef(allele, value);
    } else {
        setAlt(allele, value);
    }
}
 
Example #21
Source File: SimpleSVType.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DuplicationTandem(final NovelAdjacencyAndAltHaplotype novelAdjacencyAndAltHaplotype,
                         final ReferenceMultiSparkSource reference) {
    super(novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc().getContig(),
            novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc().getStart(),
            novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc().getStart(),
            getIDString(novelAdjacencyAndAltHaplotype),
            Allele.create(extractRefBases(novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc(), reference), true),
            Allele.create(createBracketedSymbAlleleString(GATKSVVCFConstants.SYMB_ALT_ALLELE_DUP)),
            novelAdjacencyAndAltHaplotype.getLengthForDupTandemExpansion(),
            Collections.singletonMap(GATKSVVCFConstants.DUP_TAN_EXPANSION_STRING, true));
}
 
Example #22
Source File: AssemblyBasedSVDiscoveryTestDataProvider.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static final VariantContextBuilder makeInsertion(final String chr, final int pos, final int end, final int svLen,
                                                 final Allele refAllele) {

    return new VariantContextBuilder().chr(chr).start(pos).stop(end)
            .alleles(Arrays.asList(refAllele, INS_SYMB_ALLELE))
            .id(makeID(SimpleSVType.SupportedType.INS.name(), chr, pos, chr, end, ""))
            .attribute(VCFConstants.END_KEY, end)
            .attribute(SVLEN, svLen)
            .attribute(SVTYPE, SimpleSVType.SupportedType.INS.name());
}
 
Example #23
Source File: RMSMappingQuality.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Combine the long tuples: sum of squared mapping quality and read counts over variant genotypes
 * Since this is not an allele-specific annotation, store the result with the NO_CALL allele key.
 * @param toAdd new data
 * @param combined passed in as previous data, modified to store the combined result
 */
private void combineAttributeMap(ReducibleAnnotationData<List<Long>> toAdd, ReducibleAnnotationData<List<Long>> combined) {
    if (combined.getAttribute(Allele.NO_CALL) != null) {
        combined.putAttribute(Allele.NO_CALL, Arrays.asList(combined.getAttribute(Allele.NO_CALL).get(SUM_OF_SQUARES_INDEX) + toAdd.getAttribute(Allele.NO_CALL).get(SUM_OF_SQUARES_INDEX),
                combined.getAttribute(Allele.NO_CALL).get(TOTAL_DEPTH_INDEX) + toAdd.getAttribute(Allele.NO_CALL).get(TOTAL_DEPTH_INDEX)));
    } else {
        combined.putAttribute(Allele.NO_CALL, toAdd.getAttribute(Allele.NO_CALL));
    }
}
 
Example #24
Source File: LiftoverVcfTest.java    From picard with MIT License 5 votes vote down vote up
@Test
public void testReverseComplementFailureDoesNotErrorOut() {
    final VariantContextBuilder builder = new VariantContextBuilder().source("test").loc("chr1", 1, 4);
    final Allele originalRef = Allele.create("CCCC", true);
    final Allele originalAlt = Allele.create("C", false);
    builder.alleles(Arrays.asList(originalRef, originalAlt));

    final Interval interval = new Interval("chr1", 1, 4, true, "test ");

    final String reference = "ATGATGATGA";
    final ReferenceSequence refSeq = new ReferenceSequence("chr1", 10, reference.getBytes());

    // we don't actually care what the results are here -- we just want to make sure that it doesn't fail
    final VariantContextBuilder result = LiftoverUtils.reverseComplementVariantContext(builder.make(), interval, refSeq);
}
 
Example #25
Source File: SegmentedCpxVariantSimpleVariantExtractor.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private List<VariantContext> whenZeroSegments(final VariantContext complexVC, final ReferenceMultiSparkSource reference) {
    final Allele anchorBaseRefAllele = getAnchorBaseRefAllele(complexVC.getContig(), complexVC.getStart(), reference);
    final int altSeqLength = complexVC.getAttributeAsString(SEQ_ALT_HAPLOTYPE, "").length() - 2;
    final List<String> mappingQualities = SVUtils.getAttributeAsStringList(complexVC, MAPPING_QUALITIES);
    final int maxAlignLength = complexVC.getAttributeAsInt(MAX_ALIGN_LENGTH, 0);
    final VariantContext insertion = makeInsertion(complexVC.getContig(), complexVC.getStart(), complexVC.getStart(), altSeqLength, anchorBaseRefAllele)
            .attribute(CPX_EVENT_KEY, complexVC.getID())
            .attribute(CONTIG_NAMES, complexVC.getAttribute(CONTIG_NAMES))
            .attribute(MAPPING_QUALITIES, mappingQualities)
            .attribute(MAX_ALIGN_LENGTH, maxAlignLength)
            .make();
    return Collections.singletonList(insertion);
}
 
Example #26
Source File: AS_FisherStrand.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected Map<Allele,Double> calculateReducedData(AlleleSpecificAnnotationData<List<Integer>> combinedData) {
    final Map<Allele,Double> annotationMap = new HashMap<>();
    final Map<Allele,List<Integer>> perAlleleData = combinedData.getAttributeMap();
    final List<Integer> refStrandCounts = perAlleleData.get(combinedData.getRefAllele());
    for (final Allele a : perAlleleData.keySet()) {
        if(!a.equals(combinedData.getRefAllele(),true)) {
            final List<Integer> altStrandCounts = combinedData.getAttribute(a);
            final int[][] refAltTable = new int[][]{new int[]{refStrandCounts.get(0), refStrandCounts.get(1)}, new int[]{altStrandCounts.get(0), altStrandCounts.get(1)}};
            annotationMap.put(a, QualityUtils.phredScaleErrorRate(Math.max(FisherStrand.pValueForContingencyTable(refAltTable), MIN_PVALUE)));
        }
    }
    return annotationMap;
}
 
Example #27
Source File: MergePedIntoVcf.java    From picard with MIT License 5 votes vote down vote up
private Allele formatAllele(final String alleleA) {
    if (alleleA.equals(SPAN_DEL_STRING)) {
        return Allele.SPAN_DEL;
    } else if (alleleA.contains(SPAN_DEL_STRING)) {
        return Allele.create(alleleA.replace(SPAN_DEL_STRING.charAt(0), ' ').trim(), true);
    } else {
        return Allele.create(alleleA, false);
    }
}
 
Example #28
Source File: PerAlleleCollection.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Take an allele, REF or ALT, and update its value appropriately
 *
 * @param allele : REF or ALT allele
 * @param value :
 */
public void set(Allele allele, X value){
    Utils.nonNull(allele, "allele is null");
    Utils.nonNull(value, "value is null");
    Utils.validateArg(type == Type.REF_AND_ALT || allele.isNonReference(), "Collection stores values for alternate alleles only");
    if (allele.isReference()){
        setRef(allele, value);
    } else {
        setAlt(allele, value);
    }
}
 
Example #29
Source File: VariantContextTestUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static List<Integer> createAlleleIndexMap(final List<Allele> originalAlleles, final List<Allele> sortedAlleles){
    final List<Integer> mapping = new ArrayList<>(originalAlleles.size());
    for ( final Allele a: sortedAlleles){
        final int newIndex = originalAlleles.indexOf(a);
        mapping.add(newIndex);
    }
    return mapping;
}
 
Example #30
Source File: MinAlleleFractionFilter.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public List<Boolean> areAllelesArtifacts(final VariantContext vc, final Mutect2FilteringEngine filteringEngine, ReferenceContext referenceContext) {
    LinkedHashMap<Allele, List<Double>> dataByAllele = getAltDataByAllele(vc, g -> g.hasExtendedAttribute(GATKVCFConstants.ALLELE_FRACTION_KEY) && filteringEngine.isTumor(g), this::getAltData, filteringEngine);
    return dataByAllele.entrySet().stream()
            .filter(entry -> !vc.getReference().equals(entry.getKey()))
            .map(entry -> entry.getValue().stream().max(Double::compare).orElse(1.0) < minAf).collect(Collectors.toList());
}