当前位置: 首页>>代码示例>>Java>>正文


Java GenotypeBuilder.alleles方法代码示例

本文整理汇总了Java中htsjdk.variant.variantcontext.GenotypeBuilder.alleles方法的典型用法代码示例。如果您正苦于以下问题:Java GenotypeBuilder.alleles方法的具体用法?Java GenotypeBuilder.alleles怎么用?Java GenotypeBuilder.alleles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在htsjdk.variant.variantcontext.GenotypeBuilder的用法示例。


在下文中一共展示了GenotypeBuilder.alleles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assignGenotype

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
/**
 * Assign genotypes (GTs) to the samples in the Variant Context greedily based on the PLs
 *
 * @param newLikelihoods the PL array
 * @param allelesToUse   the list of alleles to choose from (corresponding to the PLs)
 * @param numChromosomes Number of chromosomes per pool
 */
private void assignGenotype(final GenotypeBuilder gb,
                            final double[] newLikelihoods,
                            final List<Allele> allelesToUse,
                            final int numChromosomes) {
    final int numNewAltAlleles = allelesToUse.size() - 1;

    // find the genotype with maximum likelihoods
    final int PLindex = numNewAltAlleles == 0 ? 0 : MathUtils.maxElementIndex(newLikelihoods);
    final GenotypeLikelihoodCalculator calculator = GenotypeLikelihoodCalculators.getInstance(numChromosomes, allelesToUse.size());
    final GenotypeAlleleCounts alleleCounts = calculator.genotypeAlleleCountsAt(PLindex);

    gb.alleles(alleleCounts.asAlleleList(allelesToUse));

    // remove PLs if necessary
    if (newLikelihoods.length > MAX_LENGTH_FOR_POOL_PL_LOGGING)
        gb.noPL();

    // TODO - deprecated so what is the appropriate method to call?
    if (numNewAltAlleles > 0)
        gb.log10PError(GenotypeLikelihoods.getGQLog10FromLikelihoods(PLindex, newLikelihoods));
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:29,代码来源:GeneralPloidyExactAFCalculator.java

示例2: subsetGenotypeAllelesWithLikelihoods

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
/**
 * From a given genotype, subset the PLs and SACs
 * @param g                                 genotype to subset
 * @param allelesToUse                      alleles to subset
 * @param vc                                variant context with alleles and genotypes
 * @param ploidy                            number of chromosomes
 * @param assignGenotypes                   true: assign hard genotypes, false: leave as no-call
 * @param newLikelihoods                    the PL values
 * @return genotype with the subsetted PLsL and SACs
 */
private Genotype subsetGenotypeAllelesWithLikelihoods(final Genotype g, final List<Allele> allelesToUse, final VariantContext vc, int ploidy,
                                                      final boolean assignGenotypes, final double[] newLikelihoods) {

    final GenotypeBuilder gb = new GenotypeBuilder(g);
    final String sampleName = g.getSampleName();

    // add likelihoods
    gb.PL(newLikelihoods);

    // get and add subsetted SACs
    final int[] newSACs = subsetSACAlleles(g, allelesToUse, vc);
    if (newSACs != null)
        gb.attribute(GaeaVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY, newSACs);
    if (assignGenotypes)
        assignGenotype(gb, vc, sampleName, newLikelihoods, allelesToUse, ploidy);
    else
        gb.alleles(GaeaGvcfVariantContextUtils.noCallAlleles(ploidy));

    return gb.make();
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:31,代码来源:GeneralPloidyExactAFCalculator.java

示例3: assignGenotype

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
/**
 * Assign genotypes (GTs) to the samples in the VariantContext greedily based on the PLs
 *
 * @param gb                   the GenotypeBuilder to modify
 * @param vc                   the VariantContext
 * @param sampleName           the sample name
 * @param newLikelihoods       the PL array
 * @param allelesToUse         the list of alleles to choose from (corresponding to the PLs)
 * @param numChromosomes       Number of chromosomes per pool
 */
private void assignGenotype(final GenotypeBuilder gb,
                            final VariantContext vc,
                            final String sampleName,
                            final double[] newLikelihoods,
                            final List<Allele> allelesToUse,
                            final int numChromosomes) {
    final int numNewAltAlleles = allelesToUse.size() - 1;

    // find the genotype with maximum likelihoods
    final int PLindex = numNewAltAlleles == 0 ? 0 : MathUtils.maxElementIndex(newLikelihoods);
    final GenotypeLikelihoodCalculator calculator = GenotypeLikelihoodCalculators.getInstance(numChromosomes,allelesToUse.size());
    final GenotypeAlleleCounts alleleCounts = calculator.genotypeAlleleCountsAt(PLindex);

    gb.alleles(alleleCounts.asAlleleList(allelesToUse));

    removePLsIfMaxNumPLValuesExceeded(gb, vc, sampleName, newLikelihoods);

    // TODO - deprecated so what is the appropriate method to call?
    if ( numNewAltAlleles > 0 )
        gb.log10PError(GenotypeLikelihoods.getGQLog10FromLikelihoods(PLindex, newLikelihoods));
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:32,代码来源:GeneralPloidyExactAFCalculator.java

示例4: assignGenotype

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
/**
 * Assign genotypes (GTs) to the samples in the VariantContext greedily based on the PLs
 *
 * @param gb                   the GenotypeBuilder to modify
 * @param vc                   the VariantContext
 * @param sampleName           the sample name
 * @param newLikelihoods       the PL array
 * @param allelesToUse         the list of alleles to choose from (corresponding to the PLs)
 * @param numChromosomes        Number of chromosomes per pool
 */
private void assignGenotype(final GenotypeBuilder gb,
                            final VariantContext vc,
                            final String sampleName,
                            final double[] newLikelihoods,
                            final List<Allele> allelesToUse,
                            final int numChromosomes) {
    final int numNewAltAlleles = allelesToUse.size() - 1;

    // find the genotype with maximum likelihoods
    final int PLindex = numNewAltAlleles == 0 ? 0 : GvcfMathUtils.maxElementIndex(newLikelihoods);
    final GenotypeLikelihoodCalculator calculator = GenotypeLikelihoodCalculators.getInstance(numChromosomes,allelesToUse.size());
    final GenotypeAlleleCounts alleleCounts = calculator.genotypeAlleleCountsAt(PLindex);

    gb.alleles(alleleCounts.asAlleleList(allelesToUse));

    removePLsIfMaxNumPLValuesExceeded(gb, vc, sampleName, newLikelihoods);

    if ( numNewAltAlleles > 0 )
        gb.log10PError(GenotypeLikelihoods.getGQLog10FromLikelihoods(PLindex, newLikelihoods));
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:31,代码来源:IndependentAllelesExactAFCalculator.java

示例5: makeCombinedAltAllelesVariantContext

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
private VariantContext makeCombinedAltAllelesVariantContext(final VariantContext vc) {
    final int nAltAlleles = vc.getNAlleles() - 1;

    if ( nAltAlleles == 1 )
        return vc;
    else {
        final VariantContextBuilder vcb = new VariantContextBuilder(vc);
        final Allele reference = vcb.getAlleles().get(0);
        vcb.alleles(Arrays.asList(reference, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE));
        final int genotypeCount = GenotypeLikelihoodCalculators.genotypeCount(2, vc.getNAlleles());
        final double[] hetLikelihoods = new double[vc.getNAlleles() - 1];
        final double[] homAltLikelihoods = new double[genotypeCount - hetLikelihoods.length - 1];
        final double[] newLikelihoods = new double[3];
        final List<Genotype> newGenotypes = new ArrayList<>(vc.getNSamples());
        for (final Genotype oldGenotype : vc.getGenotypes()) {
            final GenotypeBuilder gb = new GenotypeBuilder(oldGenotype);
            final List<Allele> oldAlleles = oldGenotype.getAlleles();
            if (oldAlleles != null) {
                final List<Allele> newAlleles = new ArrayList<>(oldAlleles.size());
                for (int i = 0; i < oldAlleles.size(); i++) {
                    final Allele oldAllele = oldAlleles.get(i);
                    if (oldAllele.isReference())
                        newAlleles.add(reference);
                    else if (oldAllele.isNoCall())
                        newAlleles.add(Allele.NO_CALL);
                    else
                        newAlleles.add(GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
                }
                gb.alleles(newAlleles);
            }
            if (combineAltAlleleLikelihoods(oldGenotype, genotypeCount, newLikelihoods, hetLikelihoods, homAltLikelihoods))
                gb.PL(newLikelihoods);
            newGenotypes.add(gb.make());
        }
        return vcb.genotypes(newGenotypes).make();
    }
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:38,代码来源:IndependentAllelesDiploidExactAFCalculator.java

示例6: makeCombinedAltAllelesVariantContext

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
private VariantContext makeCombinedAltAllelesVariantContext(final VariantContext vc) {
    final int nAltAlleles = vc.getNAlleles() - 1;

    if ( nAltAlleles == 1 )
        return vc;
    else {
        final VariantContextBuilder vcb = new VariantContextBuilder(vc);
        final Allele reference = vcb.getAlleles().get(0);
        vcb.alleles(Arrays.asList(reference, GaeaVCFConstants.NON_REF_SYMBOLIC_ALLELE));
        final int genotypeCount = GenotypeLikelihoodCalculators.genotypeCount(2, vc.getNAlleles());
        final double[] hetLikelihoods = new double[vc.getNAlleles() - 1];
        final double[] homAltLikelihoods = new double[genotypeCount - hetLikelihoods.length - 1];
        final double[] newLikelihoods = new double[3];
        final List<Genotype> newGenotypes = new ArrayList<>(vc.getNSamples());
        for (final Genotype oldGenotype : vc.getGenotypes()) {
            final GenotypeBuilder gb = new GenotypeBuilder(oldGenotype);
            final List<Allele> oldAlleles = oldGenotype.getAlleles();
            if (oldAlleles != null) {
                final List<Allele> newAlleles = new ArrayList<>(oldAlleles.size());
                for (int i = 0; i < oldAlleles.size(); i++) {
                    final Allele oldAllele = oldAlleles.get(i);
                    if (oldAllele.isReference())
                        newAlleles.add(reference);
                    else if (oldAllele.isNoCall())
                        newAlleles.add(Allele.NO_CALL);
                    else
                        newAlleles.add(GaeaVCFConstants.NON_REF_SYMBOLIC_ALLELE);
                }
                gb.alleles(newAlleles);
            }
            if (oldGenotype.isNonInformative())
                gb.PL(BIALLELIC_NON_INFORMATIVE_PLS);
            else if (combineAltAlleleLikelihoods(oldGenotype, genotypeCount, newLikelihoods, hetLikelihoods, homAltLikelihoods))
                gb.PL(newLikelihoods);
            newGenotypes.add(gb.make());
        }
        return vcb.genotypes(newGenotypes).make();
    }
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:40,代码来源:IndependentAllelesDiploidExactAFCalculator.java

示例7: composeNonTruthOverlappingGenotype

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
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();
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:32,代码来源:EvaluateCopyNumberTriStateCalls.java

示例8: setGenotype

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
private void setGenotype(GenotypeBuilder genotypeBuilder, Allele refAllele, Allele altAllele, Genotype genotype) {
    switch (genotype) {
        case HOMOZYGOUS_ALT:
            genotypeBuilder.alleles(Arrays.asList(altAllele, altAllele));
            break;
        case HOMOZYGOUS_REF:
            genotypeBuilder.alleles(Arrays.asList(refAllele, refAllele));
            break;
        case HETEROZYGOUS:
            genotypeBuilder.alleles(Arrays.asList(refAllele, altAllele));
            break;
        default:
            break;
    }
}
 
开发者ID:exomiser,项目名称:Exomiser,代码行数:16,代码来源:TestVariantFactory.java

示例9: testMinMedian

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
@Test
public void testMinMedian() {
    final VariantContext vc = getVariantContext();
    final HomRefBlock band = getHomRefBlock(vc);
    final GenotypeBuilder gb = new GenotypeBuilder(SAMPLE_NAME);
    gb.alleles(vc.getAlleles());

    int pos = band.getStart();
    band.add(pos++, gb.DP(10).GQ(11).PL(new int[]{0,11,100}).make());
    Assert.assertEquals(band.getEnd(), pos - 1);
    assertValues(band, 10, 10);

    band.add(pos++, gb.DP(11).GQ(10).PL(new int[]{0, 10, 100}).make());
    Assert.assertEquals(band.getEnd(), pos - 1);
    assertValues(band, 10, 11);

    band.add(pos++, gb.DP(12).GQ(12).PL(new int[]{0,12,100}).make());
    Assert.assertEquals(band.getEnd(), pos - 1);
    assertValues(band, 10, 11);

    band.add(pos++, gb.DP(13).GQ(15).PL(new int[]{0,15,100}).make());
    Assert.assertEquals(band.getEnd(), pos - 1);
    band.add(pos++, gb.DP(14).GQ(16).PL(new int[]{0,16,100}).make());
    Assert.assertEquals(band.getEnd(), pos - 1);
    band.add(pos++, gb.DP(15).GQ(17).PL(new int[]{0,17,100}).make());
    Assert.assertEquals(band.getEnd(), pos - 1);
    band.add(pos++, gb.DP(16).GQ(18).PL(new int[]{0,18,100}).make());
    Assert.assertEquals(band.getEnd(), pos - 1);
    assertValues(band, 10, 13);
    Assert.assertEquals(band.getSize(), pos - vc.getStart());
    Assert.assertEquals(band.getMinPLs(), new int[]{0, 10, 100});
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:33,代码来源:HomRefBlockUnitTest.java

示例10: entryToObject

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
@Override
public Genotype entryToObject(TupleInput in)
	{
	GenotypeBuilder gb=new GenotypeBuilder(in.readString());
	if(in.readBoolean()) gb.DP(in.readInt());
	if(in.readBoolean()) gb.AD(arrayOfIntToEntry(in));
	if(in.readBoolean()) gb.GQ(in.readInt());
	if(in.readBoolean()) gb.PL(arrayOfIntToEntry(in));
	
	/* ALLELES ======================================== */
	int n=in.readInt();
	List<Allele> alleles=new ArrayList<Allele>(n);
	for(int i=0;i< n;++i)
		{
		alleles.add(this.alleleBinding.entryToObject(in));
		}
	gb.alleles(alleles);
	/* ATTRIBUTES ===================================== */
	n=in.readInt();
	for(int i=0;i< n;++i)
		{
		String key=in.readString();
		gb.attribute(key, super.readAttribute(in));
		}
	 
	return gb.make();
	}
 
开发者ID:lindenb,项目名称:jvarkit,代码行数:28,代码来源:GenotypeBinding.java

示例11: cleanupGenotypeAnnotations

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
/**
 * Cleans up genotype-level annotations that need to be updated.
 * 1. move MIN_DP to DP if present
 * 2. propagate DP to AD if not present
 * 3. remove SB if present
 * 4. change the PGT value from "0|1" to "1|1" for homozygous variant genotypes
 *
 * @param VC            the VariantContext with the Genotypes to fix
 * @param createRefGTs  if true we will also create proper hom ref genotypes since we assume the site is monomorphic
 * @return a new set of Genotypes
 */
private List<Genotype> cleanupGenotypeAnnotations(final VariantContext VC, final boolean createRefGTs) {
    final GenotypesContext oldGTs = VC.getGenotypes();
    final List<Genotype> recoveredGs = new ArrayList<>(oldGTs.size());
    for ( final Genotype oldGT : oldGTs ) {
        final Map<String, Object> attrs = new HashMap<>(oldGT.getExtendedAttributes());

        final GenotypeBuilder builder = new GenotypeBuilder(oldGT);
        int depth = oldGT.hasDP() ? oldGT.getDP() : 0;

        // move the MIN_DP to DP
        if ( oldGT.hasExtendedAttribute("MIN_DP") ) {
            depth = Integer.parseInt((String)oldGT.getAnyAttribute("MIN_DP"));
            builder.DP(depth);
            attrs.remove("MIN_DP");
        }

        // remove SB
        attrs.remove("SB");

        // update PGT for hom vars
        if ( oldGT.isHomVar() && oldGT.hasExtendedAttribute(HaplotypeCaller.HAPLOTYPE_CALLER_PHASING_GT_KEY) ) {
            attrs.put(HaplotypeCaller.HAPLOTYPE_CALLER_PHASING_GT_KEY, "1|1");
        }

        // create AD if it's not there
        if ( !oldGT.hasAD() && VC.isVariant() ) {
            final int[] AD = new int[VC.getNAlleles()];
            AD[0] = depth;
            builder.AD(AD);
        }

        if ( createRefGTs ) {
            final int ploidy = oldGT.getPloidy();
            final List<Allele> refAlleles = Collections.nCopies(ploidy,VC.getReference());

            //keep 0 depth samples as no-call
            if (depth > 0) {
                builder.alleles(refAlleles);
            }

            // also, the PLs are technically no longer usable
            builder.noPL();
        }

        recoveredGs.add(builder.noAttributes().attributes(attrs).make());
    }
    return recoveredGs;
}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:60,代码来源:GenotypeGVCFs.java

示例12: subsetAlleles

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
/**
 * From a given variant context, extract a given subset of alleles, and update genotype context accordingly,
 * including updating the PL's, and assign genotypes accordingly
 *
 * @param vc              variant context with alleles and genotype likelihoods
 * @param defaultPloidy   ploidy to assume in case that {@code vc} does not contain that information
 *                        for a sample.
 * @param allelesToUse    alleles to subset
 * @param assignGenotypes true: assign hard genotypes, false: leave as no-call
 * @return GenotypesContext with new PLs
 */
public GenotypesContext subsetAlleles(final VariantContext vc, final int defaultPloidy,
                                      final List<Allele> allelesToUse,
                                      final boolean assignGenotypes) {
    // the genotypes with PLs
    final GenotypesContext oldGTs = vc.getGenotypes();

    // samples
    final List<String> sampleIndices = oldGTs.getSampleNamesOrderedByName();

    // the new genotypes to create
    final GenotypesContext newGTs = GenotypesContext.create();

    // we need to determine which of the alternate alleles (and hence the likelihoods) to use and carry forward
    final int numOriginalAltAlleles = vc.getAlternateAlleles().size();
    final int numNewAltAlleles = allelesToUse.size() - 1;


    // create the new genotypes
    for (int k = 0; k < oldGTs.size(); k++) {
        final Genotype g = oldGTs.get(sampleIndices.get(k));
        final int declaredPloidy = g.getPloidy();
        final int ploidy = declaredPloidy <= 0 ? defaultPloidy : declaredPloidy;
        if (!g.hasLikelihoods()) {
            newGTs.add(GenotypeBuilder.create(g.getSampleName(), GATKVariantContextUtils.noCallAlleles(ploidy)));
            continue;
        }

        // create the new likelihoods array from the alleles we are allowed to use
        final double[] originalLikelihoods = g.getLikelihoods().getAsVector();
        double[] newLikelihoods;

        // Optimization: if # of new alt alleles = 0 (pure ref call), keep original likelihoods so we skip normalization
        // and subsetting
        if (numOriginalAltAlleles == numNewAltAlleles || numNewAltAlleles == 0) {
            newLikelihoods = originalLikelihoods;
        } else {
            newLikelihoods = GeneralPloidyGenotypeLikelihoods.subsetToAlleles(originalLikelihoods, ploidy, vc.getAlleles(), allelesToUse);

            // might need to re-normalize
            newLikelihoods = MathUtils.normalizeFromLog10(newLikelihoods, false, true);
        }

        // if there is no mass on the (new) likelihoods, then just no-call the sample
        if (MathUtils.sum(newLikelihoods) > GATKVariantContextUtils.SUM_GL_THRESH_NOCALL) {
            newGTs.add(GenotypeBuilder.create(g.getSampleName(), GATKVariantContextUtils.noCallAlleles(ploidy)));
        } else {
            final GenotypeBuilder gb = new GenotypeBuilder(g);

            if (numNewAltAlleles == 0)
                gb.noPL();
            else
                gb.PL(newLikelihoods);

            // if we weren't asked to assign a genotype, then just no-call the sample
            if (!assignGenotypes || MathUtils.sum(newLikelihoods) > GATKVariantContextUtils.SUM_GL_THRESH_NOCALL)
                gb.alleles(GATKVariantContextUtils.noCallAlleles(ploidy));
            else
                assignGenotype(gb, newLikelihoods, allelesToUse, ploidy);
            newGTs.add(gb.make());
        }
    }

    return newGTs;

}
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:77,代码来源:GeneralPloidyExactAFCalculator.java

示例13: getLikelihoods

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
public VariantContext getLikelihoods(final RefMetaDataTracker tracker,
                                         final ReferenceContext ref,
                                         final Map<String, AlignmentContext> contexts,
                                         final AlignmentContextUtils.ReadOrientation contextType,
                                         final List<Allele> allAllelesToUse,
                                         final boolean useBAQedPileup,
                                         final GenomeLocParser locParser,
                                         final Map<String, PerReadAlleleLikelihoodMap> perReadAlleleLikelihoodMap) {

        GenomeLoc loc = ref.getLocus();
//        if (!ref.getLocus().equals(lastSiteVisited)) {
        if (contextType == AlignmentContextUtils.ReadOrientation.COMPLETE) {
            // starting a new site: clear allele list
            haplotypeMap.clear();
            perReadAlleleLikelihoodMap.clear(); // clean mapping sample-> per read, per allele likelihoods
            alleleList = getInitialAlleleList(tracker, ref, contexts, contextType, UAC, ignoreSNPAllelesWhenGenotypingIndels);
            if (alleleList.isEmpty())
                return null;
        }

        getHaplotypeMapFromAlleles(alleleList, ref, loc, haplotypeMap); // will update haplotypeMap adding elements
        if (haplotypeMap == null || haplotypeMap.isEmpty())
            return null;

        // start making the VariantContext
        // For all non-snp VC types, VC end location is just startLocation + length of ref allele including padding base.
        final int endLoc = loc.getStart() + alleleList.get(0).length() - 1;
        final int eventLength = getEventLength(alleleList);

        final VariantContextBuilder builder = new VariantContextBuilder("UG_call", loc.getContig(), loc.getStart(), endLoc, alleleList);

        // create the genotypes; no-call everyone for now
        GenotypesContext genotypes = GenotypesContext.create();
        final int ploidy = UAC.genotypeArgs.samplePloidy;
        final List<Allele> noCall = GATKVariantContextUtils.noCallAlleles(ploidy);

        // For each sample, get genotype likelihoods based on pileup
        // compute prior likelihoods on haplotypes, and initialize haplotype likelihood matrix with them.

        for (Map.Entry<String, AlignmentContext> sample : contexts.entrySet()) {
            AlignmentContext context = AlignmentContextUtils.stratify(sample.getValue(), contextType);

            if (!perReadAlleleLikelihoodMap.containsKey(sample.getKey())){
                // no likelihoods have been computed for this sample at this site
                perReadAlleleLikelihoodMap.put(sample.getKey(), new PerReadAlleleLikelihoodMap());
            }
            final ReadBackedPileup pileup = context.getBasePileup();
            if (pileup != null) {
                final GenotypeBuilder b = new GenotypeBuilder(sample.getKey());
                final double[] genotypeLikelihoods = pairModel.computeDiploidReadHaplotypeLikelihoods(pileup, haplotypeMap, ref, eventLength, perReadAlleleLikelihoodMap.get(sample.getKey()), UAC.getSampleContamination().get(sample.getKey()));
                b.PL(genotypeLikelihoods);
                b.alleles(noCall);
                b.DP(getFilteredDepth(pileup));
                genotypes.add(b.make());

                if (DEBUG) {
                    System.out.format("Sample:%s Alleles:%s GL:", sample.getKey(), alleleList.toString());
                    for (int k = 0; k < genotypeLikelihoods.length; k++)
                        System.out.format("%1.4f ", genotypeLikelihoods[k]);
                    System.out.println();
                }
            }
        }

        return builder.genotypes(genotypes).make();
    }
 
开发者ID:PAA-NCIC,项目名称:SparkSeq,代码行数:67,代码来源:IndelGenotypeLikelihoodsCalculationModel.java

示例14: cleanupGenotypeAnnotations

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
private List<Genotype> cleanupGenotypeAnnotations(final VariantContext VC, final boolean createRefGTs) {
	final GenotypesContext oldGTs = VC.getGenotypes();
	final List<Genotype> recoveredGs = new ArrayList<>(oldGTs.size());
	for (final Genotype oldGT : oldGTs) {
		final Map<String, Object> attrs = new HashMap<>(oldGT.getExtendedAttributes());

		final GenotypeBuilder builder = new GenotypeBuilder(oldGT);
		int depth = oldGT.hasDP() ? oldGT.getDP() : 0;

		// move the MIN_DP to DP
		if (oldGT.hasExtendedAttribute(GaeaVCFConstants.MIN_DP_FORMAT_KEY)) {
			depth = Integer.parseInt((String) oldGT.getAnyAttribute(GaeaVCFConstants.MIN_DP_FORMAT_KEY));
			builder.DP(depth);
			attrs.remove(GaeaVCFConstants.MIN_DP_FORMAT_KEY);
		}

		// move the GQ to RGQ
		if (createRefGTs && oldGT.hasGQ()) {
			builder.noGQ();
			attrs.put(GaeaVCFConstants.REFERENCE_GENOTYPE_QUALITY, oldGT.getGQ());
		}

		// remove SB
		attrs.remove(GaeaVCFConstants.STRAND_BIAS_BY_SAMPLE_KEY);

		// update PGT for hom vars
		if (oldGT.isHomVar() && oldGT.hasExtendedAttribute(GaeaVCFConstants.HAPLOTYPE_CALLER_PHASING_GT_KEY)) {
			attrs.put(GaeaVCFConstants.HAPLOTYPE_CALLER_PHASING_GT_KEY, "1|1");
		}

		// create AD if it's not there
		if (!oldGT.hasAD() && VC.isVariant()) {
			final int[] AD = new int[VC.getNAlleles()];
			AD[0] = depth;
			builder.AD(AD);
		}

		if (createRefGTs) {
			final int ploidy = oldGT.getPloidy();
			final List<Allele> refAlleles = Collections.nCopies(ploidy, VC.getReference());

			// keep 0 depth samples and 0 GQ samples as no-call
			if (depth > 0 && oldGT.hasGQ() && oldGT.getGQ() > 0) {
				builder.alleles(refAlleles);
			}

			// also, the PLs are technically no longer usable
			builder.noPL();
		}

		recoveredGs.add(builder.noAttributes().attributes(attrs).make());
	}
	return recoveredGs;
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:55,代码来源:JointCallingEngine.java

示例15: subsetAlleles

import htsjdk.variant.variantcontext.GenotypeBuilder; //导入方法依赖的package包/类
@Override
@Requires("vc != null && allelesToUse != null")
public GenotypesContext subsetAlleles(VariantContext vc, int defaultPloidy, List<Allele> allelesToUse, boolean assignGenotypes) {
    // the genotypes with PLs
    final GenotypesContext oldGTs = vc.getGenotypes();

    // samples
    final List<String> sampleIndices = oldGTs.getSampleNamesOrderedByName();

    // the new genotypes to create
    final GenotypesContext newGTs = GenotypesContext.create();

    // we need to determine which of the alternate alleles (and hence the likelihoods) to use and carry forward
    final int numOriginalAltAlleles = vc.getAlternateAlleles().size();
    final int numNewAltAlleles = allelesToUse.size() - 1;


    // create the new genotypes
    for ( int k = 0; k < oldGTs.size(); k++ ) {
        final Genotype g = oldGTs.get(sampleIndices.get(k));
        final int declaredPloidy = g.getPloidy();
        final int ploidy = declaredPloidy <= 0 ? defaultPloidy : declaredPloidy;
        if ( !g.hasLikelihoods() ) {
            newGTs.add(GenotypeBuilder.create(g.getSampleName(),GaeaGvcfVariantContextUtils.noCallAlleles(ploidy)));
            continue;
        }

        // create the new likelihoods array from the alleles we are allowed to use
        final double[] originalLikelihoods = g.getLikelihoods().getAsVector();
        double[] newLikelihoods;

        // Optimization: if # of new alt alleles = 0 (pure ref call), keep original likelihoods so we skip normalization
        // and subsetting
        if ( numOriginalAltAlleles == numNewAltAlleles || numNewAltAlleles == 0) {
            newLikelihoods = originalLikelihoods;
        } else {
            newLikelihoods = GeneralPloidyGenotypeLikelihoods.subsetToAlleles(originalLikelihoods, ploidy, vc.getAlleles(), allelesToUse);

            // might need to re-normalize
            newLikelihoods = GvcfMathUtils.normalizeFromLog10(newLikelihoods, false, true);
        }

        // if there is no mass on the (new) likelihoods, then just no-call the sample
        if ( GvcfMathUtils.sum(newLikelihoods) > GaeaGvcfVariantContextUtils.SUM_GL_THRESH_NOCALL ) {
            newGTs.add(GenotypeBuilder.create(g.getSampleName(), GaeaGvcfVariantContextUtils.noCallAlleles(ploidy)));
        } else {
            final GenotypeBuilder gb = new GenotypeBuilder(g);
            final String sampleName = g.getSampleName();

            if ( numNewAltAlleles == 0 )
                gb.noPL();
            else
                gb.PL(newLikelihoods);

            // if we weren't asked to assign a genotype, then just no-call the sample
            if ( !assignGenotypes || GvcfMathUtils.sum(newLikelihoods) > GaeaGvcfVariantContextUtils.SUM_GL_THRESH_NOCALL )
                gb.alleles(GaeaGvcfVariantContextUtils.noCallAlleles(ploidy));
            else
                assignGenotype(gb, vc, sampleName, newLikelihoods, allelesToUse, ploidy);
            newGTs.add(gb.make());
        }
    }

    return GaeaGvcfVariantContextUtils.fixADFromSubsettedAlleles(newGTs, vc, allelesToUse);
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:66,代码来源:IndependentAllelesExactAFCalculator.java


注:本文中的htsjdk.variant.variantcontext.GenotypeBuilder.alleles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。