Java Code Examples for htsjdk.variant.variantcontext.VariantContext#filtersWereApplied()
The following examples show how to use
htsjdk.variant.variantcontext.VariantContext#filtersWereApplied() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VcfToVariant.java From genomewarp with Apache License 2.0 | 5 votes |
@VisibleForTesting static List<String> getFilter(VariantContext vc) { if (vc.isFiltered()) { return (List<String>) ParsingUtils.sortList(vc.getFilters()); } if (vc.filtersWereApplied()) { return Arrays.asList(VCFConstants.PASSES_FILTERS_v4); } return Arrays.asList(VCFConstants.UNFILTERED); }
Example 2
Source File: TestFilterVcf.java From picard with MIT License | 5 votes |
/** * Tests that all records get PASS set as their filter when extreme values are used for filtering. */ @Test(dataProvider = "goodInputVcfs") public void testNoFiltering(final File input) throws Exception { final File out = testFiltering(input, ".vcf.gz", 0, 0, 0, Double.MAX_VALUE); final VCFFileReader in = new VCFFileReader(out, false); for (final VariantContext ctx : in) { if (!ctx.filtersWereApplied() || ctx.isFiltered()) { Assert.fail("Context should not have been filtered: " + ctx.toString()); } } in.close(); }
Example 3
Source File: CombineGenotypingArrayVcfs.java From picard with MIT License | 4 votes |
/** * Merges multiple VariantContexts all for the same locus into a single hybrid. * * @param variantContexts list of VCs * @return new VariantContext representing the merge of variantContexts */ public static VariantContext merge(final List<VariantContext> variantContexts) { if ( variantContexts == null || variantContexts.isEmpty() ) return null; // establish the baseline info from the first VC final VariantContext first = variantContexts.get(0); final String name = first.getSource(); final Set<String> filters = new HashSet<>(); int depth = 0; double log10PError = CommonInfo.NO_LOG10_PERROR; boolean anyVCHadFiltersApplied = false; GenotypesContext genotypes = GenotypesContext.create(); // Go through all the VCs, verify that the loci and ID and other attributes agree. final Map<String, Object> firstAttributes = first.getAttributes(); for (final VariantContext vc : variantContexts ) { if ((vc.getStart() != first.getStart()) || (!vc.getContig().equals(first.getContig()))) { throw new PicardException("Mismatch in loci among input VCFs"); } if (!vc.getID().equals(first.getID())) { throw new PicardException("Mismatch in ID field among input VCFs"); } if (!vc.getReference().equals(first.getReference())) { throw new PicardException("Mismatch in REF allele among input VCFs"); } checkThatAllelesMatch(vc, first); genotypes.addAll(vc.getGenotypes()); // We always take the QUAL of the first VC with a non-MISSING qual for the combined value if ( log10PError == CommonInfo.NO_LOG10_PERROR ) log10PError = vc.getLog10PError(); filters.addAll(vc.getFilters()); anyVCHadFiltersApplied |= vc.filtersWereApplied(); // add attributes // special case DP (add it up) if (vc.hasAttribute(VCFConstants.DEPTH_KEY)) depth += vc.getAttributeAsInt(VCFConstants.DEPTH_KEY, 0); // Go through all attributes - if any differ (other than AC, AF, or AN) that's an error. (recalc AC, AF, and AN later) for (final Map.Entry<String, Object> p : vc.getAttributes().entrySet()) { final String key = p.getKey(); if ((!key.equals("AC")) && (!key.equals("AF")) && (!key.equals("AN")) && (!key.equals("devX_AB")) && (!key.equals("devY_AB"))) { final Object value = p.getValue(); final Object extantValue = firstAttributes.get(key); if (extantValue == null) { // attribute in one VCF but not another. Die! throw new PicardException("Attribute '" + key + "' not found in all VCFs"); } else if (!extantValue.equals(value)) { // Attribute disagrees in value between one VCF Die! (if not AC, AF, nor AN, skipped above) throw new PicardException("Values for attribute '" + key + "' disagrees among input VCFs"); } } } } if (depth > 0) firstAttributes.put(VCFConstants.DEPTH_KEY, String.valueOf(depth)); final VariantContextBuilder builder = new VariantContextBuilder().source(name).id(first.getID()); builder.loc(first.getContig(), first.getStart(), first.getEnd()); builder.alleles(first.getAlleles()); builder.genotypes(genotypes); builder.attributes(new TreeMap<>(firstAttributes)); // AC, AF, and AN are recalculated here VariantContextUtils.calculateChromosomeCounts(builder, false); builder.log10PError(log10PError); if ( anyVCHadFiltersApplied ) { builder.filters(filters.isEmpty() ? filters : new TreeSet<>(filters)); } return builder.make(); }