Search in sources :

Example 1 with VCFFormatHeaderLine

use of htsjdk.variant.vcf.VCFFormatHeaderLine in project gatk by broadinstitute.

the class FilterVcf method doWork.

@Override
protected Object doWork() {
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsWritable(OUTPUT);
    final List<VariantFilter> variantFilters = CollectionUtil.makeList(new AlleleBalanceFilter(MIN_AB), new FisherStrandFilter(MAX_FS), new QdFilter(MIN_QD));
    final List<GenotypeFilter> genotypeFilters = CollectionUtil.makeList(new GenotypeQualityFilter(MIN_GQ), new DepthFilter(MIN_DP));
    try (final VCFFileReader in = new VCFFileReader(INPUT, false)) {
        final FilterApplyingVariantIterator iterator = new FilterApplyingVariantIterator(in.iterator(), variantFilters, genotypeFilters);
        try (final VariantContextWriter out = new VariantContextWriterBuilder().setOutputFile(OUTPUT).build()) {
            final VCFHeader header = in.getFileHeader();
            header.addMetaDataLine(new VCFFilterHeaderLine("AllGtsFiltered", "Site filtered out because all genotypes are filtered out."));
            header.addMetaDataLine(new VCFFormatHeaderLine("FT", VCFHeaderLineCount.UNBOUNDED, VCFHeaderLineType.String, "Genotype filters."));
            for (final VariantFilter filter : variantFilters) {
                for (final VCFFilterHeaderLine line : filter.headerLines()) {
                    header.addMetaDataLine(line);
                }
            }
            out.writeHeader(in.getFileHeader());
            while (iterator.hasNext()) {
                out.add(iterator.next());
            }
        }
    }
    return null;
}
Also used : VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VCFFilterHeaderLine(htsjdk.variant.vcf.VCFFilterHeaderLine) VCFHeader(htsjdk.variant.vcf.VCFHeader) VCFFormatHeaderLine(htsjdk.variant.vcf.VCFFormatHeaderLine)

Aggregations

VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)1 VariantContextWriterBuilder (htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder)1 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)1 VCFFilterHeaderLine (htsjdk.variant.vcf.VCFFilterHeaderLine)1 VCFFormatHeaderLine (htsjdk.variant.vcf.VCFFormatHeaderLine)1 VCFHeader (htsjdk.variant.vcf.VCFHeader)1