Search in sources :

Example 1 with VariantContextFilter

use of htsjdk.variant.variantcontext.filter.VariantContextFilter in project hmftools by hartwigmedical.

the class StrelkaPostProcessApplication method processVariants.

private static void processVariants(@NotNull final String filePath, @NotNull final Slicer highConfidenceSlicer, @NotNull final String outputVcf, @NotNull final String sampleName, @NotNull final String tumorBam) {
    final VCFFileReader vcfReader = new VCFFileReader(new File(filePath), false);
    final VCFHeader outputHeader = generateOutputHeader(vcfReader.getFileHeader(), sampleName);
    final VariantContextWriter writer = new VariantContextWriterBuilder().setOutputFile(outputVcf).setReferenceDictionary(outputHeader.getSequenceDictionary()).build();
    writer.writeHeader(outputHeader);
    final MNVValidator validator = ImmutableMNVValidator.of(tumorBam);
    Pair<PotentialMNVRegion, Optional<PotentialMNVRegion>> outputPair = ImmutablePair.of(PotentialMNVRegion.empty(), Optional.empty());
    final VariantContextFilter filter = new StrelkaPostProcess(highConfidenceSlicer);
    for (final VariantContext variantContext : vcfReader) {
        if (filter.test(variantContext)) {
            final VariantContext simplifiedVariant = StrelkaPostProcess.simplifyVariant(variantContext, sampleName);
            final PotentialMNVRegion potentialMNV = outputPair.getLeft();
            outputPair = MNVDetector.fitsMNVRegion(potentialMNV, simplifiedVariant);
            outputPair.getRight().ifPresent(mnvRegion -> validator.mergeVariants(mnvRegion).forEach(writer::add));
        }
    }
    validator.mergeVariants(outputPair.getLeft()).forEach(writer::add);
    writer.close();
    vcfReader.close();
    LOGGER.info("Written output variants to " + outputVcf);
}
Also used : PotentialMNVRegion(com.hartwig.hmftools.strelka.mnv.PotentialMNVRegion) Optional(java.util.Optional) VariantContextFilter(htsjdk.variant.variantcontext.filter.VariantContextFilter) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) ImmutableMNVValidator(com.hartwig.hmftools.strelka.mnv.ImmutableMNVValidator) MNVValidator(com.hartwig.hmftools.strelka.mnv.MNVValidator) VariantContext(htsjdk.variant.variantcontext.VariantContext) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File)

Aggregations

ImmutableMNVValidator (com.hartwig.hmftools.strelka.mnv.ImmutableMNVValidator)1 MNVValidator (com.hartwig.hmftools.strelka.mnv.MNVValidator)1 PotentialMNVRegion (com.hartwig.hmftools.strelka.mnv.PotentialMNVRegion)1 VariantContext (htsjdk.variant.variantcontext.VariantContext)1 VariantContextFilter (htsjdk.variant.variantcontext.filter.VariantContextFilter)1 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)1 VariantContextWriterBuilder (htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder)1 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)1 VCFHeader (htsjdk.variant.vcf.VCFHeader)1 File (java.io.File)1 Optional (java.util.Optional)1