Search in sources :

Example 6 with VCFHeaderLine

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

the class VcfUtilsUnitTest method testUpdateContigsReferenceNameOnly.

@Test(dataProvider = "testData")
public void testUpdateContigsReferenceNameOnly(final Set<VCFHeaderLine> inHeaderLines, final SAMSequenceDictionary seqDict, final File referenceFile, final boolean refNameOnly, final String expectedRefName) {
    Set<VCFHeaderLine> resultLines = VcfUtils.updateHeaderContigLines(inHeaderLines, referenceFile, seqDict, refNameOnly);
    Assert.assertEquals(resultLines.size(), referenceFile == null ? 2 : 3);
    for (VCFHeaderLine resultLine : resultLines) {
        if (resultLine instanceof VCFContigHeaderLine) {
            VCFContigHeaderLine headerLine = (VCFContigHeaderLine) resultLine;
            SAMSequenceRecord samSeqRec = headerLine.getSAMSequenceRecord();
            if (samSeqRec.getSequenceName().equals("contig1")) {
                Assert.assertEquals(samSeqRec.getSequenceLength(), 100);
            } else if (samSeqRec.getSequenceName().equals("contig2")) {
                Assert.assertEquals(samSeqRec.getSequenceLength(), 200);
            } else {
                Assert.fail("Bad sequence name in header lines");
            }
        } else {
            if (referenceFile != null) {
                Assert.assertEquals(resultLine.getValue(), expectedRefName);
            } else {
                Assert.fail("Unexpected reference name in header lines");
            }
        }
    }
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) SAMSequenceRecord(htsjdk.samtools.SAMSequenceRecord) VCFContigHeaderLine(htsjdk.variant.vcf.VCFContigHeaderLine) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 7 with VCFHeaderLine

use of htsjdk.variant.vcf.VCFHeaderLine in project gatk-protected by broadinstitute.

the class Concordance method onTraversalStart.

@Override
public void onTraversalStart() {
    Set<VCFHeaderLine> defaultToolHeaderLines = getDefaultToolVCFHeaderLines();
    for (final ConcordanceState state : ConcordanceState.values()) {
        snpCounts.put(state, new MutableLong(0));
        indelCounts.put(state, new MutableLong(0));
    }
    if (truePositivesAndFalseNegativesVcf != null) {
        truePositivesAndFalseNegativesVcfWriter = createVCFWriter(truePositivesAndFalseNegativesVcf);
        final VCFHeader truthHeader = getTruthHeader();
        truthHeader.addMetaDataLine(TRUTH_STATUS_HEADER_LINE);
        defaultToolHeaderLines.forEach(truthHeader::addMetaDataLine);
        truePositivesAndFalseNegativesVcfWriter.writeHeader(truthHeader);
    }
    if (truePositivesAndFalsePositivesVcf != null) {
        truePositivesAndFalsePositivesVcfWriter = createVCFWriter(truePositivesAndFalsePositivesVcf);
        final VCFHeader evalHeader = getEvalHeader();
        defaultToolHeaderLines.forEach(evalHeader::addMetaDataLine);
        evalHeader.addMetaDataLine(TRUTH_STATUS_HEADER_LINE);
        truePositivesAndFalsePositivesVcfWriter.writeHeader(evalHeader);
    }
    if (filteredTrueNegativesAndFalseNegativesVcf != null) {
        filteredTrueNegativesAndFalseNegativesVcfWriter = createVCFWriter(filteredTrueNegativesAndFalseNegativesVcf);
        final VCFHeader evalHeader = getEvalHeader();
        evalHeader.addMetaDataLine(TRUTH_STATUS_HEADER_LINE);
        defaultToolHeaderLines.forEach(evalHeader::addMetaDataLine);
        filteredTrueNegativesAndFalseNegativesVcfWriter.writeHeader(evalHeader);
    }
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) MutableLong(org.apache.commons.lang.mutable.MutableLong) VCFHeader(htsjdk.variant.vcf.VCFHeader)

Example 8 with VCFHeaderLine

