/** * 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; }
/** * 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; }
/** * From a given genotype, extract a given subset of alleles and return the new SACs * @param g genotype to subset * @param allelesToUse alleles to subset * @param vc variant context with alleles and genotypes * @return the subsetted SACs */ private int[] subsetSACAlleles(final Genotype g, final List<Allele> allelesToUse, final VariantContext vc){ if ( !g.hasExtendedAttribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY) ) return null; // 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; final List<Integer> sacIndexesToUse = numOriginalAltAlleles == numNewAltAlleles ? null : GATKVariantContextUtils.determineSACIndexesToUse(vc, allelesToUse); return GATKVariantContextUtils.makeNewSACs(g, sacIndexesToUse); }
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); } }
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); } }
/** * 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"); }
@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)); }
static private String anchorFromVc(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); if (genotype == null || !genotype.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { return SYNTHETIC_PHASESET_PREFIX + "_" + vc.getContig() + "_" + vc.getStart(); } else { return PHASESET_PREFIX + "_" + vc.getContig() + "_" + genotype.getExtendedAttribute(VCFConstants.PHASE_SET_KEY); } }
static private String anchorFromVc(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); if (genotype == null || !genotype.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { return SYNTHETIC_PHASESET_PREFIX + "_" + vc.getContig() + "_" + vc.getStart(); } else { return PHASESET_PREFIX + "_" + vc.getContig() + "_" + genotype.getExtendedAttribute(VCFConstants.PHASE_SET_KEY); } }
@Test(dataProvider="ConstructPhaseGroupsProvider") public void testConstructPhaseGroups(final List<VariantContext> calls, final Map<VariantContext, Pair<Integer, String>> phaseMap, final int endIndex, final int expectedNumGroups, final int expectedGroupSize) { final List<VariantContext> actualPhasedCalls; try { actualPhasedCalls = HaplotypeCallerGenotypingEngine.constructPhaseGroups(calls, phaseMap, endIndex); } catch (IllegalStateException e) { Assert.assertEquals(-1, expectedNumGroups); return; } final Set<String> uniqueGroups = new HashSet<>(); int counter = 0; for ( final VariantContext call : actualPhasedCalls ) { for ( final Genotype g : call.getGenotypes() ) { if ( g.hasExtendedAttribute(GATKVCFConstants.HAPLOTYPE_CALLER_PHASING_ID_KEY) ) { uniqueGroups.add(g.getExtendedAttribute(GATKVCFConstants.HAPLOTYPE_CALLER_PHASING_ID_KEY).toString()); counter++; } } } Assert.assertEquals(uniqueGroups.size(), expectedNumGroups); Assert.assertEquals(counter, expectedGroupSize); }
double[] likelihoods; if (genotype != null && hasCalledGT(genotype.getType()) && genotype.hasExtendedAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY)) { Object GPfromVCF = genotype.getExtendedAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY); final String key = genotype.hasExtendedAttribute(GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY) ? GATKVCFConstants.PHRED_SCALED_POSTERIORS_KEY : VCFConstants.GENOTYPE_PL_KEY; throw new UserException(genotype + " has " + likelihoods.length + " " + key + " values, should be " + NUM_CALLED_GENOTYPETYPES +
if(gt.isHomRef()) { if (gt.hasExtendedAttribute("MIN_DP")) numOfReads -= Integer.parseInt(gt.getExtendedAttribute("MIN_DP").toString()); else if (gt.hasDP())
if ( oldGT.hasExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY) ) { depth = Integer.parseInt((String)oldGT.getAnyAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY)); builder.DP(depth); if ( oldGT.isHomVar() && oldGT.hasExtendedAttribute(GATKVCFConstants.HAPLOTYPE_CALLER_PHASING_GT_KEY) ) { attrs.put(GATKVCFConstants.HAPLOTYPE_CALLER_PHASING_GT_KEY, "1|1");
if (hasGc && gc.isPhased() && !gc.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { throw new IllegalStateException("Haplotype map VCF Variants' genotypes that are phased must have a PhaseSet (" + VCFConstants.PHASE_SET_KEY+")" + vc.toString());
if (hasGc && gc.isPhased() && !gc.hasExtendedAttribute(VCFConstants.PHASE_SET_KEY)) { throw new IllegalStateException("Haplotype map VCF Variants' genotypes that are phased must have a PhaseSet (" + VCFConstants.PHASE_SET_KEY+")" + vc.toString());
/** * Returns a list of attribute values from a VCF file * * @param vcfFile VCF file * @param attributeName attribute name * * @throws IOException if the file does not exist or can not be opened * * @return list of attribute values */ private List<String> getAttributeValues(final File vcfFile, final String attributeName) throws IOException { final VCFCodec codec = new VCFCodec(); final FileInputStream s = new FileInputStream(vcfFile); final LineIterator lineIteratorVCF = codec.makeSourceFromStream(new PositionalBufferedStream(s)); codec.readHeader(lineIteratorVCF); final List<String> attributeValues = new ArrayList<String>(); while (lineIteratorVCF.hasNext()) { final String line = lineIteratorVCF.next(); Assert.assertFalse(line == null); final VariantContext vc = codec.decode(line); for (final Genotype g : vc.getGenotypes()) { if (g.hasExtendedAttribute(attributeName)) { attributeValues.add((String) g.getExtendedAttribute(attributeName)); } } } return attributeValues; }
if (g.hasExtendedAttribute(attributeName)) { attributeValues.add((String) g.getExtendedAttribute(attributeName));
final boolean hasSAC = g.hasExtendedAttribute(GATKVCFConstants.STRAND_COUNT_BY_SAMPLE_KEY); if (doPLs || hasSAC || hasAD) { final int[] perSampleIndexesOfRelevantAlleles = getIndexesOfRelevantAlleles(remappedAlleles, targetAlleles, vc.getStart(), g);