Search in sources :

Example 1 with VCFHeader

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

the class UpdateVCFSequenceDictionaryIntegrationTest method testGoodUpdateSequenceDictionary.

@Test(dataProvider = "UpdateGoodSequenceDictionaryData")
private void testGoodUpdateSequenceDictionary(final File inputVariantsFile, final File inputSourceFile, final File inputReferenceFile, final boolean replace) throws FileNotFoundException {
    final SAMSequenceDictionary resultingDictionary = updateSequenceDictionary(inputVariantsFile, inputSourceFile, inputReferenceFile, replace);
    // get the original sequence dictionary from the source for comparison
    SAMSequenceDictionary sourceDictionary = SAMSequenceDictionaryExtractor.extractDictionary(inputSourceFile == null ? inputReferenceFile : inputSourceFile);
    // Some sequence dictionary sources will contain optional attributes (i.e., if the source is a .dict file,
    // or if only a reference is presented to the tool using -R, which will in turn cause the framework to retrieve
    // the dictionary from the .dict file accompanying the reference, the dictionary will likely include md5 and
    // UR attributes). However, htsjdk doesn't propagate these attributes to the VCF header properly
    // (https://github.com/samtools/htsjdk/issues/730), and many are stripped out. In order to ensure the
    // roundtrip comparison succeeds, roundtrip it through a VCF header to match what htsjdk will have written out.
    VCFHeader sourceVCFHeader = new VCFHeader();
    sourceVCFHeader.setSequenceDictionary(sourceDictionary);
    sourceDictionary = sourceVCFHeader.getSequenceDictionary();
    Assert.assertEquals(sourceDictionary, resultingDictionary);
}
Also used : VCFHeader(htsjdk.variant.vcf.VCFHeader) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 2 with VCFHeader

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

the class GVCFWriterUnitTest method testHeaderWriting.

@Test
public void testHeaderWriting() {
    final MockWriter mockWriter = new MockWriter();
    final GVCFWriter writer = new GVCFWriter(mockWriter, standardPartition, HomoSapiensConstants.DEFAULT_PLOIDY);
    writer.writeHeader(new VCFHeader());
    Assert.assertTrue(mockWriter.headerWritten);
}
Also used : VCFHeader(htsjdk.variant.vcf.VCFHeader) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 3 with VCFHeader

use of htsjdk.variant.vcf.VCFHeader 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 4 with VCFHeader

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

the class MultiVariantWalkerIntegrationTest method testGetCompatibleHeader.

@Test
public void testGetCompatibleHeader() throws Exception {
    final TestMultiVariantWalker tool = new TestMultiVariantWalker();
    final List<String> args = new ArrayList<>();
    File testFile1 = new File(getTestDataDir(), "interleavedVariants_1.vcf");
    args.add("--variant");
    args.add(testFile1.getAbsolutePath());
    File testFile2 = new File(getTestDataDir(), "interleavedVariants_2.vcf");
    args.add("--variant");
    args.add(testFile2.getAbsolutePath());
    tool.instanceMain(args.toArray(new String[args.size()]));
    VCFHeader header = tool.getHeaderForVariants();
    Assert.assertEquals(header.getSequenceDictionary().getSequences().size(), 4);
}
Also used : ArrayList(java.util.ArrayList) VCFHeader(htsjdk.variant.vcf.VCFHeader) File(java.io.File) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 5 with VCFHeader

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

the class SVVCFWriter method getVcfHeader.

private static VCFHeader getVcfHeader(final SAMSequenceDictionary referenceSequenceDictionary) {
    final VCFHeader header = new VCFHeader(new HashSet<>(GATKSVVCFHeaderLines.vcfHeaderLines.values()));
    header.setSequenceDictionary(referenceSequenceDictionary);
    header.addMetaDataLine(VCFStandardHeaderLines.getInfoLine(VCFConstants.END_KEY));
    return header;
}
Also used : VCFHeader(htsjdk.variant.vcf.VCFHeader)

Aggregations

VCFHeader (htsjdk.variant.vcf.VCFHeader)182 VariantContext (htsjdk.variant.variantcontext.VariantContext)113 File (java.io.File)93 ArrayList (java.util.ArrayList)79 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)73 VCFHeaderLine (htsjdk.variant.vcf.VCFHeaderLine)64 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)63 HashSet (java.util.HashSet)60 SAMSequenceDictionaryProgress (com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress)58 IOException (java.io.IOException)55 VCFInfoHeaderLine (htsjdk.variant.vcf.VCFInfoHeaderLine)52 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)49 Genotype (htsjdk.variant.variantcontext.Genotype)48 Allele (htsjdk.variant.variantcontext.Allele)47 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)47 List (java.util.List)44 Set (java.util.Set)38 VcfIterator (com.github.lindenb.jvarkit.util.vcf.VcfIterator)36 CloserUtil (htsjdk.samtools.util.CloserUtil)35 Collectors (java.util.stream.Collectors)34