use of htsjdk.variant.vcf.VCFHeaderLine in project gatk-protected by broadinstitute.

the class HaplotypeCallerEngine method writeHeader.

/**
     * Writes an appropriate VCF header, given our arguments, to the provided writer
     *
     * @param vcfWriter writer to which the header should be written
     */
public void writeHeader(final VariantContextWriter vcfWriter, final SAMSequenceDictionary sequenceDictionary, final Set<VCFHeaderLine> defaultToolHeaderLines) {
    Utils.nonNull(vcfWriter);
    final Set<VCFHeaderLine> headerInfo = new HashSet<>();
    headerInfo.addAll(defaultToolHeaderLines);
    headerInfo.addAll(genotypingEngine.getAppropriateVCFInfoHeaders());
    // all annotation fields from VariantAnnotatorEngine
    headerInfo.addAll(annotationEngine.getVCFAnnotationDescriptions());
    // all callers need to add these standard annotation header lines
    headerInfo.add(GATKVCFHeaderLines.getInfoLine(GATKVCFConstants.DOWNSAMPLED_KEY));
    headerInfo.add(GATKVCFHeaderLines.getInfoLine(GATKVCFConstants.MLE_ALLELE_COUNT_KEY));
    headerInfo.add(GATKVCFHeaderLines.getInfoLine(GATKVCFConstants.MLE_ALLELE_FREQUENCY_KEY));
    // all callers need to add these standard FORMAT field header lines
    VCFStandardHeaderLines.addStandardFormatLines(headerInfo, true, VCFConstants.GENOTYPE_KEY, VCFConstants.GENOTYPE_QUALITY_KEY, VCFConstants.DEPTH_KEY, VCFConstants.GENOTYPE_PL_KEY);
    if (!hcArgs.doNotRunPhysicalPhasing) {
        headerInfo.add(GATKVCFHeaderLines.getFormatLine(GATKVCFConstants.HAPLOTYPE_CALLER_PHASING_ID_KEY));
        headerInfo.add(GATKVCFHeaderLines.getFormatLine(GATKVCFConstants.HAPLOTYPE_CALLER_PHASING_GT_KEY));
    }
    // FILTER fields are added unconditionally as it's not always 100% certain the circumstances
    // where the filters are used.  For example, in emitting all sites the lowQual field is used
    headerInfo.add(GATKVCFHeaderLines.getFilterLine(GATKVCFConstants.LOW_QUAL_FILTER_NAME));
    if (emitReferenceConfidence()) {
        headerInfo.addAll(referenceConfidenceModel.getVCFHeaderLines());
    }
    final VCFHeader vcfHeader = new VCFHeader(headerInfo, sampleSet);
    vcfHeader.setSequenceDictionary(sequenceDictionary);
    vcfWriter.writeHeader(vcfHeader);
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) VCFHeader(htsjdk.variant.vcf.VCFHeader)

Example 9 with VCFHeaderLine

use of htsjdk.variant.vcf.VCFHeaderLine in project gatk-protected by broadinstitute.

the class AnnotateVcfWithExpectedAlleleFraction method onTraversalStart.

@Override
public void onTraversalStart() {
    final VCFHeader inputHeader = getHeaderForVariants();
    final Set<VCFHeaderLine> headerLines = new HashSet<>(inputHeader.getMetaDataInSortedOrder());
    headerLines.add(new VCFInfoHeaderLine(EXPECTED_ALLELE_FRACTION_NAME, 1, VCFHeaderLineType.Float, "expected allele fraction in pooled bam"));
    final VCFHeader vcfHeader = new VCFHeader(headerLines, inputHeader.getGenotypeSamples());
    headerLines.addAll(getDefaultToolVCFHeaderLines());
    vcfWriter = createVCFWriter(outputVcf);
    vcfWriter.writeHeader(vcfHeader);
    final List<MixingFraction> mixingFractionsList = MixingFraction.readMixingFractions(inputMixingFractions);
    final Map<String, Double> mixingfractionsMap = mixingFractionsList.stream().collect(Collectors.toMap(MixingFraction::getSample, MixingFraction::getMixingFraction));
    mixingFractionsInSampleOrder = inputHeader.getSampleNamesInOrder().stream().mapToDouble(mixingfractionsMap::get).toArray();
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) VCFHeader(htsjdk.variant.vcf.VCFHeader) VCFInfoHeaderLine(htsjdk.variant.vcf.VCFInfoHeaderLine) HashSet(java.util.HashSet)

