public boolean hasAnyAttribute(final String key) { if (key.equals(VCFConstants.GENOTYPE_KEY)) { return isAvailable(); } else if (key.equals(VCFConstants.GENOTYPE_QUALITY_KEY)) { return hasGQ(); } else if (key.equals(VCFConstants.GENOTYPE_ALLELE_DEPTHS)) { return hasAD(); } else if (key.equals(VCFConstants.GENOTYPE_PL_KEY)) { return hasPL(); } else if (key.equals(VCFConstants.DEPTH_KEY)) { return hasDP(); } else if (key.equals(VCFConstants.GENOTYPE_FILTER_KEY)) { return true; //always available } else { return hasExtendedAttribute(key); } }
public boolean hasAnyAttribute(final String key) { if (key.equals(VCFConstants.GENOTYPE_KEY)) { return isAvailable(); } else if (key.equals(VCFConstants.GENOTYPE_QUALITY_KEY)) { return hasGQ(); } else if (key.equals(VCFConstants.GENOTYPE_ALLELE_DEPTHS)) { return hasAD(); } else if (key.equals(VCFConstants.GENOTYPE_PL_KEY)) { return hasPL(); } else if (key.equals(VCFConstants.DEPTH_KEY)) { return hasDP(); } else { return hasExtendedAttribute(key); } }
public boolean hasAnyAttribute(final String key) { if (key.equals(VCFConstants.GENOTYPE_KEY)) { return isAvailable(); } else if (key.equals(VCFConstants.GENOTYPE_QUALITY_KEY)) { return hasGQ(); } else if (key.equals(VCFConstants.GENOTYPE_ALLELE_DEPTHS)) { return hasAD(); } else if (key.equals(VCFConstants.GENOTYPE_PL_KEY)) { return hasPL(); } else if (key.equals(VCFConstants.DEPTH_KEY)) { return hasDP(); } else if (key.equals(VCFConstants.GENOTYPE_FILTER_KEY)) { return true; //always available } else { return hasExtendedAttribute(key); } }
if ( targetAllele == Allele.SPAN_DEL && g.hasPL() ) { final int occurrences = Collections.frequency(remappedAlleles, Allele.SPAN_DEL); if ( occurrences > 1 ) {
/** * Add information from this Genotype to this band * @param g a non-null Genotype with GQ and DP attributes */ public void add(final int pos, final Genotype g) { if ( g == null ) throw new IllegalArgumentException("g cannot be null"); if ( ! g.hasGQ() ) throw new IllegalArgumentException("g must have GQ field"); if ( ! g.hasPL() ) throw new IllegalArgumentException("g must have PL field"); if ( pos != stop + 1 ) throw new IllegalArgumentException("adding genotype at pos " + pos + " isn't contiguous with previous stop " + stop); if ( g.getPloidy() != ploidy) throw new IllegalArgumentException("cannot add a genotype with a different ploidy: " + g.getPloidy() + " != " + ploidy); if( minPLs == null ) minPLs = g.getPL(); else { // otherwise take the min with the provided genotype's PLs final int[] PL = g.getPL(); if (PL.length != minPLs.length) throw new IllegalStateException("trying to merge different PL array sizes: " + PL.length + " != " + minPLs.length); for (int i = 0; i < PL.length; i++) if (minPLs[i] > PL[i]) minPLs[i] = PL[i]; } stop = pos; GQs.add(Math.min(g.getGQ(), 99)); // cap the GQs by the max. of 99 emission DPs.add(Math.max(g.getDP(),0)); }
if ( g.hasDP() ) sawDP = true; if ( g.hasAD() ) sawAD = true; if ( g.hasPL() ) sawPL = true; if (g.isFiltered()) sawGenotypeFilter = true;
if ( g.hasDP() ) sawDP = true; if ( g.hasAD() ) sawAD = true; if ( g.hasPL() ) sawPL = true; if (g.isFiltered()) sawGenotypeFilter = true;
if ( g.hasDP() ) sawDP = true; if ( g.hasAD() ) sawAD = true; if ( g.hasPL() ) sawPL = true; if (g.isFiltered()) sawGenotypeFilter = true;
public VCFGenotype(Genotype wrappedGenotype) { vcfGenotype = wrappedGenotype; attributes = new HashMap<String, Object>(); if (vcfGenotype.hasDP()) { attributes.put("DP", vcfGenotype.getDP()); } if (vcfGenotype.hasAD()) { String adString = ""; int[] ad = vcfGenotype.getAD(); for (int i = 0; i < ad.length; i++) { if (i != 0) adString += ","; adString += String.valueOf(ad[i]); } attributes.put("AD", adString); } if (vcfGenotype.hasGQ()) { attributes.put("GQ", vcfGenotype.getGQ()); } if (vcfGenotype.hasPL()) { String plString = ""; int[] pl = vcfGenotype.getPL(); for (int i = 0; i < pl.length; i++) { if (i != 0) plString += ","; plString += String.valueOf(pl[i]); } attributes.put("PL", plString); } attributes.putAll(vcfGenotype.getExtendedAttributes()); }
if (hasPL()) { final List<Integer> intList = new ArrayList<Integer>(getPL().length); for(int i : getPL()) intList.add(i);
if (hasPL()) { final List<Integer> intList = new ArrayList<Integer>(getPL().length); for(int i : getPL()) intList.add(i);
private boolean genotypeCanBeMergedInCurrentBlock(final Genotype g) { return currentBlock != null && currentBlock.withinBounds(capToMaxGQ(g.getGQ())) && currentBlock.getPloidy() == g.getPloidy() && (currentBlock.getMinPLs() == null || !g.hasPL() || (currentBlock.getMinPLs().length == g.getPL().length)); }
private void assertGoodVC(final VariantContext vc, final String contig, final int start, final int stop, final boolean nonRef) { Assert.assertEquals(vc.getChr(), contig); Assert.assertEquals(vc.getStart(), start); Assert.assertEquals(vc.getEnd(), stop); if ( nonRef ) { Assert.assertNotEquals(vc.getAlternateAllele(0), GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE); } else { Assert.assertEquals(vc.getNAlleles(), 2); Assert.assertEquals(vc.getAlternateAllele(0), GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE); Assert.assertEquals(vc.getAttributeAsInt(VCFConstants.END_KEY, -1), stop); Assert.assertTrue(vc.hasGenotypes()); Assert.assertTrue(vc.hasGenotype(SAMPLE_NAME)); Assert.assertEquals(vc.getGenotypes().size(), 1); final Genotype g = vc.getGenotype(SAMPLE_NAME); Assert.assertEquals(g.hasAD(), false); Assert.assertEquals(g.hasLikelihoods(), true); Assert.assertEquals(g.hasPL(), true); Assert.assertEquals(g.getPL().length == 3, true); Assert.assertEquals(g.hasDP(), true); Assert.assertEquals(g.hasGQ(), true); } }
@Override protected void reduceScopeCalculateLikelihoodSums(final VariantContext vc, final int defaultPloidy, final LikelihoodSum[] likelihoodSums) { final int numOriginalAltAlleles = likelihoodSums.length; final GenotypesContext genotypes = vc.getGenotypes(); for ( final Genotype genotype : genotypes.iterateInSampleNameOrder() ) { if (!genotype.hasPL()) continue; final double[] gls = genotype.getLikelihoods().getAsVector(); if (MathUtils.sum(gls) >= GATKVariantContextUtils.SUM_GL_THRESH_NOCALL) continue; final int PLindexOfBestGL = MathUtils.maxElementIndex(gls); final double bestToHomRefDiffGL = PLindexOfBestGL == PL_INDEX_OF_HOM_REF ? 0.0 : gls[PLindexOfBestGL] - gls[PL_INDEX_OF_HOM_REF]; final int declaredPloidy = genotype.getPloidy(); final int ploidy = declaredPloidy <= 0 ? defaultPloidy : declaredPloidy; final int[] acCount = GeneralPloidyGenotypeLikelihoods.getAlleleCountFromPLIndex(1 + numOriginalAltAlleles, ploidy, PLindexOfBestGL); // by convention, first count coming from getAlleleCountFromPLIndex comes from reference allele for (int k=1; k < acCount.length;k++) if (acCount[k] > 0 ) likelihoodSums[k-1].sum += acCount[k] * bestToHomRefDiffGL; } }
public static void assertGenotypesAreEqual(final Genotype actual, final Genotype expected) { Assert.assertEquals(actual.getSampleName(), expected.getSampleName(), "Genotype names"); Assert.assertEquals(actual.getAlleles(), expected.getAlleles(), "Genotype alleles"); Assert.assertEquals(actual.getGenotypeString(), expected.getGenotypeString(), "Genotype string"); Assert.assertEquals(actual.getType(), expected.getType(), "Genotype type"); // filters are the same Assert.assertEquals(actual.getFilters(), expected.getFilters(), "Genotype fields"); Assert.assertEquals(actual.isFiltered(), expected.isFiltered(), "Genotype isFiltered"); // inline attributes Assert.assertEquals(actual.getDP(), expected.getDP(), "Genotype dp"); Assert.assertTrue(Arrays.equals(actual.getAD(), expected.getAD())); Assert.assertEquals(actual.getGQ(), expected.getGQ(), "Genotype gq"); Assert.assertEquals(actual.hasPL(), expected.hasPL(), "Genotype hasPL"); Assert.assertEquals(actual.hasAD(), expected.hasAD(), "Genotype hasAD"); Assert.assertEquals(actual.hasGQ(), expected.hasGQ(), "Genotype hasGQ"); Assert.assertEquals(actual.hasDP(), expected.hasDP(), "Genotype hasDP"); Assert.assertEquals(actual.hasLikelihoods(), expected.hasLikelihoods(), "Genotype haslikelihoods"); Assert.assertEquals(actual.getLikelihoodsString(), expected.getLikelihoodsString(), "Genotype getlikelihoodsString"); Assert.assertEquals(actual.getLikelihoods(), expected.getLikelihoods(), "Genotype getLikelihoods"); Assert.assertTrue(Arrays.equals(actual.getPL(), expected.getPL())); Assert.assertEquals(actual.getPhredScaledQual(), expected.getPhredScaledQual(), "Genotype phredScaledQual"); assertAttributesEquals(actual.getExtendedAttributes(), expected.getExtendedAttributes()); Assert.assertEquals(actual.isPhased(), expected.isPhased(), "Genotype isPhased"); Assert.assertEquals(actual.getPloidy(), expected.getPloidy(), "Genotype getPloidy"); }
@Override @Requires("vc != null && likelihoodSums != null") protected void reduceScopeCalculateLikelihoodSums(final VariantContext vc, final int defaultPloidy, final LikelihoodSum[] likelihoodSums) { final int numOriginalAltAlleles = likelihoodSums.length; final GenotypesContext genotypes = vc.getGenotypes(); for ( final Genotype genotype : genotypes.iterateInSampleNameOrder() ) { if (!genotype.hasPL()) continue; final double[] gls = genotype.getLikelihoods().getAsVector(); if (MathUtils.sum(gls) >= GATKVariantContextUtils.SUM_GL_THRESH_NOCALL) continue; final int PLindexOfBestGL = MathUtils.maxElementIndex(gls); final double bestToHomRefDiffGL = PLindexOfBestGL == PL_INDEX_OF_HOM_REF ? 0.0 : gls[PLindexOfBestGL] - gls[PL_INDEX_OF_HOM_REF]; final int declaredPloidy = genotype.getPloidy(); final int ploidy = declaredPloidy <= 0 ? defaultPloidy : declaredPloidy; final int[] acCount = GeneralPloidyGenotypeLikelihoods.getAlleleCountFromPLIndex(1 + numOriginalAltAlleles, ploidy, PLindexOfBestGL); // by convention, first count coming from getAlleleCountFromPLIndex comes from reference allele for (int k=1; k < acCount.length;k++) if (acCount[k] > 0 ) likelihoodSums[k-1].sum += acCount[k] * bestToHomRefDiffGL; } }
public static void assertEquals(final Genotype actual, final Genotype expected) { Assert.assertEquals(actual.getSampleName(), expected.getSampleName(), "Genotype names"); Assert.assertEquals(actual.getAlleles(), expected.getAlleles(), "Genotype alleles"); Assert.assertEquals(actual.getGenotypeString(), expected.getGenotypeString(), "Genotype string"); Assert.assertEquals(actual.getType(), expected.getType(), "Genotype type"); // filters are the same Assert.assertEquals(actual.getFilters(), expected.getFilters(), "Genotype fields"); Assert.assertEquals(actual.isFiltered(), expected.isFiltered(), "Genotype isFiltered"); // inline attributes Assert.assertEquals(actual.getDP(), expected.getDP(), "Genotype dp"); Assert.assertTrue(Arrays.equals(actual.getAD(), expected.getAD())); Assert.assertEquals(actual.getGQ(), expected.getGQ(), "Genotype gq"); Assert.assertEquals(actual.hasPL(), expected.hasPL(), "Genotype hasPL"); Assert.assertEquals(actual.hasAD(), expected.hasAD(), "Genotype hasAD"); Assert.assertEquals(actual.hasGQ(), expected.hasGQ(), "Genotype hasGQ"); Assert.assertEquals(actual.hasDP(), expected.hasDP(), "Genotype hasDP"); Assert.assertEquals(actual.hasLikelihoods(), expected.hasLikelihoods(), "Genotype haslikelihoods"); Assert.assertEquals(actual.getLikelihoodsString(), expected.getLikelihoodsString(), "Genotype getlikelihoodsString"); Assert.assertEquals(actual.getLikelihoods(), expected.getLikelihoods(), "Genotype getLikelihoods"); Assert.assertTrue(Arrays.equals(actual.getPL(), expected.getPL())); Assert.assertEquals(actual.getGQ(), expected.getGQ(), "Genotype phredScaledQual"); assertAttributesEquals(actual.getExtendedAttributes(), expected.getExtendedAttributes()); Assert.assertEquals(actual.isPhased(), expected.isPhased(), "Genotype isPhased"); Assert.assertEquals(actual.getPloidy(), expected.getPloidy(), "Genotype getPloidy"); }
Assert.assertTrue(Arrays.equals(actual.getAD(), expected.getAD())); Assert.assertEquals(actual.getGQ(), expected.getGQ(), "Genotype gq"); Assert.assertEquals(actual.hasPL(), expected.hasPL(), "Genotype hasPL"); Assert.assertEquals(actual.hasAD(), expected.hasAD(), "Genotype hasAD"); Assert.assertEquals(actual.hasGQ(), expected.hasGQ(), "Genotype hasGQ");
final PerReadAlleleLikelihoodMap alleleLikelihoodMap) { if (!g.hasPL()) return; final int[] PL = g.getPL();
if (!genotype.hasPL()) continue; final double[] gls = genotype.getLikelihoods().getAsVector();