Search in sources :

Example 11 with VCFHeaderLine

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

the class GATKToolUnitTest method testGetDefaultToolVCFHeaderLines.

@Test
public void testGetDefaultToolVCFHeaderLines() throws IOException {
    final TestGATKToolWithFeatures tool = new TestGATKToolWithFeatures();
    final File vcfFile = new File(publicTestDir + "org/broadinstitute/hellbender/engine/feature_data_source_test_with_bigHeader.vcf");
    final String[] args = { "--mask", vcfFile.getCanonicalPath(), "--" + StandardArgumentDefinitions.ADD_OUTPUT_VCF_COMMANDLINE, "true" };
    tool.instanceMain(args);
    Set<VCFHeaderLine> stdHeaderLines = tool.getDefaultToolVCFHeaderLines();
    VCFHeader hdr = new VCFHeader(stdHeaderLines);
    VCFHeaderLine sourceLine = hdr.getOtherHeaderLine("source");
    Assert.assertEquals(sourceLine.getValue(), tool.getClass().getSimpleName());
    VCFIDHeaderLine commandLine = (VCFIDHeaderLine) hdr.getOtherHeaderLine("GATKCommandLine");
    Assert.assertEquals(commandLine.getID(), tool.getClass().getSimpleName());
    String commandLineString = commandLine.toString();
    assertContains(commandLineString, "CommandLine=");
    assertContains(commandLineString, "Version=");
    assertContains(commandLineString, "Date=");
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) VCFHeader(htsjdk.variant.vcf.VCFHeader) VCFIDHeaderLine(htsjdk.variant.vcf.VCFIDHeaderLine) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 12 with VCFHeaderLine

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

the class GATKTool method getDefaultToolVCFHeaderLines.

/**
     * @return If addOutputVCFCommandLine is true, a set of VCF header lines containing the tool name, version,
     * date and command line, otherwise an empty set.
     */
protected Set<VCFHeaderLine> getDefaultToolVCFHeaderLines() {
    final Set<VCFHeaderLine> gatkToolHeaderLines = new HashSet<>();
    if (addOutputVCFCommandLine) {
        final Map<String, String> simpleHeaderLineMap = new HashMap<>(4);
        simpleHeaderLineMap.put("ID", this.getClass().getSimpleName());
        simpleHeaderLineMap.put("Version", getVersion());
        simpleHeaderLineMap.put("Date", Utils.getDateTimeForDisplay((ZonedDateTime.now())));
        simpleHeaderLineMap.put("CommandLine", getCommandLine());
        gatkToolHeaderLines.add(new VCFHeaderLine("source", this.getClass().getSimpleName()));
        gatkToolHeaderLines.add(new VCFSimpleHeaderLine(String.format("%sCommandLine", getToolkitName()), simpleHeaderLineMap));
    }
    return gatkToolHeaderLines;
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) HashMap(java.util.HashMap) VCFSimpleHeaderLine(htsjdk.variant.vcf.VCFSimpleHeaderLine) HashSet(java.util.HashSet)

Example 13 with VCFHeaderLine

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

the class VcfUtils method updateHeaderContigLines.

//TODO: these should be refactored/consolidated as part of
// https://github.com/broadinstitute/gatk/issues/121 and
// https://github.com/broadinstitute/gatk/issues/1116
/**
     * Given a set of VCF header lines, update the set with contig
     * lines from the provided reference dictionary.
     * @param oldLines
     * @param referenceFile
     * @param refDict
     * @param referenceNameOnly
     * @return Updated list of VCF header lines.
     */
public static Set<VCFHeaderLine> updateHeaderContigLines(final Set<VCFHeaderLine> oldLines, final File referenceFile, final SAMSequenceDictionary refDict, final boolean referenceNameOnly) {
    final Set<VCFHeaderLine> lines = new LinkedHashSet<>(oldLines.size());
    for (final VCFHeaderLine line : oldLines) {
        if (line instanceof VCFContigHeaderLine) {
            // skip old contig lines
            continue;
        }
        if (line.getKey().equals(VCFHeader.REFERENCE_KEY)) {
            // skip the old reference key
            continue;
        }
        lines.add(line);
    }
    lines.addAll(makeContigHeaderLines(refDict, referenceFile).stream().collect(Collectors.toList()));
    if (referenceFile != null) {
        final String referenceValue;
        if (referenceNameOnly) {
            final int extensionStart = referenceFile.getName().lastIndexOf(".");
            referenceValue = extensionStart == -1 ? referenceFile.getName() : referenceFile.getName().substring(0, extensionStart);
        } else {
            referenceValue = "file://" + referenceFile.getAbsolutePath();
        }
        lines.add(new VCFHeaderLine(VCFHeader.REFERENCE_KEY, referenceValue));
    }
    return lines;
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) VCFContigHeaderLine(htsjdk.variant.vcf.VCFContigHeaderLine)

Example 14 with VCFHeaderLine

use of htsjdk.variant.vcf.VCFHeaderLine in project gatk 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 15 with VCFHeaderLine

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

the class ReferenceConfidenceModel method getVCFHeaderLines.

/**
     * Get the VCF header lines to include when emitting reference confidence values via {@link #calculateRefConfidence}.
     * @return a non-null set of VCFHeaderLines
     */
public Set<VCFHeaderLine> getVCFHeaderLines() {
    final Set<VCFHeaderLine> headerLines = new LinkedHashSet<>();
    headerLines.add(new VCFSimpleHeaderLine(GATKVCFConstants.SYMBOLIC_ALLELE_DEFINITION_HEADER_TAG, GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE_NAME, "Represents any possible alternative allele at this location"));
    return headerLines;
}
Also used : VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) VCFSimpleHeaderLine(htsjdk.variant.vcf.VCFSimpleHeaderLine)

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