本文整理汇总了Java中htsjdk.variant.variantcontext.GenotypesContext.get方法的典型用法代码示例。如果您正苦于以下问题:Java GenotypesContext.get方法的具体用法?Java GenotypesContext.get怎么用?Java GenotypesContext.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.variant.variantcontext.GenotypesContext
的用法示例。
在下文中一共展示了GenotypesContext.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getInstance
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* Returns a AF calculator capable to handle a particular variant-context.
* @param variantContext the target context build.
* @param defaultPloidy the assumed ploidy in case that there is no a GT call present to determine it.
* @return never {@code null}
*/
public AFCalculator getInstance(final VariantContext variantContext, final int defaultPloidy, final int maximumAltAlleles) {
if (variantContext == null)
throw new IllegalArgumentException("variant context cannot be null");
final int sampleCount = variantContext.getNSamples();
if (sampleCount == 0)
return getInstance(defaultPloidy,maximumAltAlleles);
final GenotypesContext genotypes = variantContext.getGenotypes();
final Genotype firstGenotype = genotypes.get(0);
int ploidy = firstGenotype.getPloidy();
if (ploidy <= 0) ploidy = defaultPloidy;
for (int i = 1 ; i < sampleCount; i++) {
final Genotype genotype = genotypes.get(i);
final int declaredPloidy = genotype.getPloidy();
final int actualPloidy = declaredPloidy <= 0 ? defaultPloidy : declaredPloidy;
if (actualPloidy != ploidy) {
ploidy = AFCalculatorImplementation.UNBOUND_PLOIDY;
break;
}
}
return getInstance(ploidy,Math.min(variantContext.getNAlleles() - 1, maximumAltAlleles));
}
示例3: 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
*/
public static GenotypesContext fixADFromSubsettedAlleles(final GenotypesContext originalGs,
final VariantContext originalVC, final List<Allele> allelesToUse) {
if (originalGs == null)
throw new IllegalArgumentException("the original Gs cannot be null");
if (originalVC == null)
throw new IllegalArgumentException("the original VC cannot be null");
if (allelesToUse == null)
throw new IllegalArgumentException("the alleles to use list cannot be null");
// the bitset representing the allele indexes we want to keep
final BitSet 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));
}
return newGTs;
}
示例4: getInstance
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* Returns a AF calculator capable to handle a particular variant-context.
* @param variantContext the target context build.
* @param defaultPloidy the assumed ploidy in case that there is no a GT call present to determine it.
* @return never {@code null}
*/
public AFCalculator getInstance(final VariantContext variantContext, final int defaultPloidy, final int maximumAltAlleles) {
Utils.nonNull(variantContext, "variant context cannot be null");
final int sampleCount = variantContext.getNSamples();
if (sampleCount == 0) {
return getInstance(defaultPloidy, maximumAltAlleles);
}
final GenotypesContext genotypes = variantContext.getGenotypes();
final Genotype firstGenotype = genotypes.get(0);
int ploidy = firstGenotype.getPloidy();
if (ploidy <= 0) {
ploidy = defaultPloidy;
}
for (int i = 1 ; i < sampleCount; i++) {
final Genotype genotype = genotypes.get(i);
final int declaredPloidy = genotype.getPloidy();
final int actualPloidy = declaredPloidy <= 0 ? defaultPloidy : declaredPloidy;
if (actualPloidy != ploidy) {
ploidy = AFCalculatorImplementation.UNBOUND_PLOIDY;
break;
}
}
return getInstance(ploidy, Math.min(variantContext.getNAlleles() - 1, maximumAltAlleles));
}
示例5: createGenotypesWithSubsettedLikelihoods
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
/**
* Create the new GenotypesContext with the subsetted PLs and ADs
*
* @param originalGs the original GenotypesContext
* @param vc the original VariantContext
* @param allelesToUse the actual alleles to use with the new Genotypes
* @param likelihoodIndexesToUse the indexes in the PL to use given the allelesToUse (@see #determineLikelihoodIndexesToUse())
* @param assignGenotypes assignment strategy for the (subsetted) PLs
* @return a new non-null GenotypesContext
*/
private static GenotypesContext createGenotypesWithSubsettedLikelihoods(final GenotypesContext originalGs,
final VariantContext vc,
final List<Allele> allelesToUse,
final List<Integer> likelihoodIndexesToUse,
final GenotypeAssignmentMethod assignGenotypes) {
// the new genotypes to create
final GenotypesContext newGTs = GenotypesContext.create(originalGs.size());
// make sure we are seeing the expected number of likelihoods per sample
final int expectedNumLikelihoods = GenotypeLikelihoods.numLikelihoods(vc.getNAlleles(), 2);
// 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));
final GenotypeBuilder gb = new GenotypeBuilder(g);
// create the new likelihoods array from the alleles we are allowed to use
double[] newLikelihoods;
if ( !g.hasLikelihoods() ) {
// we don't have any likelihoods, so we null out PLs and make G ./.
newLikelihoods = null;
gb.noPL();
} else {
final double[] originalLikelihoods = g.getLikelihoods().getAsVector();
if ( likelihoodIndexesToUse == null ) {
newLikelihoods = originalLikelihoods;
} else if ( originalLikelihoods.length != expectedNumLikelihoods ) {
newLikelihoods = null;
} else {
newLikelihoods = new double[likelihoodIndexesToUse.size()];
int newIndex = 0;
for ( final int oldIndex : likelihoodIndexesToUse )
newLikelihoods[newIndex++] = originalLikelihoods[oldIndex];
// might need to re-normalize
newLikelihoods = MathUtils.normalizeFromLog10(newLikelihoods, false, true);
}
if ( newLikelihoods == null || likelihoodsAreUninformative(newLikelihoods) )
gb.noPL();
else
gb.PL(newLikelihoods);
}
updateGenotypeAfterSubsetting(g.getAlleles(), gb, assignGenotypes, newLikelihoods, allelesToUse);
newGTs.add(gb.make());
}
return fixADFromSubsettedAlleles(newGTs, vc, allelesToUse);
}
示例6: 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 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;
}
示例7: subsetAlleles
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的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);
}
示例8: report
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
private void report(
final File f,
final VCFHeader header,
final VariantContext ctx,
final Mutation mpos
)
{
final GenotypesContext genotypes=ctx.getGenotypes();
if(genotypes==null || genotypes.isEmpty())
{
reportPos(f,header,ctx);
out.println();
}
else
{
VCFFormatHeaderLine DP4header = header.getFormatHeaderLine("DP4");
if(DP4header!=null &&
!( DP4header.getType().equals(VCFHeaderLineType.Integer) &&
DP4header.getCount()==4))
{
DP4header=null;
}
for(int i=0;i< genotypes.size();++i)
{
Genotype g=genotypes.get(i);
if(!g.isCalled() && this.hideNoCall) continue;
if(g.isHomRef() && this.hideHomRef) continue;
reportPos(f,header,ctx);
out.print('\t');
out.print(g.getSampleName());
out.print('\t');
out.print(g.getType());
out.print('\t');
List<Allele> alleles=g.getAlleles();
for(int na=0;na<alleles.size();++na)
{
if(na>0) out.print(" ");
out.print(alleles.get(na).getDisplayString());
}
if(DP4header!=null)
{
final Object dp4=g.getExtendedAttribute("DP4");
if(dp4!=null )
{
out.print('\t');
out.print(String.valueOf(dp4));//it's a String not an int[] ??
}
}
out.println();
}
}
}
示例9: doWork
import htsjdk.variant.variantcontext.GenotypesContext; //导入方法依赖的package包/类
@Override
public int doWork(final List<String> args)
{
PrintStream out = null;
VcfIterator in = null;
try
{
in = super.openVcfIterator(oneAndOnlyOneFile(args));
out = openFileOrStdoutAsPrintStream(outputFile);
out.println("CHR\tPOS\tID\tREF\tALT\tTOTAL_CNT\tALT_CNT\tFRQ");
while(in.hasNext() && !out.checkError())
{
final VariantContext ctx=in.next();
final Allele ref=ctx.getReference();
if(ref==null) continue;
if(ctx.getNSamples()==0 || ctx.getAlternateAlleles().isEmpty()) continue;
final Allele alt=ctx.getAltAlleleWithHighestAlleleCount();
if(alt==null) continue;
GenotypesContext genotypes=ctx.getGenotypes();
if(genotypes==null) continue;
int total_ctn=0;
int alt_ctn=0;
for(int i=0;i< genotypes.size();++i)
{
Genotype g=genotypes.get(i);
for(final Allele allele: g.getAlleles())
{
if(allele.equals(ref))
{
total_ctn++;
}
else if (allele.equals(alt))
{
total_ctn++;
alt_ctn++;
}
}
}
out.print(ctx.getContig());
out.print("\t");
out.print(ctx.getStart());
out.print("\t");
out.print(ctx.hasID()?ctx.getID():".");
out.print("\t");
out.print(ref.getBaseString());
out.print("\t");
out.print(alt.getBaseString());
out.print("\t");
out.print(total_ctn);
out.print("\t");
out.print(alt_ctn);
out.print("\t");
out.print(alt_ctn/(float)total_ctn);
out.println();
}
out.flush();
return RETURN_OK;
}
catch(Exception err)
{
LOG.error(err);
return -1;
}
finally
{
CloserUtil.close(out);
CloserUtil.close(in);
}
}