/** * Is key associated with a value (even a null one) in the extended attributes? * * Note this will not return true for the inline attributes DP, GQ, AD, or PL * * @param key a non-null string key to check for an association * @return true if key has a value in the extendedAttributes */ public boolean hasExtendedAttribute(final String key) { return getExtendedAttributes().containsKey(key); }
/** * Is key associated with a value (even a null one) in the extended attributes? * * Note this will not return true for the inline attributes DP, GQ, AD, or PL * * @param key a non-null string key to check for an association * @return true if key has a value in the extendedAttributes */ public boolean hasExtendedAttribute(final String key) { return getExtendedAttributes().containsKey(key); }
/** * Get the extended attribute value associated with key, if possible * * @param key a non-null string key to fetch a value for * @param defaultValue the value to return if key isn't in the extended attributes * @return a value (potentially) null associated with key, or defaultValue if no association exists */ public Object getExtendedAttribute(final String key, final Object defaultValue) { return hasExtendedAttribute(key) ? getExtendedAttributes().get(key) : defaultValue; }
/** * Get the extended attribute value associated with key, if possible * * @param key a non-null string key to fetch a value for * @param defaultValue the value to return if key isn't in the extended attributes * @return a value (potentially) null associated with key, or defaultValue if no association exists */ public Object getExtendedAttribute(final String key, final Object defaultValue) { return hasExtendedAttribute(key) ? getExtendedAttributes().get(key) : defaultValue; }
/** * Is key associated with a value (even a null one) in the extended attributes? * * Note this will not return true for the inline attributes DP, GQ, AD, or PL * * @param key a non-null string key to check for an association * @return true if key has a value in the extendedAttributes */ @Requires({"key != null", "! isForbiddenKey(key)"}) public boolean hasExtendedAttribute(final String key) { return getExtendedAttributes().containsKey(key); }
/** * Get the genotype SACs * * @param g the genotype * @return an arrays of SACs * @throws ReviewedGATKException if the type of the SACs is unexpected */ private static int[] getSACs(final Genotype g) { if ( g == null ) throw new IllegalArgumentException("the Genotype cannot be null"); if ( !g.hasExtendedAttribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY) ) throw new IllegalArgumentException("Genotype must have SAC"); if ( g.getExtendedAttributes().get(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY).getClass().equals(String.class) ) { final String SACsString = (String) g.getExtendedAttributes().get(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY); ArrayList<String> stringSACs = Utils.split(SACsString, ","); final int[] intSACs = new int[stringSACs.size()]; int i = 0; for (String sac : stringSACs) intSACs[i++] = Integer.parseInt(sac); return intSACs; } else if ( g.getExtendedAttributes().get(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY).getClass().equals(int[].class) ) return (int[]) g.getExtendedAttributes().get(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY); else throw new ReviewedGATKException("Unexpected SAC type"); }
/** * Get the extended attribute value associated with key, if possible * * @param key a non-null string key to fetch a value for * @param defaultValue the value to return if key isn't in the extended attributes * @return a value (potentially) null associated with key, or defaultValue if no association exists */ @Requires({"key != null", "! isForbiddenKey(key)"}) @Ensures("hasExtendedAttribute(key) || result == defaultValue") public Object getExtendedAttribute(final String key, final Object defaultValue) { return hasExtendedAttribute(key) ? getExtendedAttributes().get(key) : defaultValue; }
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(); }
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()); }
private final Genotype fullyDecodeGenotypes(final Genotype g, final VCFHeader header) { final Map<String, Object> map = fullyDecodeAttributes(g.getExtendedAttributes(), header, true); return new GenotypeBuilder(g).attributes(map).make(); }
private final Genotype fullyDecodeGenotypes(final Genotype g, final VCFHeader header) { final Map<String, Object> map = fullyDecodeAttributes(g.getExtendedAttributes(), header, true); return new GenotypeBuilder(g).attributes(map).make(); }
private final Genotype fullyDecodeGenotypes(final Genotype g, final VCFHeader header) { final Map<String, Object> map = fullyDecodeAttributes(g.getExtendedAttributes(), header, true); return new GenotypeBuilder(g).attributes(map).make(); }
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())); }
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"); }
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"); }
/** * 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; }