Java Code Examples for htsjdk.variant.variantcontext.VariantContext#isNotFiltered()

The following examples show how to use htsjdk.variant.variantcontext.VariantContext#isNotFiltered() . 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: AmberSiteFactory.java    From hmftools with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
public static ListMultimap<Chromosome, AmberSite> sites(@NotNull final String vcfFile) throws IOException {
    final ListMultimap<Chromosome, AmberSite> result = ArrayListMultimap.create();

    try (final AbstractFeatureReader<VariantContext, LineIterator> reader = getFeatureReader(vcfFile, new VCFCodec(), false)) {
        for (VariantContext variant : reader.iterator()) {
            if (variant.isNotFiltered()) {
                if (HumanChromosome.contains(variant.getContig())) {
                    HumanChromosome chromosome = HumanChromosome.fromString(variant.getContig());
                    result.put(chromosome,
                            ImmutableAmberSite.builder()
                                    .chromosome(variant.getContig())
                                    .position(variant.getStart())
                                    .ref(variant.getReference().getBaseString())
                                    .alt(variant.getAlternateAllele(0).getBaseString())
                                    .snpCheck(variant.hasAttribute("SNPCHECK"))
                                    .build());
                }
            }
        }
    }

    return result;
}
 
Example 2
Source File: TestFilterVcf.java    From picard with MIT License 5 votes vote down vote up
/**
 * Consumes a VCF and returns a ListMap where each they keys are the IDs of filtered out sites and the values are the set of filters.
 */
private ListMap<String, String> slurpFilters(final File vcf) {
    final ListMap<String, String> map = new ListMap<>();
    final VCFFileReader in = new VCFFileReader(vcf, false);
    for (final VariantContext ctx : in) {
        if (ctx.isNotFiltered()) continue;
        for (final String filter : ctx.getFilters()) {
            map.add(ctx.getID(), filter);
        }
    }
    in.close();
    return map;
}
 
Example 3
Source File: ApplyVQSR.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext ref, final FeatureContext featureContext) {

    final List<VariantContext> recals =  featureContext.getValues(recal, vc.getStart());
    final boolean evaluateThisVariant = useASannotations || VariantDataManager.checkVariationClass( vc, MODE );

    //vc.isNotFiltered is true for PASS; vc.filtersHaveBeenApplied covers PASS and filters
    final boolean variantIsNotFiltered = IGNORE_ALL_FILTERS || vc.isNotFiltered() ||
            (!ignoreInputFilterSet.isEmpty() && ignoreInputFilterSet.containsAll(vc.getFilters()));

    if( evaluateThisVariant && variantIsNotFiltered) {
        String filterString;
        final VariantContextBuilder builder = new VariantContextBuilder(vc);
        if (!useASannotations) {
            filterString = doSiteSpecificFiltering(vc, recals, builder);
        }
        else {  //allele-specific mode
            filterString = doAlleleSpecificFiltering(vc, recals, builder);
        }

        //for both non-AS and AS modes:
        if( filterString.equals(VCFConstants.PASSES_FILTERS_v4) ) {
            builder.passFilters();
        } else if(filterString.equals(VCFConstants.UNFILTERED)) {
            builder.unfiltered();
        } else {
            builder.filters(filterString);
        }

        final VariantContext outputVC = builder.make();
        if( !EXCLUDE_FILTERED || outputVC.isNotFiltered() ) {
            vcfWriter.add( outputVC );
        }
    } else { // valid VC but not compatible with this mode, so just emit the variant untouched
        vcfWriter.add( vc );
    }
}
 
Example 4
Source File: VariantRecalibrator.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addVariantDatum(final VariantContext vc, final boolean isInput, final FeatureContext context ) {
    if( vc != null && ( IGNORE_ALL_FILTERS || vc.isNotFiltered() || ignoreInputFilterSet.containsAll(vc.getFilters()) ) ) {
        if( VariantDataManager.checkVariationClass( vc, VRAC.MODE ) && !VRAC.useASannotations) {
            addDatum(reduceSum, isInput, context, vc, null, null);
        }
        else if( VRAC.useASannotations ) {
            for (final Allele allele : vc.getAlternateAlleles()) {
                if (!GATKVCFConstants.isSpanningDeletion(allele) && VariantDataManager.checkVariationClass(vc, allele, VRAC.MODE)) {
                    //note that this may not be the minimal representation for the ref and alt allele
                    addDatum(reduceSum, isInput, context, vc, vc.getReference(), allele);
                }
            }
        }
    }
}
 
Example 5
Source File: VariantsToTable.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext ref, final FeatureContext featureContext) {
    if ( showFiltered || vc.isNotFiltered() ) {
        nRecords++;
        final List<List<String>> records = extractFields(vc);
        if (moltenizeOutput){
            records.forEach(record -> emitMoltenizedOutput(record));
        } else {
            records.forEach(record -> outputStream.println(Utils.join("\t", record)));
        }
    }
}
 
Example 6
Source File: CompOverlap.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void update2(VariantContext eval, VariantContext comp, final ReferenceContext referenceContext, final ReadsContext readsContext, final FeatureContext featureContext) {
    boolean evalIsGood = eval != null && eval.isPolymorphicInSamples();
    boolean compIsGood = comp != null && comp.isNotFiltered();

    if (evalIsGood) nEvalVariants++;           // count the number of eval events

    if (compIsGood && evalIsGood) {
        nVariantsAtComp++;

        if (!discordantP(eval, comp)) {    // count whether we're concordant or not with the comp value
            nConcordant++;
        }
    }
}
 
Example 7
Source File: PrintMissingComp.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void update2(VariantContext eval, VariantContext comp, final ReferenceContext referenceContext, final ReadsContext readsContext, final FeatureContext featureContext) {
    final boolean compIsGood = comp != null && comp.isNotFiltered() && comp.isSNP();
    final boolean evalIsGood = eval != null && eval.isSNP();

    if ( compIsGood && !evalIsGood ) {
        nMissing++;
    }
}
 
Example 8
Source File: MTLowHeteroplasmyFilterTool.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void firstPassApply(VariantContext variant, ReadsContext readsContext, ReferenceContext referenceContext, FeatureContext featureContext) {
    // if the site is not filtered but it is low het, increment counter
    if (variant.isNotFiltered() && isSiteLowHeteroplasmy(variant)) {
        unfilteredLowHetSites++;
    }
}
 
Example 9
Source File: RecoverStructuralVariants.java    From hmftools with GNU General Public License v3.0 4 votes vote down vote up
@NotNull
private static Set<String> filterSet(@NotNull VariantContext variantContext) {
    return variantContext.isNotFiltered() ? Sets.newHashSet("PASS") : Sets.newHashSet(variantContext.getFilters());
}
 
Example 10
Source File: VariantDataManager.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private boolean isValidVariant( final VariantContext evalVC, final VariantContext trainVC, final boolean TRUST_ALL_POLYMORPHIC) {
    return trainVC != null && trainVC.isNotFiltered() && trainVC.isVariant() && checkVariationClass( evalVC, trainVC ) &&
            (TRUST_ALL_POLYMORPHIC || !trainVC.hasGenotypes() || trainVC.isPolymorphicInSamples());
}