Search in sources :

Example 1 with PotentialMNVRegion

use of com.hartwig.hmftools.strelka.mnv.PotentialMNVRegion in project hmftools by hartwigmedical.

the class MNVDetectorApplication method processVariants.

private static void processVariants(@NotNull final String filePath, @NotNull final String outputVcf, @NotNull final String outputBed, boolean strelka) throws IOException {
    final VCFFileReader vcfReader = new VCFFileReader(new File(filePath), false);
    final VCFHeader outputHeader = strelka ? generateOutputHeader(vcfReader.getFileHeader(), StrelkaPostProcess.TUMOR_GENOTYPE) : vcfReader.getFileHeader();
    final BufferedWriter bedWriter = new BufferedWriter(new FileWriter(outputBed, false));
    final VariantContextWriter vcfWriter = new VariantContextWriterBuilder().setOutputFile(outputVcf).setReferenceDictionary(outputHeader.getSequenceDictionary()).build();
    vcfWriter.writeHeader(outputHeader);
    Pair<PotentialMNVRegion, Optional<PotentialMNVRegion>> outputPair = ImmutablePair.of(PotentialMNVRegion.empty(), Optional.empty());
    for (final VariantContext rawVariant : vcfReader) {
        final VariantContext variant = strelka ? StrelkaPostProcess.simplifyVariant(rawVariant, StrelkaPostProcess.TUMOR_GENOTYPE) : rawVariant;
        final PotentialMNVRegion potentialMNVregion = outputPair.getLeft();
        outputPair = MNVDetector.fitsMNVRegion(potentialMNVregion, variant);
        outputPair.getRight().ifPresent(mnvRegion -> filterMnvRegion(mnvRegion).ifPresent(filteredRegion -> writeMnvRegionToFiles(filteredRegion, vcfWriter, bedWriter, "\n")));
    }
    filterMnvRegion(outputPair.getLeft()).ifPresent(mnvRegion -> writeMnvRegionToFiles(mnvRegion, vcfWriter, bedWriter, ""));
    vcfWriter.close();
    vcfReader.close();
    bedWriter.close();
    LOGGER.info("Written output variants to {}. Written bed regions to {}.", outputVcf, outputBed);
}
Also used : PotentialMNVRegion(com.hartwig.hmftools.strelka.mnv.PotentialMNVRegion) CommandLineParser(org.apache.commons.cli.CommandLineParser) BufferedWriter(java.io.BufferedWriter) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) FileWriter(java.io.FileWriter) Options(org.apache.commons.cli.Options) IOException(java.io.IOException) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) HelpFormatter(org.apache.commons.cli.HelpFormatter) File(java.io.File) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DefaultParser(org.apache.commons.cli.DefaultParser) Logger(org.apache.logging.log4j.Logger) Pair(org.apache.commons.lang3.tuple.Pair) ParseException(org.apache.commons.cli.ParseException) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) Optional(java.util.Optional) CommandLine(org.apache.commons.cli.CommandLine) VariantContext(htsjdk.variant.variantcontext.VariantContext) NotNull(org.jetbrains.annotations.NotNull) MNVDetector(com.hartwig.hmftools.strelka.mnv.MNVDetector) LogManager(org.apache.logging.log4j.LogManager) StrelkaPostProcessApplication.generateOutputHeader(com.hartwig.hmftools.strelka.StrelkaPostProcessApplication.generateOutputHeader) PotentialMNVRegion(com.hartwig.hmftools.strelka.mnv.PotentialMNVRegion) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) Optional(java.util.Optional) FileWriter(java.io.FileWriter) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VariantContext(htsjdk.variant.variantcontext.VariantContext) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 2 with PotentialMNVRegion

use of com.hartwig.hmftools.strelka.mnv.PotentialMNVRegion in project hmftools by hartwigmedical.

the class MNVValidatorApplication method processVariants.

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

Example 3 with PotentialMNVRegion

use of com.hartwig.hmftools.strelka.mnv.PotentialMNVRegion 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

PotentialMNVRegion (com.hartwig.hmftools.strelka.mnv.PotentialMNVRegion)3 VariantContext (htsjdk.variant.variantcontext.VariantContext)3 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)3 VariantContextWriterBuilder (htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder)3 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)3 File (java.io.File)3 Optional (java.util.Optional)3 ImmutableMNVValidator (com.hartwig.hmftools.strelka.mnv.ImmutableMNVValidator)2 MNVValidator (com.hartwig.hmftools.strelka.mnv.MNVValidator)2 VCFHeader (htsjdk.variant.vcf.VCFHeader)2 StrelkaPostProcessApplication.generateOutputHeader (com.hartwig.hmftools.strelka.StrelkaPostProcessApplication.generateOutputHeader)1 MNVDetector (com.hartwig.hmftools.strelka.mnv.MNVDetector)1 VariantContextFilter (htsjdk.variant.variantcontext.filter.VariantContextFilter)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1