/** * Does the AD field have a value? * @return true if there's a AD field value */ public boolean hasAD() { return getAD() != null; }
/** * Does the AD field have a value? * @return true if there's a AD field value */ public boolean hasAD() { return getAD() != null; }
@Override public int[] getValues(final Genotype g) { return g.getAD(); } }
@Override public int[] getValues(final Genotype g) { return g.getAD(); } }
@Override public int[] getValues(final Genotype g) { return g.getAD(); } }
@Override public double getAlternativeAlleleFraction(Genotype gt) { int[] ads = gt.getAD(); if (ads == null) return 0.0; int sum = 0; for (int i = 1; i < ads.length; ++i) sum += ads[i]; return ((double) sum) / gt.getDP(); }
/** * Does the AD field have a value? * @return true if there's a AD field value */ @Ensures("(result == false && getAD() == null) || (result == true && getAD() != null)") public boolean hasAD() { return getAD() != null; }
@Override public double getAlleleFraction(Genotype gt, int alleleNo) { if (gt.getDP() == 0) return 0.0; else return ((double) gt.getAD()[alleleNo]) / gt.getDP(); }
/** * Fix the AD for the given Genotype * * @param genotype the original Genotype * @param alleleIndexesToUse a bitset describing whether or not to keep a given index * @return a non-null Genotype */ private static Genotype fixAD(final Genotype genotype, final BitSet alleleIndexesToUse) { // if it ain't broke don't fix it if ( !genotype.hasAD() ) return genotype; final GenotypeBuilder builder = new GenotypeBuilder(genotype); final int[] oldAD = genotype.getAD(); final int[] newAD = new int[alleleIndexesToUse.cardinality()]; int currentIndex = 0; for ( int i = alleleIndexesToUse.nextSetBit(0); i >= 0; i = alleleIndexesToUse.nextSetBit(i+1) ) { if ( i >= oldAD.length ) { throw new IllegalStateException("AD has " + oldAD.length + " items. It should have at least " + (i+1) + "."); } newAD[currentIndex++] = oldAD[i]; } return builder.AD(newAD).make(); }
@Override public String filter(final VariantContext ctx) { if (ctx.getHetCount() == 0) return null; final Map<List<Allele>, Counts> countsMap = new HashMap<List<Allele>, Counts>(); for (final Genotype gt : ctx.getGenotypesOrderedByName()) { if (gt.isNoCall() || !gt.isHet() || !gt.hasAD()) continue; final List<Allele> alleles = gt.getAlleles(); Counts counts = countsMap.get(alleles); if (counts == null) { counts = new Counts(); countsMap.put(alleles, counts); } counts.allele1 += gt.getAD()[ctx.getAlleleIndex(alleles.get(0))]; counts.allele2 += gt.getAD()[ctx.getAlleleIndex(alleles.get(1))]; } for (final Counts counts : countsMap.values()) { final int total = counts.allele1 + counts.allele2; if (total > 0 && Math.min(counts.allele1, counts.allele2) / (double) total < this.hetAlleleBalance) return AB_FILTER; } return null; } }
@Override public String filter(final VariantContext ctx) { if (ctx.getHetCount() == 0) return null; final Map<List<Allele>, Counts> countsMap = new HashMap<List<Allele>, Counts>(); for (final Genotype gt : ctx.getGenotypesOrderedByName()) { if (gt.isNoCall() || !gt.isHet() || !gt.hasAD()) continue; final List<Allele> alleles = gt.getAlleles(); Counts counts = countsMap.get(alleles); if (counts == null) { counts = new Counts(); countsMap.put(alleles, counts); } counts.allele1 += gt.getAD()[ctx.getAlleleIndex(alleles.get(0))]; counts.allele2 += gt.getAD()[ctx.getAlleleIndex(alleles.get(1))]; } for (final Counts counts : countsMap.values()) { final int total = counts.allele1 + counts.allele2; if (total > 0 && Math.min(counts.allele1, counts.allele2) / (double) total < this.hetAlleleBalance) return AB_FILTER; } return null; } }
private int getMaxCountInParents(VariantContext vc, String sampleName, Allele deNovoAllele) { final int alleleIdx = vc.getAlleleIndex(deNovoAllele); final Person person = this.pedigree.getNameToMember().get(sampleName).getPerson(); final Genotype gtFather = vc.getGenotype(person.getFather().getName()); final Genotype gtMother = vc.getGenotype(person.getMother().getName()); final int[] adFather = gtFather.getAD(); final int[] adMother = gtMother.getAD(); int result = 0; for (int[] ad : new int[][] {adFather, adMother}) { if (ad != null && ad.length > alleleIdx) { result = Math.max(result, ad[alleleIdx]); } } return result; }
@Override public Map<String, Object> finalizeRawData(VariantContext vc, VariantContext originalVC) { int totalAD = 0; for (final Genotype gt : vc.getGenotypes()){ if(gt != null) { if(gt.hasAD()) { totalAD += MathUtils.sum(gt.getAD()); continue; } // this is needed since the finalizing of HOM_REF genotypes comes after the finalizing of annotations. so the AD field is null at this point. // TODO: this will become unneeded if the above statement is false in which case it can be safely removed. if(gt.hasExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY)) { totalAD += Integer.parseInt((String) gt.getExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY)); } } } final int depth = vc.getAttributeAsInt(VCFConstants.DEPTH_KEY, 0); return Collections.singletonMap(GATKVCFConstants.FRACTION_INFORMATIVE_READS_KEY, (Object) (depth != 0 ? totalAD / (double) depth : 0)); }
public static void assertEquals(final GenotypesContext actual, final GenotypesContext expected) { if (expected == null) { Assert.assertNull(actual); return; } Assert.assertEquals(actual.getSampleNamesOrderedByName(), expected.getSampleNamesOrderedByName(), "Sample names differ"); for (final String name : expected.getSampleNamesOrderedByName()) { Assert.assertEquals(actual.get(name).getAlleles(), expected.get(name).getAlleles(), "Alleles differ for sample " + name); Assert.assertEquals(actual.get(name).getAD(), expected.get(name).getAD()); Assert.assertEquals(actual.get(name).getPL(), expected.get(name).getPL()); } }
public String toString() { return String.format("[%s %s%s%s%s%s%s%s]", getSampleName(), getGenotypeString(false), toStringIfExists(VCFConstants.GENOTYPE_QUALITY_KEY, getGQ()), toStringIfExists(VCFConstants.DEPTH_KEY, getDP()), toStringIfExists(VCFConstants.GENOTYPE_ALLELE_DEPTHS, getAD()), toStringIfExists(VCFConstants.GENOTYPE_PL_KEY, getPL()), toStringIfExists(VCFConstants.GENOTYPE_FILTER_KEY, getFilters()), sortedString(getExtendedAttributes())); }
public String toString() { return String.format("[%s %s%s%s%s%s%s%s]", getSampleName(), getGenotypeString(false), toStringIfExists(VCFConstants.GENOTYPE_QUALITY_KEY, getGQ()), toStringIfExists(VCFConstants.DEPTH_KEY, getDP()), toStringIfExists(VCFConstants.GENOTYPE_ALLELE_DEPTHS, getAD()), toStringIfExists(VCFConstants.GENOTYPE_PL_KEY, getPL()), toStringIfExists(VCFConstants.GENOTYPE_FILTER_KEY, getFilters()), sortedString(getExtendedAttributes())); }
public String toString() { return String.format("[%s %s%s%s%s%s%s%s]", getSampleName(), getGenotypeString(false), toStringIfExists(VCFConstants.GENOTYPE_QUALITY_KEY, getGQ()), toStringIfExists(VCFConstants.DEPTH_KEY, getDP()), toStringIfExists(VCFConstants.GENOTYPE_ALLELE_DEPTHS, getAD()), toStringIfExists(VCFConstants.GENOTYPE_PL_KEY, getPL()), toStringIfExists(VCFConstants.GENOTYPE_FILTER_KEY, getFilters()), sortedString(getExtendedAttributes())); }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }
/** * Copy all of the values for this builder from Genotype g * @param g * @return */ public GenotypeBuilder copy(final Genotype g) { name(g.getSampleName()); alleles(g.getAlleles()); phased(g.isPhased()); GQ(g.getGQ()); DP(g.getDP()); AD(g.getAD()); PL(g.getPL()); filter(g.getFilters()); attributes(g.getExtendedAttributes()); return this; }