Example 10 with VCFHeaderLine

use of htsjdk.variant.vcf.VCFHeaderLine in project gatk-protected by broadinstitute.

the class FilterMutectCalls method onTraversalStart.

@Override
public void onTraversalStart() {
    final VCFHeader inputHeader = getHeaderForVariants();
    final Set<VCFHeaderLine> headerLines = new HashSet<>(inputHeader.getMetaDataInSortedOrder());
    Mutect2FilteringEngine.M_2_FILTER_NAMES.stream().map(GATKVCFHeaderLines::getFilterLine).forEach(headerLines::add);
    headerLines.add(new VCFFilterHeaderLine(Mutect2FilteringEngine.ARTIFACT_IN_NORMAL_FILTER_NAME, "artifact_in_normal"));
    headerLines.add(new VCFFilterHeaderLine(Mutect2FilteringEngine.MEDIAN_BASE_QUALITY_DIFFERENCE_FILTER_NAME, "ref - alt median base quality"));
    headerLines.add(new VCFFilterHeaderLine(Mutect2FilteringEngine.MEDIAN_MAPPING_QUALITY_DIFFERENCE_FILTER_NAME, "ref - alt median mapping quality"));
    headerLines.add(new VCFFilterHeaderLine(Mutect2FilteringEngine.MEDIAN_CLIPPING_DIFFERENCE_FILTER_NAME, "ref - alt median clipping"));
    headerLines.add(new VCFFilterHeaderLine(Mutect2FilteringEngine.MEDIAN_FRAGMENT_LENGTH_DIFFERENCE_FILTER_NAME, "abs(ref - alt) median fragment length"));
    headerLines.add(new VCFFilterHeaderLine(Mutect2FilteringEngine.READ_POSITION_FILTER_NAME, "median distance of alt variants from end of reads"));
    headerLines.add(new VCFFilterHeaderLine(Mutect2FilteringEngine.CONTAMINATION_FILTER_NAME, "contamination"));
    headerLines.addAll(getDefaultToolVCFHeaderLines());
    final VCFHeader vcfHeader = new VCFHeader(headerLines, inputHeader.getGenotypeSamples());
    vcfWriter = createVCFWriter(new File(outputVcf));
    vcfWriter.writeHeader(vcfHeader);
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) VCFFilterHeaderLine(htsjdk.variant.vcf.VCFFilterHeaderLine) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File)

Aggregations

VCFHeaderLine (htsjdk.variant.vcf.VCFHeaderLine)19 VCFHeader (htsjdk.variant.vcf.VCFHeader)11 VCFSimpleHeaderLine (htsjdk.variant.vcf.VCFSimpleHeaderLine)5 File (java.io.File)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)4 Test (org.testng.annotations.Test)4 VCFContigHeaderLine (htsjdk.variant.vcf.VCFContigHeaderLine)3 HashSet (java.util.HashSet)3 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)2 VCFFilterHeaderLine (htsjdk.variant.vcf.VCFFilterHeaderLine)2 VCFInfoHeaderLine (htsjdk.variant.vcf.VCFInfoHeaderLine)2 MutableLong (org.apache.commons.lang.mutable.MutableLong)2 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)1 IndexedFastaSequenceFile (htsjdk.samtools.reference.IndexedFastaSequenceFile)1 VariantContext (htsjdk.variant.variantcontext.VariantContext)1 VCFIDHeaderLine (htsjdk.variant.vcf.VCFIDHeaderLine)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1 CommandLineException (org.broadinstitute.barclay.argparser.CommandLineException)1