use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class GATKToolUnitTest method testCreateVCFWriterLenientTrue.
@Test(dataProvider = "createVCFWriterLenientData")
public void testCreateVCFWriterLenientTrue(final File inputFile, final String outputExtension, final String indexExtension, final boolean createIndex, final boolean createMD5) throws IOException {
final TestGATKToolWithVariants tool = new TestGATKToolWithVariants();
// verify lenient==true is honored by writing a bad attribute
final File outputFile = setupVCFWriter(inputFile, outputExtension, tool, createIndex, createMD5, true);
try (VariantContextWriter writer = tool.createVCFWriter(outputFile)) {
// write bad attribute succeed with lenient set
writeHeaderAndBadVariant(writer);
}
final File outFileIndex = new File(outputFile.getAbsolutePath() + indexExtension);
final File outFileMD5 = new File(outputFile.getAbsolutePath() + ".md5");
Assert.assertTrue(outputFile.exists(), "No output file was not created");
Assert.assertEquals(outFileIndex.exists(), createIndex, "The createIndex argument was not honored");
Assert.assertEquals(outFileMD5.exists(), createMD5, "The createMD5 argument was not honored");
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class GATKToolUnitTest method testCreateVCFWriterWithNoSequenceDictionary.
@Test(dataProvider = "createVCFWriterData")
public void testCreateVCFWriterWithNoSequenceDictionary(final File inputFile, final String outputExtension, final String indexExtension, final boolean createIndex, final boolean createMD5) throws IOException {
// verify that a null sequence dictionary still results in a file, but with no index
final TestGATKVariantToolWithNoSequenceDictionary tool = new TestGATKVariantToolWithNoSequenceDictionary();
final File outputFile = setupVCFWriter(inputFile, outputExtension, tool, createIndex, createMD5, false);
final VariantContextWriter writer = tool.createVCFWriter(outputFile);
writer.close();
final File outFileIndex = new File(outputFile.getAbsolutePath() + indexExtension);
final File outFileMD5 = new File(outputFile.getAbsolutePath() + ".md5");
Assert.assertTrue(outputFile.exists(), "No output file was not created");
// always false with no seq dictionary
Assert.assertEquals(outFileIndex.exists(), false, "An index file should not have been created");
Assert.assertEquals(outFileMD5.exists(), createMD5, "The createMD5 argument was not honored");
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class GATKToolUnitTest method testCreateVCFWriterDefaults.
@Test(dataProvider = "createVCFWriterData")
public void testCreateVCFWriterDefaults(// unused
final File inputFile, final String outputExtension, final String indexExtension, // unused
final boolean createIndex, // unused
final boolean createMD5) throws IOException {
// create a writer and make sure the default index/md5 params are honored
final TestGATKToolWithVariants tool = createTestVariantTool(null);
final File tmpDir = createTempDir("createVCFTest");
final File outputFile = new File(tmpDir.getAbsolutePath(), "createVCFTest" + outputExtension);
final VariantContextWriter writer = tool.createVCFWriter(outputFile);
writer.close();
final File outFileIndex = new File(outputFile.getAbsolutePath() + indexExtension);
final File outFileMD5 = new File(outputFile.getAbsolutePath() + ".md5");
Assert.assertTrue(outputFile.exists(), "No output file was not created");
Assert.assertTrue(outFileIndex.exists(), "The index file was not created");
Assert.assertFalse(outFileMD5.exists(), "An md5 file was created and should not have been");
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter in project gatk by broadinstitute.
the class SVVCFWriter method writeVariants.
private static void writeVariants(final PipelineOptions pipelineOptions, final String fileName, final List<VariantContext> variantsArrayList, final SAMSequenceDictionary referenceSequenceDictionary) {
try (final OutputStream outputStream = new BufferedOutputStream(BucketUtils.createFile(fileName))) {
final VariantContextWriter vcfWriter = getVariantContextWriter(outputStream, referenceSequenceDictionary);
vcfWriter.writeHeader(getVcfHeader(referenceSequenceDictionary));
variantsArrayList.forEach(vcfWriter::add);
vcfWriter.close();
} catch (final IOException e) {
throw new GATKException("Could not create output file", e);
}
}
use of htsjdk.variant.variantcontext.writer.VariantContextWriter 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);
}
Aggregations