本文整理汇总了Java中htsjdk.variant.variantcontext.GenotypesContext.add方法的典型用法代码示例。如果您正苦于以下问题:Java GenotypesContext.add方法的具体用法?Java GenotypesContext.add怎么用?Java GenotypesContext.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.variant.variantcontext.GenotypesContext
的用法示例。
在下文中一共展示了GenotypesContext.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fixADFromSubsettedAlleles
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* Fix the AD for the GenotypesContext of a VariantContext that has been subset
*
* @param originalGs the original GenotypesContext
* @param originalVC the original VariantContext
* @param allelesToUse the new (sub)set of alleles to use
* @return a new non-null GenotypesContext
*/
static private GenotypesContext fixADFromSubsettedAlleles(final GenotypesContext originalGs, final VariantContext originalVC, final List<Allele> allelesToUse) {
// the bitset representing the allele indexes we want to keep
final boolean[] alleleIndexesToUse = getAlleleIndexBitset(originalVC, allelesToUse);
// the new genotypes to create
final GenotypesContext newGTs = GenotypesContext.create(originalGs.size());
// the samples
final List<String> sampleIndices = originalGs.getSampleNamesOrderedByName();
// create the new genotypes
for ( int k = 0; k < originalGs.size(); k++ ) {
final Genotype g = originalGs.get(sampleIndices.get(k));
newGTs.add(fixAD(g, alleleIndexesToUse, allelesToUse.size()));
}
return newGTs;
}
示例2: mergeGenotypes
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
private static void mergeGenotypes(GenotypesContext mergedGenotypes, VariantContext oneVC, AlleleMapper alleleMapping, boolean uniquifySamples) {
//TODO: should we add a check for cases when the genotypeMergeOption is REQUIRE_UNIQUE
for ( final Genotype g : oneVC.getGenotypes() ) {
final String name = mergedSampleName(oneVC.getSource(), g.getSampleName(), uniquifySamples);
if ( ! mergedGenotypes.containsSample(name) ) {
// only add if the name is new
Genotype newG = g;
if ( uniquifySamples || alleleMapping.needsRemapping() ) {
final List<Allele> alleles = alleleMapping.needsRemapping() ? alleleMapping.remap(g.getAlleles()) : g.getAlleles();
newG = new GenotypeBuilder(g).name(name).alleles(alleles).make();
}
mergedGenotypes.add(newG);
}
}
}
示例3: pruneVariantContext
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
public static VariantContextBuilder pruneVariantContext(final VariantContextBuilder builder, Collection<String> keysToPreserve ) {
final VariantContext vc = builder.make();
if ( keysToPreserve == null ) keysToPreserve = Collections.emptyList();
// VC info
final Map<String, Object> attributes = subsetAttributes(vc.getCommonInfo(), keysToPreserve);
// Genotypes
final GenotypesContext genotypes = GenotypesContext.create(vc.getNSamples());
for ( final Genotype g : vc.getGenotypes() ) {
final GenotypeBuilder gb = new GenotypeBuilder(g);
// remove AD, DP, PL, and all extended attributes, keeping just GT and GQ
gb.noAD().noDP().noPL().noAttributes();
genotypes.add(gb.make());
}
return builder.genotypes(genotypes).attributes(attributes);
}
示例4: purgeUnallowedGenotypeAttributes
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
public static VariantContext purgeUnallowedGenotypeAttributes(VariantContext vc, Set<String> allowedAttributes) {
if ( allowedAttributes == null )
return vc;
final GenotypesContext newGenotypes = GenotypesContext.create(vc.getNSamples());
for ( final Genotype genotype : vc.getGenotypes() ) {
final Map<String, Object> attrs = new HashMap<>();
for ( final Map.Entry<String, Object> attr : genotype.getExtendedAttributes().entrySet() ) {
if ( allowedAttributes.contains(attr.getKey()) )
attrs.put(attr.getKey(), attr.getValue());
}
newGenotypes.add(new GenotypeBuilder(genotype).attributes(attrs).make());
}
return new VariantContextBuilder(vc).genotypes(newGenotypes).make();
}
示例5: annotateGenotypes
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
private GenotypesContext annotateGenotypes(final RefMetaDataTracker tracker,
final ReferenceContext ref, final Map<String, AlignmentContext> stratifiedContexts,
final VariantContext vc,
final Map<String, PerReadAlleleLikelihoodMap> stratifiedPerReadAlleleLikelihoodMap) {
if (requestedGenotypeAnnotations.isEmpty())
return vc.getGenotypes();
final GenotypesContext genotypes = GenotypesContext.create(vc.getNSamples());
for (final Genotype genotype : vc.getGenotypes()) {
AlignmentContext context = null;
PerReadAlleleLikelihoodMap perReadAlleleLikelihoodMap = null;
if (stratifiedContexts != null)
context = stratifiedContexts.get(genotype.getSampleName());
if (stratifiedPerReadAlleleLikelihoodMap != null)
perReadAlleleLikelihoodMap = stratifiedPerReadAlleleLikelihoodMap.get(genotype.getSampleName());
final GenotypeBuilder gb = new GenotypeBuilder(genotype);
for (final GenotypeAnnotation annotation : requestedGenotypeAnnotations) {
annotation.annotate(tracker, walker, ref, context, vc, genotype, gb, perReadAlleleLikelihoodMap);
}
genotypes.add(gb.make());
}
return genotypes;
}
示例6: annotateGenotypes
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
private GenotypesContext annotateGenotypes(final RefMetaDataTracker tracker, final ChromosomeInformationShare ref, final VariantContext vc) {
if (requestedGenotypeAnnotations.isEmpty())
return vc.getGenotypes();
final GenotypesContext genotypes = GenotypesContext.create(vc.getNSamples());
for (final Genotype genotype : vc.getGenotypes()) {
final GenotypeBuilder gb = new GenotypeBuilder(genotype);
for (final GenotypeAnnotation annotation : requestedGenotypeAnnotations) {
annotation.annotate(tracker, ref, vc, genotype, gb);
}
genotypes.add(gb.make());
}
return genotypes;
}
示例7: pruneVariantContext
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
public static VariantContextBuilder pruneVariantContext(final VariantContextBuilder builder,
Collection<String> keysToPreserve) {
final VariantContext vc = builder.make();
if (keysToPreserve == null)
keysToPreserve = Collections.emptyList();
// VC info
final Map<String, Object> attributes = subsetAttributes(vc.getCommonInfo(), keysToPreserve);
// Genotypes
final GenotypesContext genotypes = GenotypesContext.create(vc.getNSamples());
for (final Genotype g : vc.getGenotypes()) {
final GenotypeBuilder gb = new GenotypeBuilder(g);
// remove AD, DP, PL, and all extended attributes, keeping just GT
// and GQ
gb.noAD().noDP().noPL().noAttributes();
genotypes.add(gb.make());
}
return builder.genotypes(genotypes).attributes(attributes);
}
示例8: purgeUnallowedGenotypeAttributes
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
public static VariantContext purgeUnallowedGenotypeAttributes(VariantContext vc, Set<String> allowedAttributes) {
if (allowedAttributes == null)
return vc;
final GenotypesContext newGenotypes = GenotypesContext.create(vc.getNSamples());
for (final Genotype genotype : vc.getGenotypes()) {
final Map<String, Object> attrs = new HashMap<>();
for (final Map.Entry<String, Object> attr : genotype.getExtendedAttributes().entrySet()) {
if (allowedAttributes.contains(attr.getKey()))
attrs.put(attr.getKey(), attr.getValue());
}
newGenotypes.add(new GenotypeBuilder(genotype).attributes(attrs).make());
}
return new VariantContextBuilder(vc).genotypes(newGenotypes).make();
}
示例9: subsetToRefOnly
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* Subset the samples in VC to reference only information with ref call alleles
*
* Preserves DP if present
*
* @param vc the variant context to subset down to
* @param ploidy ploidy to use if a genotype doesn't have any alleles
* @return a GenotypesContext
*/
public static GenotypesContext subsetToRefOnly(final VariantContext vc, final int ploidy) {
if ( vc == null ) throw new IllegalArgumentException("vc cannot be null");
if ( ploidy < 1 ) throw new IllegalArgumentException("ploidy must be >= 1 but got " + ploidy);
// the genotypes with PLs
final GenotypesContext oldGTs = vc.getGenotypes();
// optimization: if no input genotypes, just exit
if (oldGTs.isEmpty()) return oldGTs;
// the new genotypes to create
final GenotypesContext newGTs = GenotypesContext.create(oldGTs.size());
final Allele ref = vc.getReference();
final List<Allele> diploidRefAlleles = Arrays.asList(ref, ref);
// create the new genotypes
for ( final Genotype g : vc.getGenotypes() ) {
final int gPloidy = g.getPloidy() == 0 ? ploidy : g.getPloidy();
final List<Allele> refAlleles = gPloidy == 2 ? diploidRefAlleles : Collections.nCopies(gPloidy, ref);
final GenotypeBuilder gb = new GenotypeBuilder(g.getSampleName(), refAlleles);
if ( g.hasDP() ) gb.DP(g.getDP());
if ( g.hasGQ() ) gb.GQ(g.getGQ());
newGTs.add(gb.make());
}
return newGTs;
}
示例10: stripPLsAndAD
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
public static GenotypesContext stripPLsAndAD(final GenotypesContext genotypes) {
final GenotypesContext newGs = GenotypesContext.create(genotypes.size());
for ( final Genotype g : genotypes ) {
newGs.add(removePLsAndAD(g));
}
return newGs;
}
示例11: updateGenotypesWithMappedAlleles
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
protected static GenotypesContext updateGenotypesWithMappedAlleles(final GenotypesContext originalGenotypes, final AlleleMapper alleleMapper) {
final GenotypesContext updatedGenotypes = GenotypesContext.create(originalGenotypes.size());
for ( final Genotype genotype : originalGenotypes ) {
final List<Allele> updatedAlleles = alleleMapper.remap(genotype.getAlleles());
updatedGenotypes.add(new GenotypeBuilder(genotype).alleles(updatedAlleles).make());
}
return updatedGenotypes;
}
示例12: mergeRefConfidenceGenotypes
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* Merge into the context a new genotype represented by the given VariantContext for the provided list of target alleles.
* This method assumes that none of the alleles in the VC overlaps with any of the alleles in the set.
*
* @param mergedGenotypes the genotypes context to add to
* @param VC the Variant Context for the sample
* @param remappedAlleles the list of remapped alleles for the sample
* @param targetAlleles the list of target alleles
*/
private static void mergeRefConfidenceGenotypes(final GenotypesContext mergedGenotypes,
final VariantContext VC,
final List<Allele> remappedAlleles,
final List<Allele> targetAlleles) {
final int maximumPloidy = VC.getMaxPloidy(GATKVariantContextUtils.DEFAULT_PLOIDY);
// the map is different depending on the ploidy, so in order to keep this method flexible (mixed ploidies)
// we need to get a map done (lazily inside the loop) for each ploidy, up to the maximum possible.
final int[][] genotypeIndexMapsByPloidy = new int[maximumPloidy + 1][];
final int maximumAlleleCount = Math.max(remappedAlleles.size(),targetAlleles.size());
final int[] indexesOfRelevantAlleles = getIndexesOfRelevantAlleles(remappedAlleles, targetAlleles, VC.getStart());
for ( final Genotype g : VC.getGenotypes() ) {
final String name = g.getSampleName();
if ( mergedGenotypes.containsSample(name) )
continue;
final int ploidy = g.getPloidy();
final GenotypeBuilder genotypeBuilder = new GenotypeBuilder(g).alleles(GATKVariantContextUtils.noCallAlleles(g.getPloidy()));
if (g.hasPL()) {
// lazy initialization of the genotype index map by ploidy.
final int[] genotypeIndexMapByPloidy = genotypeIndexMapsByPloidy[ploidy] == null
? GenotypeLikelihoodCalculators.getInstance(ploidy, maximumAlleleCount).genotypeIndexMap(indexesOfRelevantAlleles)
: genotypeIndexMapsByPloidy[ploidy];
final int[] PLs = generatePL(g, genotypeIndexMapByPloidy);
final int[] AD = g.hasAD() ? generateAD(g.getAD(), indexesOfRelevantAlleles) : null;
genotypeBuilder.PL(PLs).AD(AD).noGQ();
}
mergedGenotypes.add(genotypeBuilder.make());
}
}
示例13: calculateGLsForThisEvent
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* For a particular event described in inputVC, form PL vector for each sample by looking into allele read map and filling likelihood matrix for each allele
* @param readLikelihoods Allele map describing mapping from reads to alleles and corresponding likelihoods
* @param mergedVC Input VC with event to genotype
* @return GenotypesContext object wrapping genotype objects with PLs
*/
private GenotypesContext calculateGLsForThisEvent( final ReadLikelihoods<Allele> readLikelihoods, final VariantContext mergedVC, final List<Allele> noCallAlleles ) {
final List<Allele> vcAlleles = mergedVC.getAlleles();
final AlleleList<Allele> alleleList = readLikelihoods.alleleCount() == vcAlleles.size() ? readLikelihoods : new IndexedAlleleList<>(vcAlleles);
final GenotypingLikelihoods<Allele> likelihoods = genotypingModel.calculateLikelihoods(alleleList,new GenotypingData<>(ploidyModel,readLikelihoods));
final int sampleCount = samples.sampleCount();
final GenotypesContext result = GenotypesContext.create(sampleCount);
for (int s = 0; s < sampleCount; s++)
result.add(new GenotypeBuilder(samples.sampleAt(s)).alleles(noCallAlleles).PL(likelihoods.sampleLikelihoods(s).getAsPLs()).make());
return result;
}
示例14: subsetAlleles
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* From a given variant context, extract a given subset of alleles, and update genotype context accordingly,
* including updating the PLs, ADs and SACs, 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, SACs and AD.
*/
@Override
public GenotypesContext subsetAlleles(final VariantContext vc, final int defaultPloidy,
final List<Allele> allelesToUse,
final boolean assignGenotypes) {
final GenotypesContext result = GenotypesContext.create();
// Subset genotypes for each sample
for (final Genotype g : vc.getGenotypes()) // If it really needs to process order by sample name do so.
result.add(subsetGenotypeAlleles(g, allelesToUse, vc, defaultPloidy, assignGenotypes));
return GaeaGvcfVariantContextUtils.fixADFromSubsettedAlleles(result, vc, allelesToUse);
}
示例15: subsetToRefOnly
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* Subset the samples in VC to reference only information with ref call
* alleles
*
* Preserves DP if present
*
* @param vc
* the variant context to subset down to
* @param ploidy
* ploidy to use if a genotype doesn't have any alleles
* @return a GenotypesContext
*/
public static GenotypesContext subsetToRefOnly(final VariantContext vc, final int ploidy) {
if (vc == null)
throw new IllegalArgumentException("vc cannot be null");
if (ploidy < 1)
throw new IllegalArgumentException("ploidy must be >= 1 but got " + ploidy);
// the genotypes with PLs
final GenotypesContext oldGTs = vc.getGenotypes();
// optimization: if no input genotypes, just exit
if (oldGTs.isEmpty())
return oldGTs;
// the new genotypes to create
final GenotypesContext newGTs = GenotypesContext.create(oldGTs.size());
final Allele ref = vc.getReference();
final List<Allele> diploidRefAlleles = Arrays.asList(ref, ref);
// create the new genotypes
for (final Genotype g : vc.getGenotypes()) {
final int gPloidy = g.getPloidy() == 0 ? ploidy : g.getPloidy();
final List<Allele> refAlleles = Collections.nCopies(gPloidy, vc.getReference());
final GenotypeBuilder gb = new GenotypeBuilder(g.getSampleName(), refAlleles);
if (g.hasDP())
gb.DP(g.getDP());
if (g.hasGQ())
gb.GQ(g.getGQ());
newGTs.add(gb.make());
}
return newGTs;
}