/** * This is just a safe wrapper around GenotypeLikelihoods.calculatePLindex() * * @param originalIndex1 the index of the first allele * @param originalIndex2 the index of the second allele * @return the PL index */ protected static int calculatePLindexFromUnorderedIndexes(final int originalIndex1, final int originalIndex2) { // we need to make sure they are ordered correctly return ( originalIndex2 < originalIndex1 ) ? GenotypeLikelihoods.calculatePLindex(originalIndex2, originalIndex1) : GenotypeLikelihoods.calculatePLindex(originalIndex1, originalIndex2); }
/** * get the PL indexes (AA, AB, BB) for the given allele pair; assumes allele1Index <= allele2Index. * * @param allele1Index the index in VariantContext.getAllele() of the first allele * @param allele2Index the index in VariantContext.getAllele() of the second allele * @return the PL indexes */ public static int[] getPLIndecesOfAlleles(final int allele1Index, final int allele2Index) { final int[] indexes = new int[3]; indexes[0] = calculatePLindex(allele1Index, allele1Index); indexes[1] = calculatePLindex(allele1Index, allele2Index); indexes[2] = calculatePLindex(allele2Index, allele2Index); return indexes; } }
/** * get the PL indices (AA, AB, BB) for the given allele pair; assumes allele1Index <= allele2Index. * * @param allele1Index the index in VariantContext.getAllele() of the first allele * @param allele2Index the index in VariantContext.getAllele() of the second allele * @return the PL indexes */ public static int[] getPLIndicesOfAlleles(final int allele1Index, final int allele2Index) { final int[] indexes = new int[3]; indexes[0] = calculatePLindex(allele1Index, allele1Index); indexes[1] = calculatePLindex(allele1Index, allele2Index); indexes[2] = calculatePLindex(allele2Index, allele2Index); return indexes; } }
/** * get the PL indices (AA, AB, BB) for the given allele pair; assumes allele1Index <= allele2Index. * * @param allele1Index the index in VariantContext.getAllele() of the first allele * @param allele2Index the index in VariantContext.getAllele() of the second allele * @return the PL indexes */ public static int[] getPLIndicesOfAlleles(final int allele1Index, final int allele2Index) { final int[] indexes = new int[3]; indexes[0] = calculatePLindex(allele1Index, allele1Index); indexes[1] = calculatePLindex(allele1Index, allele2Index); indexes[2] = calculatePLindex(allele2Index, allele2Index); return indexes; } }
private double getLog10GQ(List<Allele> genotypeAlleles,List<Allele> contextAlleles) { int allele1Index = contextAlleles.indexOf(genotypeAlleles.get(0)); int allele2Index = contextAlleles.indexOf(genotypeAlleles.get(1)); int plIndex = calculatePLindex(allele1Index,allele2Index); return getGQLog10FromLikelihoods(plIndex,getAsVector()); }
private double getLog10GQ(List<Allele> genotypeAlleles,List<Allele> contextAlleles) { int allele1Index = contextAlleles.indexOf(genotypeAlleles.get(0)); int allele2Index = contextAlleles.indexOf(genotypeAlleles.get(1)); int plIndex = calculatePLindex(allele1Index,allele2Index); return getGQLog10FromLikelihoods(plIndex,getAsVector()); }
@Requires({"genotypeAlleles != null","genotypeAlleles.size()==2","contextAlleles != null","contextAlleles.size() >= 1"}) private double getLog10GQ(List<Allele> genotypeAlleles,List<Allele> contextAlleles) { int allele1Index = contextAlleles.indexOf(genotypeAlleles.get(0)); int allele2Index = contextAlleles.indexOf(genotypeAlleles.get(1)); int plIndex = calculatePLindex(allele1Index,allele2Index); return getGQLog10FromLikelihoods(plIndex,getAsVector()); }
/** * Given a list of original alleles and a subset of new alleles to retain, find the array of old PL indices that correspond * to new PL indices i.e. result[7] = old PL index of genotype containing same alleles as the new genotype with PL index 7. * <p> * This method is written in terms f indices rather than subsetting PLs directly in order to produce output that can be * recycled from sample to sample, provided that the ploidy is the same. * * @param originalAlleles List of original alleles * @param newAlleles New alleles -- must be a subset of {@code originalAlleles} * @return old PL indices of new genotypes */ public static int[] subsettedPLIndices(final List<Allele> originalAlleles, final List<Allele> newAlleles) { final int[] result = new int[GenotypeLikelihoods.numLikelihoods(newAlleles.size(), 2)]; for (int oldPLIndex = 0; oldPLIndex < GenotypeLikelihoods.numLikelihoods(originalAlleles.size(), 2); oldPLIndex++) { final GenotypeLikelihoods.GenotypeLikelihoodsAllelePair allelePairFromPLIndex = GenotypeLikelihoods.getAllelePair(oldPLIndex); final Allele allele1 = originalAlleles.get(allelePairFromPLIndex.alleleIndex1); final Allele allele2 = originalAlleles.get(allelePairFromPLIndex.alleleIndex2); final boolean containsOnlyNewAlleles = newAlleles.contains(allele1) && newAlleles.contains(allele2); if (containsOnlyNewAlleles) { // thus we want this PL...but we need to figure out where its new index is.... final int newPLIndex = GenotypeLikelihoods.calculatePLindex(newAlleles.indexOf(allele1), newAlleles.indexOf(allele2)); result[newPLIndex] = oldPLIndex; } } return result; }
@Test public void testCalculatePLindex(){ int counter = 0; for ( int i = 0; i <= 3; i++ ) { for ( int j = i; j <= 3; j++ ) { Assert.assertEquals(GenotypeLikelihoods.calculatePLindex(i, j), GenotypeLikelihoods.PLindexConversion[counter++], "PL index of alleles " + i + "," + j + " was not calculated correctly"); } } }
private static GenotypeLikelihoodsAllelePair[] calculatePLcache(final int altAlleles) { final int numLikelihoods = numLikelihoods(1 + altAlleles, 2); final GenotypeLikelihoodsAllelePair[] cache = new GenotypeLikelihoodsAllelePair[numLikelihoods]; // for all possible combinations of 2 alleles for ( int allele1 = 0; allele1 <= altAlleles; allele1++ ) { for ( int allele2 = allele1; allele2 <= altAlleles; allele2++ ) { cache[calculatePLindex(allele1, allele2)] = new GenotypeLikelihoodsAllelePair(allele1, allele2); } } // a bit of sanity checking for ( int i = 0; i < cache.length; i++ ) { if ( cache[i] == null ) throw new IllegalStateException("BUG: cache entry " + i + " is unexpected null"); } return cache; }
/** * Given a list of original alleles and a subset of new alleles to retain, find the array of old PL indices that correspond * to new PL indices i.e. result[7] = old PL index of genotype containing same alleles as the new genotype with PL index 7. * <p> * This method is written in terms f indices rather than subsetting PLs directly in order to produce output that can be * recycled from sample to sample, provided that the ploidy is the same. * * @param originalAlleles List of original alleles * @param newAlleles New alleles -- must be a subset of {@code originalAlleles} * @return old PL indices of new genotypes */ public static int[] subsettedPLIndices(final List<Allele> originalAlleles, final List<Allele> newAlleles) { final int[] result = new int[GenotypeLikelihoods.numLikelihoods(newAlleles.size(), 2)]; for (int oldPLIndex = 0; oldPLIndex < GenotypeLikelihoods.numLikelihoods(originalAlleles.size(), 2); oldPLIndex++) { final GenotypeLikelihoods.GenotypeLikelihoodsAllelePair allelePairFromPLIndex = GenotypeLikelihoods.getAllelePair(oldPLIndex); final Allele allele1 = originalAlleles.get(allelePairFromPLIndex.alleleIndex1); final Allele allele2 = originalAlleles.get(allelePairFromPLIndex.alleleIndex2); final boolean containsOnlyNewAlleles = newAlleles.contains(allele1) && newAlleles.contains(allele2); if (containsOnlyNewAlleles) { // thus we want this PL...but we need to figure out where its new index is.... final int newPLIndex = GenotypeLikelihoods.calculatePLindex(newAlleles.indexOf(allele1), newAlleles.indexOf(allele2)); result[newPLIndex] = oldPLIndex; } } return result; }
public Genotype makePL(final GenotypeType type, final int nonTypePL, final int altI) { GenotypeBuilder gb = new GenotypeBuilder("sample" + sampleNameCounter++); gb.alleles(getAlleles(type, altI)); final int[] pls = new int[numPLs()]; Arrays.fill(pls, nonTypePL); int index = 0; switch ( type ) { case HOM_REF: index = GenotypeLikelihoods.calculatePLindex(0, 0); break; case HET: index = GenotypeLikelihoods.calculatePLindex(0, altI); break; case HOM_VAR: index = GenotypeLikelihoods.calculatePLindex(altI, altI); break; } pls[index] = 0; gb.PL(pls); return gb.make(); } }
/** * Calculate the cache of diploid alleles for each PL index * * @param altAlleles number of alternate alleles * @return cache of diploid alleles for each PL index */ private static GenotypeLikelihoodsAllelePair[] calculateDiploidPLcache(final int altAlleles) { final int numLikelihoods = numLikelihoods(1 + altAlleles, 2); final GenotypeLikelihoodsAllelePair[] cache = new GenotypeLikelihoodsAllelePair[numLikelihoods]; // for all possible combinations of 2 alleles for ( int allele1 = 0; allele1 <= altAlleles; allele1++ ) { for ( int allele2 = allele1; allele2 <= altAlleles; allele2++ ) { cache[calculatePLindex(allele1, allele2)] = new GenotypeLikelihoodsAllelePair(allele1, allele2); } } // a bit of sanity checking for ( int i = 0; i < cache.length; i++ ) { if ( cache[i] == null ) throw new IllegalStateException("BUG: cache entry " + i + " is unexpected null"); } return cache; }
/** * Calculate the cache of diploid alleles for each PL index * * @param altAlleles number of alternate alleles * @return cache of diploid alleles for each PL index */ private static GenotypeLikelihoodsAllelePair[] calculateDiploidPLcache(final int altAlleles) { final int numLikelihoods = numLikelihoods(1 + altAlleles, 2); final GenotypeLikelihoodsAllelePair[] cache = new GenotypeLikelihoodsAllelePair[numLikelihoods]; // for all possible combinations of 2 alleles for ( int allele1 = 0; allele1 <= altAlleles; allele1++ ) { for ( int allele2 = allele1; allele2 <= altAlleles; allele2++ ) { cache[calculatePLindex(allele1, allele2)] = new GenotypeLikelihoodsAllelePair(allele1, allele2); } } // a bit of sanity checking for ( int i = 0; i < cache.length; i++ ) { if ( cache[i] == null ) throw new IllegalStateException("BUG: cache entry " + i + " is unexpected null"); } return cache; }
alleleCounts.put(a, currentAlleleCounts + 2*normalizedLikelihoods[GenotypeLikelihoods.calculatePLindex(altIndex,altIndex)]); continue; idxAB = GenotypeLikelihoods.calculatePLindex(Math.min(i,altIndex),Math.max(i,altIndex)); final double aHetCounts = hetCounts.get(a); hetCounts.put(a, aHetCounts + normalizedLikelihoods[idxAB]);
ACcountsClone[allele]++; final int PLindex = GenotypeLikelihoods.calculatePLindex(0, allele+1); updateACset(ACcountsClone, numChr, set, PLindex, ACqueue, indexesToACset, genotypeLikelihoods); final int PLindex = GenotypeLikelihoods.calculatePLindex(allele_i+1, allele_j+1); if ( allele_i == allele_j ) sameAlleles.add(new DependentSet(ACcountsClone, PLindex));