本文整理汇总了Java中htsjdk.variant.variantcontext.GenotypesContext.create方法的典型用法代码示例。如果您正苦于以下问题:Java GenotypesContext.create方法的具体用法?Java GenotypesContext.create怎么用?Java GenotypesContext.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.variant.variantcontext.GenotypesContext
的用法示例。
在下文中一共展示了GenotypesContext.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subsetDiploidAlleles
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* subset the Variant Context to the specific set of alleles passed in (pruning the PLs appropriately)
*
* @param vc variant context with genotype likelihoods
* @param allelesToUse which alleles from the vc are okay to use; *** must be in the same relative order as those in the original VC ***
* @param assignGenotypes assignment strategy for the (subsetted) PLs
* @return a new non-null GenotypesContext
*/
public static GenotypesContext subsetDiploidAlleles(final VariantContext vc,
final List<Allele> allelesToUse,
final GenotypeAssignmentMethod assignGenotypes) {
if ( allelesToUse.get(0).isNonReference() ) throw new IllegalArgumentException("First allele must be the reference allele");
if ( allelesToUse.size() == 1 ) throw new IllegalArgumentException("Cannot subset to only 1 alt allele");
// optimization: if no input genotypes, just exit
if (vc.getGenotypes().isEmpty()) return GenotypesContext.create();
// we need to determine which of the alternate alleles (and hence the likelihoods) to use and carry forward
final List<Integer> likelihoodIndexesToUse = determineLikelihoodIndexesToUse(vc, allelesToUse);
// create the new genotypes
return createGenotypesWithSubsettedLikelihoods(vc.getGenotypes(), vc, allelesToUse, likelihoodIndexesToUse, assignGenotypes);
}
示例2: 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;
}
示例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: 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;
}
示例13: 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);
}
示例14: subsetAlleles
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* Subset the Variant Context to the specific set of alleles passed in
* (pruning the PLs appropriately)
*
* @param vc
* variant context with genotype likelihoods
* @param allelesToUse
* which alleles from the vc are okay to use; *** must be in the
* same relative order as those in the original VC ***
* @param assignGenotypes
* assignment strategy for the (subsetted) PLs
* @return a new non-null GenotypesContext
*/
public static GenotypesContext subsetAlleles(final VariantContext vc, final List<Allele> allelesToUse,
final GenotypeAssignmentMethod assignGenotypes) {
if (vc == null)
throw new IllegalArgumentException("the VariantContext cannot be null");
if (allelesToUse == null)
throw new IllegalArgumentException("the alleles to use cannot be null");
if (allelesToUse.isEmpty())
throw new IllegalArgumentException("must have alleles to use");
if (allelesToUse.get(0).isNonReference())
throw new IllegalArgumentException("First allele must be the reference allele");
if (allelesToUse.size() == 1)
throw new IllegalArgumentException("Cannot subset to only 1 alt allele");
// optimization: if no input genotypes, just exit
if (vc.getGenotypes().isEmpty())
return GenotypesContext.create();
// find the likelihoods indexes to use from the used alternate alleles
//final List<Integer> likelihoodIndexesToUse = determineDiploidLikelihoodIndexesToUse(vc, allelesToUse);
final List<List<Integer>> likelihoodIndexesToUse = determineLikelihoodIndexesToUse(vc, allelesToUse);
// find the strand allele count indexes to use from the used alternate
// alleles
final List<Integer> sacIndexesToUse = determineSACIndexesToUse(vc, allelesToUse);
// create the new genotypes
return createGenotypesWithSubsettedLikelihoods(vc.getGenotypes(), vc, allelesToUse, likelihoodIndexesToUse,
sacIndexesToUse, assignGenotypes);
}
示例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;
}